Compare commits

...

3 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

View File

@@ -157,6 +157,8 @@ type GuiConfig struct {
// Status panel view.
// One of 'dashboard' (default) | '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 {
@@ -702,7 +704,8 @@ func GetDefaultConfig() *UserConfig {
Frames: []string{"|", "/", "-", "\\"},
Rate: 50,
},
StatusPanelView: "dashboard",
StatusPanelView: "dashboard",
HorizontalPadding: 0,
},
Git: GitConfig{
Paging: PagingConfig{

View File

@@ -125,8 +125,10 @@ func GetWindowDimensions(args WindowArrangementArgs) map[string]boxlayout.Dimens
sideSectionWeight, mainSectionWeight := getMidSectionWeights(args)
sidePanelsDirection := boxlayout.COLUMN
sidePanelsPadding := args.UserConfig.Gui.HorizontalPadding
if shouldUsePortraitMode(args) {
sidePanelsDirection = boxlayout.ROW
sidePanelsPadding = 0
}
showInfoSection := args.UserConfig.Gui.ShowBottomLine ||
@@ -143,6 +145,7 @@ func GetWindowDimensions(args WindowArrangementArgs) map[string]boxlayout.Dimens
Children: []*boxlayout.Box{
{
Direction: sidePanelsDirection,
Padding: sidePanelsPadding,
Weight: 1,
Children: []*boxlayout.Box{
{
@@ -173,13 +176,16 @@ func GetWindowDimensions(args WindowArrangementArgs) map[string]boxlayout.Dimens
func mainPanelChildren(args WindowArrangementArgs) []*boxlayout.Box {
mainPanelsDirection := boxlayout.ROW
mainPanelsPadding := 0
if splitMainPanelSideBySide(args) {
mainPanelsDirection = boxlayout.COLUMN
mainPanelsPadding = args.UserConfig.Gui.HorizontalPadding
}
result := []*boxlayout.Box{
{
Direction: mainPanelsDirection,
Padding: mainPanelsPadding,
Children: mainSectionChildren(args),
Weight: 1,
},

View File

@@ -430,6 +430,10 @@
],
"description": "Status panel view.\nOne of 'dashboard' (default) | 'allBranchesLog'",
"default": "dashboard"
},
"horizontalPadding": {
"type": "integer",
"description": "Horizontal padding between views that are next to each other."
}
},
"additionalProperties": false,

View File

@@ -831,6 +831,17 @@ func (g *Gui) onResize() {
// 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.
func (g *Gui) drawFrameEdges(v *View, fgColor, bgColor Attribute) error {
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.
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()
// if GUI's size has changed, we need to redraw all views

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
// TODO: consider making there be one int and a type enum so we can't have size and Weight simultaneously defined
Weight int
// Padding between children
Padding int
}
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 {
availableSize = height
}
availableSize -= (len(children) - 1) * root.Padding
sizes := calcSizes(children, availableSize)
@@ -87,7 +91,7 @@ func ArrangeWindows(root *Box, x0, y0, width, height int) map[string]Dimensions
}
result = mergeDimensionMaps(result, resultForChild)
offset += boxSize
offset += boxSize + (i+1)*root.Padding
}
return result