summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-01-29 18:38:59 +1100
committerJesse Duffield <jessedduffield@gmail.com>2020-01-29 18:44:50 +1100
commit1a6d2690634b255f15fe0bdc424829666e6fe87a (patch)
tree0d9e7263d969564ca576683b5eb056f77771a80e
parentb64953ebdb7ea4bd535ebd09f8387f1ff2e71114 (diff)
split main view vertically
When staging lines (or doing anything that requires the main view to split into two) we want to split vertically if there's not much width available in the window. If there is enough width we will split horizontally. The aim here is to allow for sufficient room in the side panel. We might need to tweak this or make it configurable but I think it's set to a pretty reasonable default i.e. switching to split vertically when the window width falls under 220
-rw-r--r--pkg/gui/gui.go31
1 files changed, 21 insertions, 10 deletions
diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go
index 45229974a..7da7f53fa 100644
--- a/pkg/gui/gui.go
+++ b/pkg/gui/gui.go
@@ -460,10 +460,22 @@ func (gui *Gui) layout(g *gocui.Gui) error {
textColor := theme.GocuiDefaultTextColor
leftSideWidth := width / 3
panelSplitX := width - 1
+ mainPanelRight := width - 1
+ secondaryPanelLeft := width - 1
+ secondaryPanelTop := 0
+ mainPanelBottom := height - 2
if gui.State.SplitMainPanel {
- units := 7
- leftSideWidth = width / units
- panelSplitX = (1 + ((units - 1) / 2)) * width / units
+ if width < 220 {
+ mainPanelBottom = height/2 - 1
+ secondaryPanelTop = mainPanelBottom + 1
+ secondaryPanelLeft = leftSideWidth + 1
+ } else {
+ units := 5
+ leftSideWidth = width / units
+ panelSplitX = (1 + ((units - 1) / 2)) * width / units
+ mainPanelRight = panelSplitX
+ secondaryPanelLeft = panelSplitX + 1
+ }
}
main := "main"
@@ -475,11 +487,10 @@ func (gui *Gui) layout(g *gocui.Gui) error {
}
// reading more lines into main view buffers upon resize
- mainHeight := height - 2
prevMainView, err := gui.g.View("main")
if err == nil {
_, prevMainHeight := prevMainView.Size()
- heightDiff := mainHeight - 1 - prevMainHeight
+ heightDiff := mainPanelBottom - prevMainHeight
if heightDiff > 0 {
if manager, ok := gui.viewBufferManagerMap["main"]; ok {
manager.ReadLines(heightDiff)
@@ -490,7 +501,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
}
}
- v, err := g.SetView(main, leftSideWidth+panelSpacing, 0, panelSplitX, mainHeight, gocui.LEFT)
+ v, err := g.SetView(main, leftSideWidth+panelSpacing, 0, mainPanelRight, mainPanelBottom, gocui.LEFT)
if err != nil {
if err.Error() != "unknown view" {
return err
@@ -504,7 +515,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
if !gui.State.SplitMainPanel {
hiddenViewOffset = 9999
}
- secondaryView, err := g.SetView(secondary, panelSplitX+1+hiddenViewOffset, hiddenViewOffset, width-1+hiddenViewOffset, mainHeight+hiddenViewOffset, gocui.LEFT)
+ secondaryView, err := g.SetView(secondary, secondaryPanelLeft+hiddenViewOffset, hiddenViewOffset+secondaryPanelTop, width-1+hiddenViewOffset, height-2+hiddenViewOffset, gocui.LEFT)
if err != nil {
if err.Error() != "unknown view" {
return err
@@ -580,7 +591,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
if gui.getCommitMessageView() == nil {
// doesn't matter where this view starts because it will be hidden
- if commitMessageView, err := g.SetView("commitMessage", width, height, width*2, height*2, 0); err != nil {
+ if commitMessageView, err := g.SetView("commitMessage", hiddenViewOffset, hiddenViewOffset, hiddenViewOffset+10, hiddenViewOffset+10, 0); err != nil {
if err.Error() != "unknown view" {
return err
}
@@ -594,7 +605,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
if check, _ := g.View("credentials"); check == nil {
// doesn't matter where this view starts because it will be hidden
- if credentialsView, err := g.SetView("credentials", width, height, width*2, height*2, 0); err != nil {
+ if credentialsView, err := g.SetView("credentials", hiddenViewOffset, hiddenViewOffset, hiddenViewOffset+10, hiddenViewOffset+10, 0); err != nil {
if err.Error() != "unknown view" {
return err
}
@@ -608,7 +619,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
}
}
- if appStatusView, err := g.SetView("appStatus", -1, height-2, width, height, 0); err != nil {
+ if appStatusView, err := g.SetView("appStatus", hiddenViewOffset, hiddenViewOffset, hiddenViewOffset+10, hiddenViewOffset+10, 0); err != nil {
if err.Error() != "unknown view" {
return err
}