Restructered spacing controls & added margin helpers.
This commit is contained in:
parent
3ea0d76efb
commit
a3aa398909
23
ui/fixed.go
23
ui/fixed.go
@ -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)
|
|
||||||
})
|
|
||||||
}
|
|
@ -93,3 +93,65 @@ func (s *Spacing) SetSize(w, h float32) {
|
|||||||
s.Width = Fixed(w)
|
s.Width = Fixed(w)
|
||||||
s.Height = Fixed(h)
|
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) }
|
||||||
|
@ -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) }
|
|
Loading…
Reference in New Issue
Block a user