From a3aa3989091db2977532a7c18c74a3f349d7256c Mon Sep 17 00:00:00 2001 From: Sander Schobers Date: Wed, 13 Mar 2019 19:03:06 +0100 Subject: [PATCH] Restructered spacing controls & added margin helpers. --- ui/fixed.go | 23 ------------------- ui/spacing.go | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++ ui/stretch.go | 21 ----------------- 3 files changed, 62 insertions(+), 44 deletions(-) delete mode 100644 ui/fixed.go delete mode 100644 ui/stretch.go diff --git a/ui/fixed.go b/ui/fixed.go deleted file mode 100644 index 9d2287a..0000000 --- a/ui/fixed.go +++ /dev/null @@ -1,23 +0,0 @@ -package ui - -// FixedSize wraps the supplied control to fill exactly the space specified. -func FixedSize(c Control, w, h float32) Control { - return BuildSpacing(c, func(s *Spacing) { - s.Width = Fixed(w) - s.Height = Fixed(h) - }) -} - -// FixedHeight wraps the supplied control to fill exactly the height specified. Width is taken from wrapped control. -func FixedHeight(c Control, h float32) Control { - return BuildSpacing(c, func(s *Spacing) { - s.Height = Fixed(h) - }) -} - -// FixedWidth wraps the supplied control to fill exactly the width specified. Height is taken from wrapped control. -func FixedWidth(c Control, w float32) Control { - return BuildSpacing(c, func(s *Spacing) { - s.Width = Fixed(w) - }) -} diff --git a/ui/spacing.go b/ui/spacing.go index 00631ed..3309c57 100644 --- a/ui/spacing.go +++ b/ui/spacing.go @@ -93,3 +93,65 @@ func (s *Spacing) SetSize(w, h float32) { s.Width = Fixed(w) s.Height = Fixed(h) } + +// FixedSize wraps the Control c to fill exactly the space specified. +func FixedSize(c Control, w, h float32) Control { + return BuildSpacing(c, func(s *Spacing) { + s.Width = Fixed(w) + s.Height = Fixed(h) + }) +} + +// FixedHeight wraps the Control c to fill exactly the height specified. Width is taken from Control c. +func FixedHeight(c Control, h float32) Control { + return BuildSpacing(c, func(s *Spacing) { + s.Height = Fixed(h) + }) +} + +// FixedWidth wraps the Control c to fill exactly the width specified. Height is taken from Control c. +func FixedWidth(c Control, w float32) Control { + return BuildSpacing(c, func(s *Spacing) { + s.Width = Fixed(w) + }) +} + +// Margin wraps the Control c to have equal margins on all sides. +func Margin(c Control, m float32) *Spacing { + return Margins(c, m, m, m, m) +} + +// MarginAxes wraps the Control c to have same margins horizontally (left, right) and vertically (top, left). +func MarginAxes(c Control, hor, ver float32) *Spacing { + return Margins(c, hor, ver, hor, ver) +} + +// Margins wraps the Control c to have different margins on all sides. +func Margins(c Control, left, top, right, bottom float32) *Spacing { + return BuildSpacing(c, func(s *Spacing) { + s.Margin.Left = Fixed(left) + s.Margin.Top = Fixed(top) + s.Margin.Right = Fixed(right) + s.Margin.Bottom = Fixed(bottom) + }) +} + +func stretch(c Control, w, h bool) *Spacing { + return BuildSpacing(c, func(s *Spacing) { + if w { + s.Width = Infinite() + } + if h { + s.Height = Infinite() + } + }) +} + +// Stretch wraps the Control c to stretch in both directions. +func Stretch(c Control) Control { return stretch(c, true, true) } + +// StretchHeight wraps the Control c to stretch vertically. Width is taken from Control c. +func StretchHeight(c Control) Control { return stretch(c, false, true) } + +// StretchWidth wraps the Control c to stretch horizontally. Height is taken from Control c. +func StretchWidth(c Control) Control { return stretch(c, true, false) } diff --git a/ui/stretch.go b/ui/stretch.go deleted file mode 100644 index 0d52322..0000000 --- a/ui/stretch.go +++ /dev/null @@ -1,21 +0,0 @@ -package ui - -func newStretch(c Control, w, h bool) *Spacing { - return BuildSpacing(c, func(s *Spacing) { - if w { - s.Width = Infinite() - } - if h { - s.Height = Infinite() - } - }) -} - -// Stretch wraps the supplied control to stretch in both directions. -func Stretch(c Control) Control { return newStretch(c, true, true) } - -// StretchHeight wraps the supplied control to stretch vertically. Width is taken from wrapped control. -func StretchHeight(c Control) Control { return newStretch(c, false, true) } - -// StretchWidth wraps the supplied control to stretch horizontally. Height is taken from wrapped control. -func StretchWidth(c Control) Control { return newStretch(c, true, false) }