layout.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package layout
  2. type LayoutManager struct {
  3. Workspaces []Workspace
  4. ActiveIdx int
  5. }
  6. type Workspace struct {
  7. RootContainer Container
  8. }
  9. type SplitType int
  10. const (
  11. SplitHorizontal SplitType = iota
  12. SplitVertical
  13. )
  14. type ContainerNode interface {
  15. isContainerNode()
  16. }
  17. type ContainerBuffers struct {
  18. Buffers []int
  19. ActiveIdx int
  20. }
  21. func (ContainerBuffers) isContainerNode() {}
  22. type Container struct {
  23. Children [2]ContainerNode
  24. Split SplitType
  25. ActiveChildIdx int
  26. }
  27. func (Container) isContainerNode() {}
  28. func NewLayoutManager() LayoutManager {
  29. return LayoutManager{
  30. Workspaces: []Workspace{NewWorkspace()},
  31. }
  32. }
  33. func NewWorkspace() Workspace {
  34. return Workspace{
  35. RootContainer: NewContainerEmpty(),
  36. }
  37. }
  38. func NewContainerEmpty() Container {
  39. return Container{
  40. Children: [2]ContainerNode{
  41. ContainerBuffers{
  42. Buffers: []int{0},
  43. ActiveIdx: 0,
  44. },
  45. },
  46. Split: SplitVertical,
  47. ActiveChildIdx: 0,
  48. }
  49. }
  50. // NB: does not set the buffer manager's CurrentIdx, only the layouts active indecies!
  51. func (c *Container) InsertBufferInContainer(bufferIdx int) {
  52. for i := range c.Children {
  53. switch child := c.Children[i].(type) {
  54. case ContainerBuffers:
  55. child.Buffers = append(child.Buffers, bufferIdx)
  56. child.ActiveIdx = len(child.Buffers) - 1
  57. c.Children[i] = child
  58. c.ActiveChildIdx = i
  59. return
  60. case Container:
  61. child.InsertBufferInContainer(bufferIdx)
  62. c.Children[i] = child
  63. c.ActiveChildIdx = i
  64. return
  65. }
  66. }
  67. c.Children[0] = ContainerBuffers{
  68. Buffers: []int{bufferIdx},
  69. ActiveIdx: 0,
  70. }
  71. c.ActiveChildIdx = 0
  72. }
  73. // ny funksjon som setter in i aktiv
  74. func (lm *LayoutManager) InsertBuffer(bufferIdx int, newNode bool) {
  75. // follow active child trail to find the active buffer container, if not newNode insert in there using InsertBufferInContainer,
  76. // else: make new containerbuffers in that current active container, if it's full then split the containerbuffers into a new containernode
  77. // and then a new containerbuffers is made and the bufferidx is put there
  78. }