diff options
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) +} |