diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2024-01-19 22:43:07 -0500 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2024-01-19 22:43:07 -0500 |
| commit | 95944c92c6d9171e3a8a2619e62bbfa29d48bfef (patch) | |
| tree | e48c3bf421d69ef48ea9dade43f86ff9dc30e05b /main.go | |
| parent | 5d107e1443baa6762bbb30b62de68a25c011cf79 (diff) | |
| download | volute-95944c92c6d9171e3a8a2619e62bbfa29d48bfef.zip | |
refine widget screen space allocation
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 27 |
1 files changed, 25 insertions, 2 deletions
@@ -38,8 +38,8 @@ func run() { Rows: []int{2, 8, 8}, Background: color.Gray{255}, Gap: 1, - Split: layout.EvenSplit, - SplitRows: layout.EvenSplit, + Split: split, + SplitRows: splitRows, Margin: 0, Border: 0, BorderColor: color.Gray{16}, @@ -97,6 +97,29 @@ Loop: } } +func split(elements int, space int) []int { + bounds := make([]int, elements) + widths := []int{ + widget.TextSize("displacement (cc)").X, + widget.TextSize("123456").X, + } + for i := 0; i < elements && space > 0; i++ { + bounds[i] = min(widths[min(i, len(widths)-1)], space) + space -= bounds[i] + } + return bounds +} + +func splitRows(elements int, space int) []int { + bounds := make([]int, elements) + height := widget.TextSize("1").Y + for i := 0; i < elements && space > 0; i++ { + bounds[i] = min(height, space) + space -= bounds[i] + } + return bounds +} + func main() { mainthread.Run(run) } |