From a69b985086ff0cfff93ef7a272e2e461fec8a993 Mon Sep 17 00:00:00 2001 From: mjarkk Date: Sat, 20 Apr 2019 15:56:23 +0200 Subject: Better UI on small screens --- pkg/gui/gui.go | 91 ++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 72 insertions(+), 19 deletions(-) (limited to 'pkg/gui') diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 8eacd3cf3..f0814f2eb 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -141,6 +141,7 @@ type guiState struct { DiffEntries []*commands.Commit MenuItemCount int // can't store the actual list because it's of interface{} type PreviousView string + SmallUI bool Platform commands.Platform Updating bool Panels *panelStates @@ -292,20 +293,84 @@ func (gui *Gui) onFocus(v *gocui.View) error { func (gui *Gui) layout(g *gocui.Gui) error { g.Highlight = true width, height := g.Size() + + smallUI := height < 28 + gui.State.SmallUI = smallUI + information := gui.Config.GetVersion() if gui.g.Mouse { donate := color.New(color.FgMagenta, color.Underline).Sprint(gui.Tr.SLocalize("Donate")) information = donate + " " + information } - leftSideWidth := width / 3 - statusFilesBoundary := 2 - filesBranchesBoundary := 2 * height / 5 - commitsBranchesBoundary := 3 * height / 5 + + minimumHeight := 16 + minimumWidth := 10 + if height < minimumHeight || width < minimumWidth { + v, err := g.SetView("limit", 0, 0, max(width-1, 2), max(height-1, 2), 0) + if err != nil { + if err.Error() != "unknown view" { + return err + } + v.Title = gui.Tr.SLocalize("NotEnoughSpace") + v.Wrap = true + g.SetViewOnTop("limit") + } + return nil + } + + var statusFilesBoundary int + var filesBranchesBoundary int + var commitsBranchesBoundary int + var commitsStashBoundary int optionsTop := height - 2 - commitsStashBoundary := optionsTop - 3 + + if smallUI { + currView := gui.g.CurrentView() + currentCyclebleView := "files" + if currView == nil { + currentCyclebleView = gui.State.PreviousView + } else { + viewName := currView.Name() + usePreviouseView := true + for _, view := range cyclableViews { + if view == viewName { + currentCyclebleView = viewName + usePreviouseView = false + break + } + } + if usePreviouseView { + currentCyclebleView = gui.State.PreviousView + } + } + + statusFilesBoundary = optionsTop - 12 + filesBranchesBoundary = optionsTop - 9 + commitsBranchesBoundary = optionsTop - 6 + commitsStashBoundary = optionsTop - 3 + + switch currentCyclebleView { + case "stash": + commitsStashBoundary = 11 + fallthrough + case "commits": + commitsBranchesBoundary = 8 + fallthrough + case "branches": + filesBranchesBoundary = 5 + fallthrough + case "files": + statusFilesBoundary = 2 + } + } else { + statusFilesBoundary = 2 + filesBranchesBoundary = 2 * height / 5 + commitsBranchesBoundary = 3 * height / 5 + commitsStashBoundary = optionsTop - 3 + } + optionsVersionBoundary := width - max(len(utils.Decolorise(information)), 1) - minimumHeight := 18 - minimumWidth := 10 + leftSideWidth := width / 3 appStatus := gui.statusManager.getStatusString() appStatusOptionsBoundary := 0 @@ -318,18 +383,6 @@ func (gui *Gui) layout(g *gocui.Gui) error { panelSpacing = 0 } - if height < minimumHeight || width < minimumWidth { - v, err := g.SetView("limit", 0, 0, max(width-1, 2), max(height-1, 2), 0) - if err != nil { - if err.Error() != "unknown view" { - return err - } - v.Title = gui.Tr.SLocalize("NotEnoughSpace") - v.Wrap = true - g.SetViewOnTop("limit") - } - return nil - } _, _ = g.SetViewOnBottom("limit") g.DeleteView("limit") -- cgit v1.2.3