aboutsummaryrefslogtreecommitdiffstats
path: root/layout/box.go
diff options
context:
space:
mode:
authorClement Benard <contact@clementbenard.com>2019-08-07 16:02:33 +0200
committerClement Benard <contact@clementbenard.com>2019-08-07 16:02:33 +0200
commit8d183ef96a57e3a2f42c0cb4ec0ab4c256e0d47e (patch)
tree4fa644f93ceeb5c102c5c1dcf85105890c0cf25b /layout/box.go
parent8b70878ccc7fe324f3647e56503a37f3780f9d41 (diff)
downloadgui-8d183ef96a57e3a2f42c0cb4ec0ab4c256e0d47e.zip
Made the layout package actually usable
Diffstat (limited to 'layout/box.go')
-rw-r--r--layout/box.go57
1 files changed, 0 insertions, 57 deletions
diff --git a/layout/box.go b/layout/box.go
deleted file mode 100644
index 24f0c0d..0000000
--- a/layout/box.go
+++ /dev/null
@@ -1,57 +0,0 @@
-package layout
-
-import (
- "image"
- "image/color"
- "image/draw"
-)
-
-type Box struct {
- // Number of child elements
- Length int
- // Background changes the background of the Box to a uniform color.
- Background color.Color
- // Split changes the way the space is divided among the elements.
- Split SplitFunc
- // Gap changes the Box gap.
- // The gap is identical everywhere (top, left, bottom, right).
- Gap int
-
- // Vertical changes the otherwise horizontal Box to be vertical.
- Vertical bool
-}
-
-func (b Box) Redraw(drw draw.Image, bounds image.Rectangle) {
- col := b.Background
- if col == nil {
- col = image.Black
- }
-
- draw.Draw(drw, bounds, image.NewUniform(col), image.ZP, draw.Src)
-}
-
-func (b Box) Lay(bounds image.Rectangle) []image.Rectangle {
- items := b.Length
- gap := b.Gap
- split := b.Split
- if split == nil {
- split = EvenSplit
- }
- ret := make([]image.Rectangle, 0, items)
- if b.Vertical {
- spl := split(items, bounds.Dy()-(gap*(items+1)))
- Y := bounds.Min.Y + gap
- for _, item := range spl {
- ret = append(ret, image.Rect(bounds.Min.X+gap, Y, bounds.Max.X-gap, Y+item))
- Y += item + gap
- }
- } else {
- spl := split(items, bounds.Dx()-(gap*(items+1)))
- X := bounds.Min.X + gap
- for _, item := range spl {
- ret = append(ret, image.Rect(X, bounds.Min.Y+gap, X+item, bounds.Max.Y-gap))
- X += item + gap
- }
- }
- return ret
-}