Skip to content

Commit 9d07404

Browse files
Chris McDonnelljesseduffield
authored andcommitted
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
1 parent e62aeb9 commit 9d07404

File tree

2 files changed

+88
-7
lines changed

2 files changed

+88
-7
lines changed

pkg/gui/controllers/helpers/window_arrangement_helper.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package helpers
22

33
import (
44
"fmt"
5+
"math"
56
"strings"
67

78
"github.com/jesseduffield/lazycore/pkg/boxlayout"
@@ -237,14 +238,14 @@ func mainSectionChildren(args WindowArrangementArgs) []*boxlayout.Box {
237238
}
238239

239240
func getMidSectionWeights(args WindowArrangementArgs) (int, int) {
240-
// we originally specified this as a ratio i.e. .20 would correspond to a weight of 1 against 4
241241
sidePanelWidthRatio := args.UserConfig.Gui.SidePanelWidth
242-
// we could make this better by creating ratios like 2:3 rather than always 1:something
243-
mainSectionWeight := int(1/sidePanelWidthRatio) - 1
244-
sideSectionWeight := 1
242+
// Using 120 so that the default of 0.3333 will remain consistent with previous behavior
243+
const maxColumnCount = 120
244+
mainSectionWeight := int(math.Round(maxColumnCount * (1 - sidePanelWidthRatio)))
245+
sideSectionWeight := int(math.Round(maxColumnCount * sidePanelWidthRatio))
245246

246247
if splitMainPanelSideBySide(args) {
247-
mainSectionWeight = 5 // need to shrink side panel to make way for main panels if side-by-side
248+
mainSectionWeight = sideSectionWeight * 5 // need to shrink side panel to make way for main panels if side-by-side
248249
}
249250

250251
if args.CurrentWindow == "main" || args.CurrentWindow == "secondary" {
@@ -254,9 +255,9 @@ func getMidSectionWeights(args WindowArrangementArgs) (int, int) {
254255
} else {
255256
if args.ScreenMode == types.SCREEN_HALF {
256257
if args.UserConfig.Gui.EnlargedSideViewLocation == "top" {
257-
mainSectionWeight = 2
258+
mainSectionWeight = sideSectionWeight * 2
258259
} else {
259-
mainSectionWeight = 1
260+
mainSectionWeight = sideSectionWeight
260261
}
261262
} else if args.ScreenMode == types.SCREEN_FULL {
262263
mainSectionWeight = 0

pkg/gui/controllers/helpers/window_arrangement_helper_test.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,86 @@ func TestGetWindowDimensions(t *testing.T) {
202202
B: information
203203
`,
204204
},
205+
{
206+
name: "0.5 SidePanelWidth",
207+
mutateArgs: func(args *WindowArrangementArgs) {
208+
args.UserConfig.Gui.SidePanelWidth = 0.5
209+
},
210+
expected: `
211+
╭status──────────────────────────────╮╭main───────────────────────────────╮
212+
│ ││ │
213+
╰────────────────────────────────────╯│ │
214+
╭files───────────────────────────────╮│ │
215+
│ ││ │
216+
│ ││ │
217+
│ ││ │
218+
│ ││ │
219+
│ ││ │
220+
│ ││ │
221+
╰────────────────────────────────────╯│ │
222+
╭branches────────────────────────────╮│ │
223+
│ ││ │
224+
│ ││ │
225+
│ ││ │
226+
│ ││ │
227+
│ ││ │
228+
│ ││ │
229+
╰────────────────────────────────────╯│ │
230+
╭commits─────────────────────────────╮│ │
231+
│ ││ │
232+
│ ││ │
233+
│ ││ │
234+
│ ││ │
235+
│ ││ │
236+
╰────────────────────────────────────╯│ │
237+
╭stash───────────────────────────────╮│ │
238+
│ ││ │
239+
╰────────────────────────────────────╯╰───────────────────────────────────╯
240+
<options──────────────────────────────────────────────────────>A<B────────>
241+
A: statusSpacer1
242+
B: information
243+
`,
244+
},
245+
{
246+
name: "0.8 SidePanelWidth",
247+
mutateArgs: func(args *WindowArrangementArgs) {
248+
args.UserConfig.Gui.SidePanelWidth = 0.8
249+
},
250+
expected: `
251+
╭status────────────────────────────────────────────────────╮╭main─────────╮
252+
│ ││ │
253+
╰──────────────────────────────────────────────────────────╯│ │
254+
╭files─────────────────────────────────────────────────────╮│ │
255+
│ ││ │
256+
│ ││ │
257+
│ ││ │
258+
│ ││ │
259+
│ ││ │
260+
│ ││ │
261+
╰──────────────────────────────────────────────────────────╯│ │
262+
╭branches──────────────────────────────────────────────────╮│ │
263+
│ ││ │
264+
│ ││ │
265+
│ ││ │
266+
│ ││ │
267+
│ ││ │
268+
│ ││ │
269+
╰──────────────────────────────────────────────────────────╯│ │
270+
╭commits───────────────────────────────────────────────────╮│ │
271+
│ ││ │
272+
│ ││ │
273+
│ ││ │
274+
│ ││ │
275+
│ ││ │
276+
╰──────────────────────────────────────────────────────────╯│ │
277+
╭stash─────────────────────────────────────────────────────╮│ │
278+
│ ││ │
279+
╰──────────────────────────────────────────────────────────╯╰─────────────╯
280+
<options──────────────────────────────────────────────────────>A<B────────>
281+
A: statusSpacer1
282+
B: information
283+
`,
284+
},
205285
{
206286
name: "half screen mode, enlargedSideViewLocation left",
207287
mutateArgs: func(args *WindowArrangementArgs) {

0 commit comments

Comments
 (0)