| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package widget |
| 6 |
|
| 7 |
import ( |
| 8 |
"golang.org/x/exp/shiny/unit" |
| 9 |
"golang.org/x/exp/shiny/widget/node" |
| 10 |
"golang.org/x/exp/shiny/widget/theme" |
| 11 |
) |
| 12 |
|
| 13 |
|
| 14 |
type Sizer struct { |
| 15 |
node.ShellEmbed |
| 16 |
NaturalWidth unit.Value |
| 17 |
NaturalHeight unit.Value |
| 18 |
} |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
func NewSizer(naturalWidth, naturalHeight unit.Value, inner node.Node) *Sizer { |
| 24 |
w := &Sizer{ |
| 25 |
NaturalWidth: naturalWidth, |
| 26 |
NaturalHeight: naturalHeight, |
| 27 |
} |
| 28 |
w.Wrapper = w |
| 29 |
if inner != nil { |
| 30 |
w.Insert(inner, nil) |
| 31 |
} |
| 32 |
return w |
| 33 |
} |
| 34 |
|
| 35 |
func (w *Sizer) Measure(t *theme.Theme, widthHint, heightHint int) { |
| 36 |
w.MeasuredSize.X = t.Pixels(w.NaturalWidth).Round() |
| 37 |
w.MeasuredSize.Y = t.Pixels(w.NaturalHeight).Round() |
| 38 |
if c := w.FirstChild; c != nil { |
| 39 |
c.Wrapper.Measure(t, w.MeasuredSize.X, w.MeasuredSize.Y) |
| 40 |
} |
| 41 |
} |