Add foundation for resizing splits arbitrarily

This commit adds the ability to lock a split's width or height so
you can have splits that aren't equally sized. It isn't yet possible
for users to resize splits but the functionality has been implemented.
This commit is contained in:
Zachary Yedidia
2016-11-16 12:36:48 -05:00
parent 855c5283e4
commit 4ce02e4c85
2 changed files with 63 additions and 11 deletions

View File

@@ -43,8 +43,10 @@ type SplitTree struct {
x int
y int
width int
height int
width int
height int
lockWidth bool
lockHeight bool
tabNum int
}
@@ -145,20 +147,57 @@ func (s *SplitTree) Cleanup() {
// ResizeSplits resizes all the splits correctly
func (s *SplitTree) ResizeSplits() {
for i, node := range s.children {
lockedWidth := 0
lockedHeight := 0
lockedChildren := 0
for _, node := range s.children {
if n, ok := node.(*LeafNode); ok {
if s.kind == VerticalSplit {
n.view.width = s.width / len(s.children)
if n.view.lockWidth {
lockedWidth += n.view.width
lockedChildren++
}
} else {
if n.view.lockHeight {
lockedHeight += n.view.height
lockedChildren++
}
}
} else if n, ok := node.(*SplitTree); ok {
if s.kind == VerticalSplit {
if n.lockWidth {
lockedWidth += n.width
lockedChildren++
}
} else {
if n.lockHeight {
lockedHeight += n.height
lockedChildren++
}
}
}
}
x, y := 0, 0
for _, node := range s.children {
if n, ok := node.(*LeafNode); ok {
if s.kind == VerticalSplit {
if !n.view.lockWidth {
n.view.width = (s.width - lockedWidth) / (len(s.children) - lockedChildren)
}
n.view.height = s.height
n.view.x = s.x + n.view.width*i
n.view.x = s.x + x
n.view.y = s.y
x += n.view.width
} else {
n.view.height = s.height / len(s.children)
if !n.view.lockHeight {
n.view.height = (s.height - lockedHeight) / (len(s.children) - lockedChildren)
}
n.view.width = s.width
n.view.y = s.y + n.view.height*i
n.view.y = s.y + y
n.view.x = s.x
y += n.view.height
}
if n.view.Buf.Settings["statusline"].(bool) {
n.view.height--
@@ -168,17 +207,23 @@ func (s *SplitTree) ResizeSplits() {
n.view.matches = Match(n.view)
} else if n, ok := node.(*SplitTree); ok {
if s.kind == VerticalSplit {
n.width = s.width / len(s.children)
if !n.lockWidth {
n.width = (s.width - lockedWidth) / (len(s.children) - lockedChildren)
}
n.height = s.height
n.x = s.x + n.width*i
n.x = s.x + x
n.y = s.y
x += n.width
} else {
n.height = s.height / len(s.children)
if !n.lockHeight {
n.height = (s.height - lockedHeight) / (len(s.children) - lockedChildren)
}
n.width = s.width
n.y = s.y + n.height*i
n.y = s.y + y
n.x = s.x
y += n.height
}
n.ResizeSplits()
}

View File

@@ -38,6 +38,9 @@ type View struct {
width int
height int
lockWidth bool
lockHeight bool
// Where this view is located
x, y int
@@ -323,6 +326,10 @@ func (v *View) GetSoftWrapLocation(vx, vy int) (int, int) {
}
func (v *View) Bottomline() int {
if !v.Buf.Settings["softwrap"].(bool) {
return v.Topline + v.height
}
screenX, screenY := 0, 0
numLines := 0
for lineN := v.Topline; lineN < v.Topline+v.height; lineN++ {