1
0

rect.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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:
  14. return Rect{
  15. X: rect.X,
  16. Y: rect.Y,
  17. Width: rect.Width / num,
  18. Height: rect.Height,
  19. }
  20. case SplitVertical:
  21. return Rect{
  22. X: rect.X,
  23. Y: rect.Y,
  24. Width: rect.Width,
  25. Height: rect.Height / num,
  26. }
  27. default:
  28. panic("[moose-error] impossible split type")
  29. }
  30. }
  31. func RectDisplace(rect Rect, split SplitType, idx int) Rect {
  32. switch split {
  33. case SplitHorizontal:
  34. return Rect{
  35. X: rect.X + (rect.Width * idx),
  36. Y: rect.Y, // + 1,
  37. Width: rect.Width,
  38. Height: rect.Height, // - 1,
  39. }
  40. case SplitVertical:
  41. return Rect{
  42. X: rect.X,
  43. Y: rect.Y + (rect.Height * idx), // + 1,
  44. Width: rect.Width,
  45. Height: rect.Height, // - 1,
  46. }
  47. default:
  48. panic("[moose-error] impossible split type")
  49. }
  50. }
  51. func RectFromScren(s tcell.Screen) Rect {
  52. sWidth, sHeight := s.Size()
  53. return Rect{
  54. X: 0,
  55. Y: 0,
  56. Width: sWidth,
  57. Height: sHeight,
  58. }
  59. }