layout_policy.go RawHistoryFolder
1package core
2
3// layoutAxis is a logical navigation axis, independent of rendering.
4type layoutAxis uint8
5
6const (
7 verticalAxis layoutAxis = iota
8 horizontalAxis
9)
10
11func (a layoutAxis) span(r Rect) int {
12 if a == verticalAxis {
13 return r.H
14 }
15 return r.W
16}
17func (a layoutAxis) offset(r *Rect, pixels int) {
18 if a == verticalAxis {
19 r.Y += pixels
20 } else {
21 r.X += pixels
22 }
23}
24
25// layoutPolicy keeps geometry capabilities distinct from workspace navigation.
26// Window state remains owned by Workspace; policies contain no mutable state.
27type layoutPolicy struct {
28 content, workspace layoutAxis
29 equalCells, appendLast, wraps bool
30}
31
32func (w *Workspace) policy() layoutPolicy {
33 if w.Overflow == OverflowCascade {
34 return layoutPolicy{content: verticalAxis, workspace: horizontalAxis, equalCells: true, appendLast: true, wraps: true}
35 }
36 if w.Overflow == OverflowFixed {
37 return layoutPolicy{content: horizontalAxis, workspace: verticalAxis, equalCells: true, appendLast: true}
38 }
39 return layoutPolicy{content: horizontalAxis, workspace: verticalAxis}
40}