diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2026-02-10 09:30:42 -0500 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2026-02-10 09:30:42 -0500 |
| commit | 3ce04a4d3dc8d174b520d85804e5c8dce8c5d08f (patch) | |
| tree | 8ae271f0f151e1870b25574a88218f2040841247 /layout/resize.go | |
| parent | fa47463d8fa0dbd1b12ef227c15fa573e45244cd (diff) | |
| download | gui-3ce04a4d3dc8d174b520d85804e5c8dce8c5d08f.zip | |
add layout resize functions
Diffstat (limited to 'layout/resize.go')
| -rw-r--r-- | layout/resize.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/layout/resize.go b/layout/resize.go new file mode 100644 index 0000000..1d3d6f1 --- /dev/null +++ b/layout/resize.go @@ -0,0 +1,35 @@ +package layout + +import "image" + +// ResizeAll resizes a layout to consume all of its parent's area. +func ResizeAll(r image.Rectangle) image.Rectangle { return r } + +// ResizeQuad1 resizes a layout to consume the top-right quadrant of its parent. +func ResizeQuad1(r image.Rectangle) image.Rectangle { + mid := midpoint(r) + return image.Rect(mid.X, r.Min.Y, r.Max.X, mid.Y) +} + +// ResizeQuad2 resizes a layout to consume the top-left quadrant of its parent. +func ResizeQuad2(r image.Rectangle) image.Rectangle { + mid := midpoint(r) + return image.Rectangle{r.Min, mid} +} + +// ResizeQuad3 resizes a layout to consume the bottom-left quadrant of its parent. +func ResizeQuad3(r image.Rectangle) image.Rectangle { + mid := midpoint(r) + return image.Rect(r.Min.X, mid.Y, mid.X, r.Max.Y) +} + +// ResizeQuad4 resizes a layout to consume the bottom-right quadrant of its parent. +func ResizeQuad4(r image.Rectangle) image.Rectangle { + mid := midpoint(r) + return image.Rectangle{mid, r.Max} +} + +// midpoint returns the point in the middle of a rectangle. +func midpoint(r image.Rectangle) image.Point { + return r.Min.Add(r.Max).Div(2) +} |