From 8d183ef96a57e3a2f42c0cb4ec0ab4c256e0d47e Mon Sep 17 00:00:00 2001 From: Clement Benard Date: Wed, 7 Aug 2019 16:02:33 +0200 Subject: Made the layout package actually usable --- layout/box.go | 57 --------------------------------------------------------- 1 file changed, 57 deletions(-) delete mode 100644 layout/box.go (limited to 'layout/box.go') 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 -} -- cgit v1.2.3