43 lines
986 B
Go
43 lines
986 B
Go
|
package ui
|
||
|
|
||
|
import (
|
||
|
"opslag.de/schobers/geom"
|
||
|
)
|
||
|
|
||
|
var _ Control = &stretch{}
|
||
|
|
||
|
type fixed struct {
|
||
|
Proxy
|
||
|
|
||
|
size geom.PointF32
|
||
|
}
|
||
|
|
||
|
func (f *fixed) DesiredSize(ctx Context) geom.PointF32 {
|
||
|
w, h := f.size.X, f.size.Y
|
||
|
if geom.IsNaN32(w) || geom.IsNaN32(h) {
|
||
|
child := f.Content.DesiredSize(ctx)
|
||
|
if geom.IsNaN32(w) {
|
||
|
w = child.X
|
||
|
}
|
||
|
if geom.IsNaN32(h) {
|
||
|
h = child.Y
|
||
|
}
|
||
|
}
|
||
|
return geom.PtF32(w, h)
|
||
|
}
|
||
|
|
||
|
// Fixed wraps the supplied control to fill exactly the space specified.
|
||
|
func Fixed(c Control, w, h float32) Control {
|
||
|
return &fixed{Proxy{Content: c}, geom.PtF32(w, 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 Fixed(c, geom.NaN32(), 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 Fixed(c, w, geom.NaN32())
|
||
|
}
|