Skip to content

Change side panel width calculation to work for larger numbers #4287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions pkg/gui/controllers/helpers/window_arrangement_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package helpers

import (
"fmt"
"math"
"strings"

"github.com/jesseduffield/lazycore/pkg/boxlayout"
Expand Down Expand Up @@ -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" {
Expand All @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should all be equivalent (and are if the tests prove anything), since the mainSectionWeight was always compared to the static side section 1 before. It will maintain its 1:1 and 1:2 ratios with this code.

}
} else if args.ScreenMode == types.SCREEN_FULL {
mainSectionWeight = 0
Expand Down
80 changes: 80 additions & 0 deletions pkg/gui/controllers/helpers/window_arrangement_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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───────────────────────────────╮│ │
│ ││ │
╰────────────────────────────────────╯╰───────────────────────────────────╯
<options──────────────────────────────────────────────────────>A<B────────>
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─────────────────────────────────────────────────────╮│ │
│ ││ │
╰──────────────────────────────────────────────────────────╯╰─────────────╯
<options──────────────────────────────────────────────────────>A<B────────>
A: statusSpacer1
B: information
`,
},
{
name: "half screen mode, enlargedSideViewLocation left",
mutateArgs: func(args *WindowArrangementArgs) {
Expand Down