Changed Length.Zero to return value instead of Length.
Spacing shorthand methods now returns Spacing object instead of Control interface.
This commit is contained in:
parent
04779d6588
commit
eb0e8322ef
@ -13,11 +13,11 @@ func (l *Length) Value() float32 {
|
||||
return l.float32
|
||||
}
|
||||
|
||||
func (l *Length) Zero(value float32) *Length {
|
||||
func (l *Length) Zero(value float32) float32 {
|
||||
if l == nil {
|
||||
return &Length{value}
|
||||
return value
|
||||
}
|
||||
return l
|
||||
return l.Value()
|
||||
}
|
||||
|
||||
func Fixed(l float32) *Length { return &Length{l} }
|
||||
|
@ -70,7 +70,7 @@ func addMargin(bounds geom.PointF32, size geom.PointF32, margin SideLengths) geo
|
||||
func (s *Spacing) Arrange(ctx Context, bounds geom.RectangleF32, offset geom.PointF32) {
|
||||
var size = s.Proxy.DesiredSize(ctx)
|
||||
var w, h = s.Width.Zero(size.X), s.Height.Zero(size.Y)
|
||||
var content = addMargin(geom.PtF32(bounds.Dx(), bounds.Dy()), geom.PtF32(w.Value(), h.Value()), s.Margin).Add(bounds.Min)
|
||||
var content = addMargin(geom.PtF32(bounds.Dx(), bounds.Dy()), geom.PtF32(w, h), s.Margin).Add(bounds.Min)
|
||||
s.Proxy.Arrange(ctx, content, offset)
|
||||
}
|
||||
|
||||
@ -85,8 +85,8 @@ func (s *Spacing) DesiredSize(ctx Context) geom.PointF32 {
|
||||
var size = s.Proxy.DesiredSize(ctx)
|
||||
var w, h = s.Width.Zero(size.X), s.Height.Zero(size.Y)
|
||||
return geom.PtF32(
|
||||
s.Margin.Left.Value()+w.Value()+s.Margin.Right.Value(),
|
||||
s.Margin.Top.Value()+h.Value()+s.Margin.Bottom.Value())
|
||||
s.Margin.Left.Value()+w+s.Margin.Right.Value(),
|
||||
s.Margin.Top.Value()+h+s.Margin.Bottom.Value())
|
||||
}
|
||||
|
||||
func (s *Spacing) SetSize(w, h float32) {
|
||||
@ -95,7 +95,7 @@ func (s *Spacing) SetSize(w, h float32) {
|
||||
}
|
||||
|
||||
// FixedSize wraps the Control c to fill exactly the space specified.
|
||||
func FixedSize(c Control, w, h float32) Control {
|
||||
func FixedSize(c Control, w, h float32) *Spacing {
|
||||
return BuildSpacing(c, func(s *Spacing) {
|
||||
s.Width = Fixed(w)
|
||||
s.Height = Fixed(h)
|
||||
@ -103,7 +103,7 @@ func FixedSize(c Control, w, h float32) Control {
|
||||
}
|
||||
|
||||
// FixedHeight wraps the Control c to fill exactly the height specified. Width is taken from Control c.
|
||||
func FixedHeight(c Control, h float32) Control {
|
||||
func FixedHeight(c Control, h float32) *Spacing {
|
||||
return BuildSpacing(c, func(s *Spacing) {
|
||||
s.Height = Fixed(h)
|
||||
})
|
||||
@ -148,10 +148,10 @@ func stretch(c Control, w, h bool) *Spacing {
|
||||
}
|
||||
|
||||
// Stretch wraps the Control c to stretch in both directions.
|
||||
func Stretch(c Control) Control { return stretch(c, true, true) }
|
||||
func Stretch(c Control) *Spacing { 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) }
|
||||
func StretchHeight(c Control) *Spacing { 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) }
|
||||
func StretchWidth(c Control) *Spacing { return stretch(c, true, false) }
|
||||
|
Loading…
Reference in New Issue
Block a user