41 lines
976 B
Go
41 lines
976 B
Go
|
package ui
|
||
|
|
||
|
import (
|
||
|
"opslag.de/schobers/geom"
|
||
|
)
|
||
|
|
||
|
var _ Control = &stretch{}
|
||
|
|
||
|
type stretch struct {
|
||
|
Proxy
|
||
|
|
||
|
w, h bool
|
||
|
}
|
||
|
|
||
|
func (s *stretch) DesiredSize(ctx Context) geom.PointF32 {
|
||
|
var size = geom.PtF32(geom.NaN32(), geom.NaN32())
|
||
|
if !s.w || !s.h {
|
||
|
child := s.Content.DesiredSize(ctx)
|
||
|
if !s.w {
|
||
|
size.X = child.X
|
||
|
}
|
||
|
if !s.h {
|
||
|
size.Y = child.Y
|
||
|
}
|
||
|
}
|
||
|
return size
|
||
|
}
|
||
|
|
||
|
func newStretch(c Control, w, h bool) *stretch {
|
||
|
return &stretch{Proxy{Content: c}, w, h}
|
||
|
}
|
||
|
|
||
|
// 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) }
|