rect.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package layout
  2. import (
  3. "github.com/gdamore/tcell/v3"
  4. )
  5. type Rect struct {
  6. X int
  7. Y int
  8. Width int
  9. Height int
  10. }
  11. func RectDivide(rect Rect, split SplitType, num int) Rect {
  12. switch split {
  13. case SplitHorizontal: return Rect{
  14. X: rect.X,
  15. Y: rect.Y,
  16. Width: rect.Width / num,
  17. Height: rect.Height,
  18. }
  19. case SplitVertical: return Rect{
  20. X: rect.X,
  21. Y: rect.Y,
  22. Width: rect.Width,
  23. Height: rect.Height / num,
  24. }
  25. default: panic("[moose-error] impossible split type")
  26. }
  27. }
  28. func RectDisplace(rect Rect, split SplitType, idx int) Rect {
  29. switch split {
  30. case SplitHorizontal: return Rect{
  31. X: rect.X + (rect.Width * idx),
  32. Y: rect.Y,
  33. Width: rect.Width,
  34. Height: rect.Height,
  35. }
  36. case SplitVertical: return Rect{
  37. X: rect.X,
  38. Y: rect.Y + (rect.Height * idx),
  39. Width: rect.Width,
  40. Height: rect.Height,
  41. }
  42. default: panic("[moose-error] impossible split type")
  43. }
  44. }
  45. func RectFromScren(s tcell.Screen) Rect {
  46. sWidth, sHeight := s.Size()
  47. return Rect{
  48. X: 0,
  49. Y: 0,
  50. Width: sWidth,
  51. Height: sHeight,
  52. }
  53. }