summaryrefslogtreecommitdiffstats
path: root/pkg/gui
diff options
context:
space:
mode:
authormjarkk <mkopenga@gmail.com>2019-04-20 15:56:23 +0200
committermjarkk <mkopenga@gmail.com>2019-04-20 15:56:23 +0200
commita69b985086ff0cfff93ef7a272e2e461fec8a993 (patch)
tree1aee206b3fabce8011c4d3f779d1129842ab8b54 /pkg/gui
parent471733fe03f7f49734a50f31affcbec0a780164c (diff)
Better UI on small screens
Diffstat (limited to 'pkg/gui')
-rw-r--r--pkg/gui/gui.go91
1 files changed, 72 insertions, 19 deletions
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")