From 9d0740427e80a12a4f9b90dc96f70214b73d8a75 Mon Sep 17 00:00:00 2001 From: Chris McDonnell Date: Wed, 19 Feb 2025 00:19:59 -0500 Subject: [PATCH] Change side panel width calculation to work for larger numbers This technically is a breaking change for some existing numbers, but it stays the same for default case, and isn't much different for others --- .../helpers/window_arrangement_helper.go | 15 ++-- .../helpers/window_arrangement_helper_test.go | 80 +++++++++++++++++++ 2 files changed, 88 insertions(+), 7 deletions(-) diff --git a/pkg/gui/controllers/helpers/window_arrangement_helper.go b/pkg/gui/controllers/helpers/window_arrangement_helper.go index a80d9282f..393b0ffb1 100644 --- a/pkg/gui/controllers/helpers/window_arrangement_helper.go +++ b/pkg/gui/controllers/helpers/window_arrangement_helper.go @@ -2,6 +2,7 @@ package helpers import ( "fmt" + "math" "strings" "github.com/jesseduffield/lazycore/pkg/boxlayout" @@ -237,14 +238,14 @@ func mainSectionChildren(args WindowArrangementArgs) []*boxlayout.Box { } func getMidSectionWeights(args WindowArrangementArgs) (int, int) { - // we originally specified this as a ratio i.e. .20 would correspond to a weight of 1 against 4 sidePanelWidthRatio := args.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 + // Using 120 so that the default of 0.3333 will remain consistent with previous behavior + const maxColumnCount = 120 + mainSectionWeight := int(math.Round(maxColumnCount * (1 - sidePanelWidthRatio))) + sideSectionWeight := int(math.Round(maxColumnCount * sidePanelWidthRatio)) if splitMainPanelSideBySide(args) { - mainSectionWeight = 5 // need to shrink side panel to make way for main panels if side-by-side + mainSectionWeight = sideSectionWeight * 5 // need to shrink side panel to make way for main panels if side-by-side } if args.CurrentWindow == "main" || args.CurrentWindow == "secondary" { @@ -254,9 +255,9 @@ func getMidSectionWeights(args WindowArrangementArgs) (int, int) { } else { if args.ScreenMode == types.SCREEN_HALF { if args.UserConfig.Gui.EnlargedSideViewLocation == "top" { - mainSectionWeight = 2 + mainSectionWeight = sideSectionWeight * 2 } else { - mainSectionWeight = 1 + mainSectionWeight = sideSectionWeight } } else if args.ScreenMode == types.SCREEN_FULL { mainSectionWeight = 0 diff --git a/pkg/gui/controllers/helpers/window_arrangement_helper_test.go b/pkg/gui/controllers/helpers/window_arrangement_helper_test.go index e69a4bf3a..d8a6f739c 100644 --- a/pkg/gui/controllers/helpers/window_arrangement_helper_test.go +++ b/pkg/gui/controllers/helpers/window_arrangement_helper_test.go @@ -202,6 +202,86 @@ func TestGetWindowDimensions(t *testing.T) { B: information `, }, + { + name: "0.5 SidePanelWidth", + mutateArgs: func(args *WindowArrangementArgs) { + args.UserConfig.Gui.SidePanelWidth = 0.5 + }, + expected: ` + ╭status──────────────────────────────╮╭main───────────────────────────────╮ + │ ││ │ + ╰────────────────────────────────────╯│ │ + ╭files───────────────────────────────╮│ │ + │ ││ │ + │ ││ │ + │ ││ │ + │ ││ │ + │ ││ │ + │ ││ │ + ╰────────────────────────────────────╯│ │ + ╭branches────────────────────────────╮│ │ + │ ││ │ + │ ││ │ + │ ││ │ + │ ││ │ + │ ││ │ + │ ││ │ + ╰────────────────────────────────────╯│ │ + ╭commits─────────────────────────────╮│ │ + │ ││ │ + │ ││ │ + │ ││ │ + │ ││ │ + │ ││ │ + ╰────────────────────────────────────╯│ │ + ╭stash───────────────────────────────╮│ │ + │ ││ │ + ╰────────────────────────────────────╯╰───────────────────────────────────╯ + A + A: statusSpacer1 + B: information + `, + }, + { + name: "0.8 SidePanelWidth", + mutateArgs: func(args *WindowArrangementArgs) { + args.UserConfig.Gui.SidePanelWidth = 0.8 + }, + expected: ` + ╭status────────────────────────────────────────────────────╮╭main─────────╮ + │ ││ │ + ╰──────────────────────────────────────────────────────────╯│ │ + ╭files─────────────────────────────────────────────────────╮│ │ + │ ││ │ + │ ││ │ + │ ││ │ + │ ││ │ + │ ││ │ + │ ││ │ + ╰──────────────────────────────────────────────────────────╯│ │ + ╭branches──────────────────────────────────────────────────╮│ │ + │ ││ │ + │ ││ │ + │ ││ │ + │ ││ │ + │ ││ │ + │ ││ │ + ╰──────────────────────────────────────────────────────────╯│ │ + ╭commits───────────────────────────────────────────────────╮│ │ + │ ││ │ + │ ││ │ + │ ││ │ + │ ││ │ + │ ││ │ + ╰──────────────────────────────────────────────────────────╯│ │ + ╭stash─────────────────────────────────────────────────────╮│ │ + │ ││ │ + ╰──────────────────────────────────────────────────────────╯╰─────────────╯ + A + A: statusSpacer1 + B: information + `, + }, { name: "half screen mode, enlargedSideViewLocation left", mutateArgs: func(args *WindowArrangementArgs) {