Compare commits

...
Author SHA1 Message Date
Stefan Haller a21c98b8d4 Add user config gui.horizontalPadding 2024-06-14 11:46:03 +02:00
Stefan Haller 851d17f456 WIP Clear screen before drawing views
We need this when there's padding between views.
2024-06-14 11:46:03 +02:00
Stefan Haller c26a9218a1 WIP Add Padding field to boxlayout.Box 2024-06-14 11:18:17 +02:00
5 changed files with 31 additions and 4 deletions
+4 -1
View File
@@ -157,6 +157,8 @@ type GuiConfig struct {
// Status panel view. // Status panel view.
// One of 'dashboard' (default) | 'allBranchesLog' // One of 'dashboard' (default) | 'allBranchesLog'
StatusPanelView string `yaml:"statusPanelView" jsonschema:"enum=dashboard,enum=allBranchesLog"` StatusPanelView string `yaml:"statusPanelView" jsonschema:"enum=dashboard,enum=allBranchesLog"`
// Horizontal padding between views that are next to each other.
HorizontalPadding int `yaml:"horizontalPadding"`
} }
func (c *GuiConfig) UseFuzzySearch() bool { func (c *GuiConfig) UseFuzzySearch() bool {
@@ -702,7 +704,8 @@ func GetDefaultConfig() *UserConfig {
Frames: []string{"|", "/", "-", "\\"}, Frames: []string{"|", "/", "-", "\\"},
Rate: 50, Rate: 50,
}, },
StatusPanelView: "dashboard", StatusPanelView: "dashboard",
HorizontalPadding: 0,
}, },
Git: GitConfig{ Git: GitConfig{
Paging: PagingConfig{ Paging: PagingConfig{
@@ -125,8 +125,10 @@ func GetWindowDimensions(args WindowArrangementArgs) map[string]boxlayout.Dimens
sideSectionWeight, mainSectionWeight := getMidSectionWeights(args) sideSectionWeight, mainSectionWeight := getMidSectionWeights(args)
sidePanelsDirection := boxlayout.COLUMN sidePanelsDirection := boxlayout.COLUMN
sidePanelsPadding := args.UserConfig.Gui.HorizontalPadding
if shouldUsePortraitMode(args) { if shouldUsePortraitMode(args) {
sidePanelsDirection = boxlayout.ROW sidePanelsDirection = boxlayout.ROW
sidePanelsPadding = 0
} }
showInfoSection := args.UserConfig.Gui.ShowBottomLine || showInfoSection := args.UserConfig.Gui.ShowBottomLine ||
@@ -143,6 +145,7 @@ func GetWindowDimensions(args WindowArrangementArgs) map[string]boxlayout.Dimens
Children: []*boxlayout.Box{ Children: []*boxlayout.Box{
{ {
Direction: sidePanelsDirection, Direction: sidePanelsDirection,
Padding: sidePanelsPadding,
Weight: 1, Weight: 1,
Children: []*boxlayout.Box{ Children: []*boxlayout.Box{
{ {
@@ -173,13 +176,16 @@ func GetWindowDimensions(args WindowArrangementArgs) map[string]boxlayout.Dimens
func mainPanelChildren(args WindowArrangementArgs) []*boxlayout.Box { func mainPanelChildren(args WindowArrangementArgs) []*boxlayout.Box {
mainPanelsDirection := boxlayout.ROW mainPanelsDirection := boxlayout.ROW
mainPanelsPadding := 0
if splitMainPanelSideBySide(args) { if splitMainPanelSideBySide(args) {
mainPanelsDirection = boxlayout.COLUMN mainPanelsDirection = boxlayout.COLUMN
mainPanelsPadding = args.UserConfig.Gui.HorizontalPadding
} }
result := []*boxlayout.Box{ result := []*boxlayout.Box{
{ {
Direction: mainPanelsDirection, Direction: mainPanelsDirection,
Padding: mainPanelsPadding,
Children: mainSectionChildren(args), Children: mainSectionChildren(args),
Weight: 1, Weight: 1,
}, },
+4
View File
@@ -430,6 +430,10 @@
], ],
"description": "Status panel view.\nOne of 'dashboard' (default) | 'allBranchesLog'", "description": "Status panel view.\nOne of 'dashboard' (default) | 'allBranchesLog'",
"default": "dashboard" "default": "dashboard"
},
"horizontalPadding": {
"type": "integer",
"description": "Horizontal padding between views that are next to each other."
} }
}, },
"additionalProperties": false, "additionalProperties": false,
+12 -2
View File
@@ -831,6 +831,17 @@ func (g *Gui) onResize() {
// g.screen.Sync() // g.screen.Sync()
} }
func (g *Gui) clear(fg, bg Attribute) (int, int) {
st := getTcellStyle(oldStyle{fg: fg, bg: bg, outputMode: g.outputMode})
w, h := Screen.Size()
for row := 0; row < h; row++ {
for col := 0; col < w; col++ {
Screen.SetContent(col, row, ' ', nil, st)
}
}
return w, h
}
// drawFrameEdges draws the horizontal and vertical edges of a view. // drawFrameEdges draws the horizontal and vertical edges of a view.
func (g *Gui) drawFrameEdges(v *View, fgColor, bgColor Attribute) error { func (g *Gui) drawFrameEdges(v *View, fgColor, bgColor Attribute) error {
runeH, runeV := '─', '│' runeH, runeV := '─', '│'
@@ -1137,8 +1148,7 @@ func (g *Gui) drawListFooter(v *View, fgColor, bgColor Attribute) error {
// flush updates the gui, re-drawing frames and buffers. // flush updates the gui, re-drawing frames and buffers.
func (g *Gui) flush() error { func (g *Gui) flush() error {
// pretty sure we don't need this, but keeping it here in case we get weird visual artifacts g.clear(g.FgColor, g.BgColor)
// g.clear(g.FgColor, g.BgColor)
maxX, maxY := Screen.Size() maxX, maxY := Screen.Size()
// if GUI's size has changed, we need to redraw all views // if GUI's size has changed, we need to redraw all views
+5 -1
View File
@@ -50,6 +50,9 @@ type Box struct {
// dynamic size. Once all statically sized children have been considered, Weight decides how much of the remaining space will be taken up by the box // dynamic size. Once all statically sized children have been considered, Weight decides how much of the remaining space will be taken up by the box
// TODO: consider making there be one int and a type enum so we can't have size and Weight simultaneously defined // TODO: consider making there be one int and a type enum so we can't have size and Weight simultaneously defined
Weight int Weight int
// Padding between children
Padding int
} }
func ArrangeWindows(root *Box, x0, y0, width, height int) map[string]Dimensions { func ArrangeWindows(root *Box, x0, y0, width, height int) map[string]Dimensions {
@@ -71,6 +74,7 @@ func ArrangeWindows(root *Box, x0, y0, width, height int) map[string]Dimensions
} else { } else {
availableSize = height availableSize = height
} }
availableSize -= (len(children) - 1) * root.Padding
sizes := calcSizes(children, availableSize) sizes := calcSizes(children, availableSize)
@@ -87,7 +91,7 @@ func ArrangeWindows(root *Box, x0, y0, width, height int) map[string]Dimensions
} }
result = mergeDimensionMaps(result, resultForChild) result = mergeDimensionMaps(result, resultForChild)
offset += boxSize offset += boxSize + (i+1)*root.Padding
} }
return result return result