diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2022-12-30 23:24:24 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2023-04-30 13:19:52 +1000 |
commit | 8edad826caf2fa48bfad33f9f8c4f3ba49a052da (patch) | |
tree | 0b49145e4f656e72441199b5a5c30176c898d7a7 /pkg/gui | |
parent | 826128a8e03fb50f7287029ebac93c85712faecb (diff) |
Begin refactoring gui
This begins a big refactor of moving more code out of the Gui struct into contexts, controllers, and helpers. We also move some code into structs in the
gui package purely for the sake of better encapsulation
Diffstat (limited to 'pkg/gui')
99 files changed, 3326 insertions, 2865 deletions
diff --git a/pkg/gui/app_status_manager.go b/pkg/gui/app_status_manager.go index 097a19438..02ba7779a 100644 --- a/pkg/gui/app_status_manager.go +++ b/pkg/gui/app_status_manager.go @@ -99,7 +99,8 @@ func (gui *Gui) renderAppStatus() { for range ticker.C { appStatus := gui.statusManager.getStatusString() gui.c.OnUIThread(func() error { - return gui.renderString(gui.Views.AppStatus, appStatus) + gui.c.SetViewContent(gui.Views.AppStatus, appStatus) + return nil }) if appStatus == "" { diff --git a/pkg/gui/arrangement.go b/pkg/gui/arrangement.go index ac6f2d9c1..d656f16d5 100644 --- a/pkg/gui/arrangement.go +++ b/pkg/gui/arrangement.go @@ -13,10 +13,14 @@ import ( const INFO_SECTION_PADDING = " " -func (gui *Gui) getWindowDimensions(informationStr string, appStatus string) map[string]boxlayout.Dimensions { - width, height := gui.g.Size() +type WindowArranger struct { + gui *Gui +} + +func (self *WindowArranger) getWindowDimensions(informationStr string, appStatus string) map[string]boxlayout.Dimensions { + width, height := self.gui.g.Size() - sideSectionWeight, mainSectionWeight := gui.getMidSectionWeights() + sideSectionWeight, mainSectionWeight := self.getMidSectionWeights() sidePanelsDirection := boxlayout.COLUMN portraitMode := width <= 84 && height > 45 @@ -25,13 +29,13 @@ func (gui *Gui) getWindowDimensions(informationStr string, appStatus string) map } mainPanelsDirection := boxlayout.ROW - if gui.splitMainPanelSideBySide() { + if self.splitMainPanelSideBySide() { mainPanelsDirection = boxlayout.COLUMN } - extrasWindowSize := gui.getExtrasWindowSize(height) + extrasWindowSize := self.getExtrasWindowSize(height) - showInfoSection := gui.c.UserConfig.Gui.ShowBottomLine || gui.State.Searching.isSearching || gui.isAnyModeActive() || gui.statusManager.showStatus() + showInfoSection := self.gui.c.UserConfig.Gui.ShowBottomLine || self.gui.State.Searching.isSearching || self.gui.isAnyModeActive() || self.gui.statusManager.showStatus() infoSectionSize := 0 if showInfoSection { infoSectionSize = 1 @@ -47,7 +51,7 @@ func (gui *Gui) getWindowDimensions(informationStr string, appStatus string) map { Direction: boxlayout.ROW, Weight: sideSectionWeight, - ConditionalChildren: gui.sidePanelChildren, + ConditionalChildren: self.sidePanelChildren, }, { Direction: boxlayout.ROW, @@ -55,7 +59,7 @@ func (gui *Gui) getWindowDimensions(informationStr string, appStatus string) map Children: []*boxlayout.Box{ { Direction: mainPanelsDirection, - Children: gui.mainSectionChildren(), + Children: self.mainSectionChildren(), Weight: 1, }, { @@ -69,7 +73,7 @@ func (gui *Gui) getWindowDimensions(informationStr string, appStatus string) map { Direction: boxlayout.COLUMN, Size: infoSectionSize, - Children: gui.infoSectionChildren(informationStr, appStatus), + Children: self.infoSectionChildren(informationStr, appStatus), }, }, } @@ -91,12 +95,12 @@ func MergeMaps[K comparable, V any](maps ...map[K]V) map[K]V { return result } -func (gui *Gui) mainSectionChildren() []*boxlayout.Box { - currentWindow := gui.currentWindow() +func (self *WindowArranger) mainSectionChildren() []*boxlayout.Box { + currentWindow := self.gui.helpers.Window.CurrentWindow() // if we're not in split mode we can just show the one main panel. Likewise if // the main panel is focused and we're in full-screen mode - if !gui.isMainPanelSplit() || (gui.State.ScreenMode == SCREEN_FULL && currentWindow == "main") { + if !self.gui.isMainPanelSplit() || (self.gui.State.ScreenMode == SCREEN_FULL && currentWindow == "main") { return []*boxlayout.Box{ { Window: "main", @@ -117,27 +121,27 @@ func (gui *Gui) mainSectionChildren() []*boxlayout.Box { } } -func (gui *Gui) getMidSectionWeights() (int, int) { - currentWindow := gui.currentWindow() +func (self *WindowArranger) getMidSectionWeights() (int, int) { + currentWindow := self.gui.helpers.Window.CurrentWindow() // we originally specified this as a ratio i.e. .20 would correspond to a weight of 1 against 4 - sidePanelWidthRatio := gui.c.UserConfig.Gui.SidePanelWidth + sidePanelWidthRatio := self.gui.c.UserConfig.Gui.SidePanelWidth // we could make this better by creating ratios like 2:3 rather than always 1:something mainSectionWeight := int(1/sidePanelWidthRatio) - 1 sideSectionWeight := 1 - if gui.splitMainPanelSideBySide() { + if self.splitMainPanelSideBySide() { mainSectionWeight = 5 // need to shrink side panel to make way for main panels if side-by-side } if currentWindow == "main" { - if gui.State.ScreenMode == SCREEN_HALF || gui.State.ScreenMode == SCREEN_FULL { + if self.gui.State.ScreenMode == SCREEN_HALF || self.gui.State.ScreenMode == SCREEN_FULL { sideSectionWeight = 0 } } else { - if gui.State.ScreenMode == SCREEN_HALF { + if self.gui.State.ScreenMode == SCREEN_HALF { mainSectionWeight = 1 - } else if gui.State.ScreenMode == SCREEN_FULL { + } else if self.gui.State.ScreenMode == SCREEN_FULL { mainSectionWeight = 0 } } @@ -145,8 +149,8 @@ func (gui *Gui) getMidSectionWeights() (int, int) { return sideSectionWeight, mainSectionWeight } -func (gui *Gui) infoSectionChildren(informationStr string, appStatus string) []*boxlayout.Box { - if gui.State.Searching.isSearching { +func (self *WindowArranger) infoSectionChildren(informationStr string, appStatus string) []*boxlayout.Box { + if self.gui.State.Searching.isSearching { return []*boxlayout.Box{ { Window: "searchPrefix", @@ -162,7 +166,7 @@ func (gui *Gui) infoSectionChildren(informationStr string, appStatus string) []* appStatusBox := &boxlayout.Box{Window: "appStatus"} optionsBox := &boxlayout.Box{Window: "options"} - if !gui.c.UserConfig.Gui.ShowBottomLine { + if !self.gui.c.UserConfig.Gui.ShowBottomLine { optionsBox.Weight = 0 appStatusBox.Weight = 1 } else { @@ -172,7 +176,7 @@ func (gui *Gui) infoSectionChildren(informationStr string, appStatus string) []* result := []*boxlayout.Box{appStatusBox, optionsBox} - if gui.c.UserConfig.Gui.ShowBo |