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/draw.go | |
| parent | fa47463d8fa0dbd1b12ef227c15fa573e45244cd (diff) | |
| download | gui-3ce04a4d3dc8d174b520d85804e5c8dce8c5d08f.zip | |
add layout resize functions
Diffstat (limited to 'layout/draw.go')
| -rw-r--r-- | layout/draw.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/layout/draw.go b/layout/draw.go new file mode 100644 index 0000000..760a149 --- /dev/null +++ b/layout/draw.go @@ -0,0 +1,27 @@ +package layout + +import ( + "image" + "image/color" + "image/draw" +) + +// subimager is implemented by most Image types. +type subimager interface { + SubImage(image.Rectangle) image.Image +} + +// Subimage returns an image representing the portion of the image m visible through r. +// The returned value shares pixels with the original. +// Panics if the concrete image type does not have a SubImage() method. +func subimage(m draw.Image, r image.Rectangle) draw.Image { + return m.(subimager).SubImage(r).(draw.Image) +} + +// drawBackground returns a draw call that fills the entire image with a color. +func drawBackground(c color.Color) func(draw.Image) image.Rectangle { + return func(img draw.Image) image.Rectangle { + draw.Draw(img, img.Bounds(), &image.Uniform{c}, image.ZP, draw.Src) + return img.Bounds() + } +} |