mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-07 18:35:34 +00:00
widget/material: add and use Icon.Layout method
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -112,13 +112,7 @@ func (b IconButton) Layout(gtx *layout.Context, button *widget.Button) {
|
|||||||
layout.UniformInset(b.Padding).Layout(gtx, func() {
|
layout.UniformInset(b.Padding).Layout(gtx, func() {
|
||||||
size := gtx.Px(b.Size) - gtx.Px(b.Padding)
|
size := gtx.Px(b.Size) - gtx.Px(b.Padding)
|
||||||
if b.Icon != nil {
|
if b.Icon != nil {
|
||||||
ico := b.Icon.image(size)
|
b.Icon.Layout(gtx, unit.Px(float32(size)))
|
||||||
ico.Add(gtx.Ops)
|
|
||||||
paint.PaintOp{
|
|
||||||
Rect: f32.Rectangle{
|
|
||||||
Max: toPointF(ico.Size()),
|
|
||||||
},
|
|
||||||
}.Add(gtx.Ops)
|
|
||||||
}
|
}
|
||||||
gtx.Dimensions = layout.Dimensions{
|
gtx.Dimensions = layout.Dimensions{
|
||||||
Size: image.Point{X: size, Y: size},
|
Size: image.Point{X: size, Y: size},
|
||||||
@@ -147,6 +141,16 @@ func (b IconButton) Layout(gtx *layout.Context, button *widget.Button) {
|
|||||||
st.Layout(gtx, bg, ico)
|
st.Layout(gtx, bg, ico)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ic *Icon) Layout(gtx *layout.Context, sz unit.Value) {
|
||||||
|
ico := ic.image(gtx.Px(sz))
|
||||||
|
ico.Add(gtx.Ops)
|
||||||
|
paint.PaintOp{
|
||||||
|
Rect: f32.Rectangle{
|
||||||
|
Max: toPointF(ico.Size()),
|
||||||
|
},
|
||||||
|
}.Add(gtx.Ops)
|
||||||
|
}
|
||||||
|
|
||||||
func (ic *Icon) image(sz int) paint.ImageOp {
|
func (ic *Icon) image(sz int) paint.ImageOp {
|
||||||
if sz == ic.imgSize {
|
if sz == ic.imgSize {
|
||||||
return ic.op
|
return ic.op
|
||||||
|
|||||||
Reference in New Issue
Block a user