util.go 734 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2016 The G3N Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package gui
  5. type BorderSizes struct {
  6. Top float32
  7. Right float32
  8. Bottom float32
  9. Left float32
  10. }
  11. func (bs *BorderSizes) Set(top, right, bottom, left float32) {
  12. if top >= 0 {
  13. bs.Top = top
  14. }
  15. if right >= 0 {
  16. bs.Right = right
  17. }
  18. if bottom >= 0 {
  19. bs.Bottom = bottom
  20. }
  21. if left >= 0 {
  22. bs.Left = left
  23. }
  24. }
  25. type Rect struct {
  26. X float32
  27. Y float32
  28. Width float32
  29. Height float32
  30. }
  31. func (r *Rect) Contains(x, y float32) bool {
  32. if x < r.X || x > r.X+r.Width {
  33. return false
  34. }
  35. if y < r.Y || y > r.Y+r.Height {
  36. return false
  37. }
  38. return true
  39. }