okami.mom/ultraviolet
git clone https://git.nkp.pet/okami.mom/ultraviolet
89c142e
upstream
1package layout 2 3import ( 4"fmt" 5) 6 7// Flex controls how leftover space is distributed once every segment's 8// constraint has been resolved. It is analogous to the CSS 9// justify-content property and is used together with [Layout]. 10type Flex int 11 12const ( 13 14// FlexStart pushes segments to the leading edge of the area, leaving 15// any surplus space at the trailing edge. 16// 17// # Examples 18// 19// <------------------------------------80 px-------------------------------------> 20// ┌────16 px─────┐┌──────20 px───────┐┌──────20 px───────┐ 21// │ Percent(20) ││ Length(20) ││ Fixed(20) │ 22// └──────────────┘└──────────────────┘└──────────────────┘ 23// 24// <------------------------------------80 px-------------------------------------> 25// ┌──────20 px───────┐┌──────20 px───────┐ 26// │ Max(20) ││ Max(20) │ 27// └──────────────────┘└──────────────────┘ 28// 29// <------------------------------------80 px-------------------------------------> 30// ┌──────20 px───────┐ 31// │ Max(20) │ 32// └──────────────────┘ 33FlexStart Flex = iota 34 35// FlexLegacy fills the entire area by assigning surplus space to the 36// lowest-priority trailing segment. This reproduces the original 37// Ratatui/tui-rs layout behaviour. 38// 39// The examples below show how surplus space is allocated for different 40// constraint combinations. Recall the priority order (highest first): 41// 42// - [Min] 43// - [Max] 44// - [Len] 45// - [Percent] 46// - [Ratio] 47// - [Fill] 48// 49// With all-[Len] constraints the surplus goes to the final segment. 50// 51// <----------------------------------- 80 px ------------------------------------> 52// ┌──────20 px───────┐┌──────20 px───────┐┌────────────────40 px─────────────────┐ 53// │ Length(20) ││ Length(20) ││ Length(20) │ 54// └──────────────────┘└──────────────────┘└──────────────────────────────────────┘ 55// ^^^^^^^^^^^^^^^^ EXCESS ^^^^^^^^^^^^^^^^ 56// 57// [Fill] has the lowest priority, so it always absorbs surplus. 58// 59// <----------------------------------- 80 px ------------------------------------> 60// ┌──────20 px───────┐┌──────20 px───────┐┌──────20 px───────┐┌──────20 px───────┐ 61// │ Fill(0) ││ Max(20) ││ Length(20) ││ Length(20) │ 62// └──────────────────┘└──────────────────┘└──────────────────┘└──────────────────┘ 63// ^^^^^^ EXCESS ^^^^^^ 64// 65// # Examples 66// 67// <------------------------------------80 px-------------------------------------> 68// ┌──────────────────────────60 px───────────────────────────┐┌──────20 px───────┐ 69// │ Min(20) ││ Max(20) │ 70// └──────────────────────────────────────────────────────────┘└──────────────────┘ 71// 72// <------------------------------------80 px-------------------------------------> 73// ┌────────────────────────────────────80 px─────────────────────────────────────┐ 74// │ Max(20) │ 75// └──────────────────────────────────────────────────────────────────────────────┘ 76FlexLegacy 77 78// FlexEnd pushes segments to the trailing edge of the area, leaving 79// surplus space at the leading edge. 80// 81// # Examples 82// 83// <------------------------------------80 px-------------------------------------> 84// ┌────16 px─────┐┌──────20 px───────┐┌──────20 px───────┐ 85// │ Percent(20) ││ Length(20) ││ Length(20) │ 86// └──────────────┘└──────────────────┘└──────────────────┘ 87// 88// <------------------------------------80 px-------------------------------------> 89// ┌──────20 px───────┐┌──────20 px───────┐ 90// │ Max(20) ││ Max(20) │ 91// └──────────────────┘└──────────────────┘ 92// 93// <------------------------------------80 px-------------------------------------> 94// ┌──────20 px───────┐ 95// │ Max(20) │ 96// └──────────────────┘ 97FlexEnd 98 99// FlexCenter places segments in the middle of the area, distributing 100// surplus space equally before the first and after the last segment. 101// 102// # Examples 103// 104// <------------------------------------80 px-------------------------------------> 105// ┌────16 px─────┐┌──────20 px───────┐┌──────20 px───────┐ 106// │ Percent(20) ││ Length(20) ││ Length(20) │ 107// └──────────────┘└──────────────────┘└──────────────────┘ 108// 109// <------------------------------------80 px-------------------------------------> 110// ┌──────20 px───────┐┌──────20 px───────┐ 111// │ Max(20) ││ Max(20) │ 112// └──────────────────┘└──────────────────┘ 113// 114// <------------------------------------80 px-------------------------------------> 115// ┌──────20 px───────┐ 116// │ Max(20) │ 117// └──────────────────┘ 118FlexCenter 119 120// FlexSpaceBetween distributes surplus space equally between adjacent 121// segments, with no space before the first or after the last. 122// 123// # Examples 124// 125// <------------------------------------80 px-------------------------------------> 126// ┌────16 px─────┐ ┌──────20 px───────┐ ┌──────20 px───────┐ 127// │ Percent(20) │ │ Length(20) │ │ Length(20) │ 128// └──────────────┘ └──────────────────┘ └──────────────────┘ 129// 130// <------------------------------------80 px-------------------------------------> 131// ┌──────20 px───────┐ ┌──────20 px───────┐ 132// │ Max(20) │ │ Max(20) │ 133// └──────────────────┘ └──────────────────┘ 134// 135// <------------------------------------80 px-------------------------------------> 136// ┌────────────────────────────────────80 px─────────────────────────────────────┐ 137// │ Max(20) │ 138// └──────────────────────────────────────────────────────────────────────────────┘ 139FlexSpaceBetween 140 141// FlexSpaceEvenly distributes surplus space so that every gap 142// (including before the first and after the last segment) is the same width. 143// 144// # Examples 145// 146// <------------------------------------80 px-------------------------------------> 147// ┌────16 px─────┐ ┌──────20 px───────┐ ┌──────20 px───────┐ 148// │ Percent(20) │ │ Length(20) │ │ Length(20) │ 149// └──────────────┘ └──────────────────┘ └──────────────────┘ 150// 151// <------------------------------------80 px-------------------------------------> 152// ┌──────20 px───────┐ ┌──────20 px───────┐ 153// │ Max(20) │ │ Max(20) │ 154// └──────────────────┘ └──────────────────┘ 155// 156// <------------------------------------80 px-------------------------------------> 157// ┌──────20 px───────┐ 158// │ Max(20) │ 159// └──────────────────┘ 160FlexSpaceEvenly 161 162// FlexSpaceAround places equal space on both sides of each segment. 163// Adjacent segments therefore have twice the gap of the outer edges. 164// 165// # Examples 166// 167// <------------------------------------80 px-------------------------------------> 168// ┌────16 px─────┐ ┌──────20 px───────┐ ┌──────20 px───────┐ 169// │ Percent(20) │ │ Length(20) │ │ Length(20) │ 170// └──────────────┘ └──────────────────┘ └──────────────────┘ 171// 172// <------------------------------------80 px-------------------------------------> 173// ┌──────20 px───────┐ ┌──────20 px───────┐ 174// │ Max(20) │ │ Max(20) │ 175// └──────────────────┘ └──────────────────┘ 176// 177// <------------------------------------80 px-------------------------------------> 178// ┌──────20 px───────┐ 179// │ Max(20) │ 180// └──────────────────┘ 181FlexSpaceAround 182) 183 184func (f Flex )String ()string { 185switch f { 186case FlexCenter : 187return "Center" 188 189case FlexEnd : 190return "End" 191 192case FlexLegacy : 193return "Legacy" 194 195case FlexSpaceAround : 196return "Space Around" 197 198case FlexSpaceBetween : 199return "Space Between" 200 201case FlexSpaceEvenly : 202return "Space Evenly" 203 204case FlexStart : 205return "Start" 206 207default : 208return fmt .Sprintf ("Flex(%d)" ,f ) 209 } 210}