mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-08 02:45:38 +00:00
widget: change Bool.Layout to follow layout protocol
Just like Clickable, Bool.Layout should respect constraints and return its dimensions. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+10
-1
@@ -1,8 +1,12 @@
|
|||||||
package widget
|
package widget
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"image"
|
||||||
|
|
||||||
"gioui.org/gesture"
|
"gioui.org/gesture"
|
||||||
|
"gioui.org/io/pointer"
|
||||||
"gioui.org/layout"
|
"gioui.org/layout"
|
||||||
|
"gioui.org/op"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Bool struct {
|
type Bool struct {
|
||||||
@@ -24,7 +28,7 @@ func (b *Bool) Changed() bool {
|
|||||||
return changed
|
return changed
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bool) Layout(gtx layout.Context) {
|
func (b *Bool) Layout(gtx layout.Context) layout.Dimensions {
|
||||||
for _, e := range b.gesture.Events(gtx) {
|
for _, e := range b.gesture.Events(gtx) {
|
||||||
switch e.Type {
|
switch e.Type {
|
||||||
case gesture.TypeClick:
|
case gesture.TypeClick:
|
||||||
@@ -35,5 +39,10 @@ func (b *Bool) Layout(gtx layout.Context) {
|
|||||||
b.Value = !b.Value
|
b.Value = !b.Value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var st op.StackOp
|
||||||
|
st.Push(gtx.Ops)
|
||||||
|
defer st.Pop()
|
||||||
|
pointer.Rect(image.Rectangle{Max: gtx.Constraints.Min}).Add(gtx.Ops)
|
||||||
b.gesture.Add(gtx.Ops)
|
b.gesture.Add(gtx.Ops)
|
||||||
|
return layout.Dimensions{Size: gtx.Constraints.Min}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ func CheckBox(th *Theme, checkBox *widget.Bool, label string) CheckBoxStyle {
|
|||||||
// Layout updates the checkBox and displays it.
|
// Layout updates the checkBox and displays it.
|
||||||
func (c CheckBoxStyle) Layout(gtx layout.Context) layout.Dimensions {
|
func (c CheckBoxStyle) Layout(gtx layout.Context) layout.Dimensions {
|
||||||
dims := c.layout(gtx, c.CheckBox.Value)
|
dims := c.layout(gtx, c.CheckBox.Value)
|
||||||
|
gtx.Constraints.Min = dims.Size
|
||||||
c.CheckBox.Layout(gtx)
|
c.CheckBox.Layout(gtx)
|
||||||
return dims
|
return dims
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,17 +104,13 @@ func (s SwitchStyle) Layout(gtx layout.Context) layout.Dimensions {
|
|||||||
Y: (float32(trackHeight)-float32(clickSize))*.5 + trackOff,
|
Y: (float32(trackHeight)-float32(clickSize))*.5 + trackOff,
|
||||||
}
|
}
|
||||||
op.TransformOp{}.Offset(clickOff).Add(gtx.Ops)
|
op.TransformOp{}.Offset(clickOff).Add(gtx.Ops)
|
||||||
pointer.Ellipse(image.Rectangle{
|
sz := image.Pt(clickSize, clickSize)
|
||||||
Max: image.Point{
|
pointer.Ellipse(image.Rectangle{Max: sz}).Add(gtx.Ops)
|
||||||
X: clickSize, Y: clickSize,
|
gtx.Constraints.Min = sz
|
||||||
},
|
|
||||||
}).Add(gtx.Ops)
|
|
||||||
s.Switch.Layout(gtx)
|
s.Switch.Layout(gtx)
|
||||||
stack.Pop()
|
stack.Pop()
|
||||||
|
|
||||||
return layout.Dimensions{
|
return layout.Dimensions{Size: image.Point{X: trackWidth, Y: thumbSize}}
|
||||||
Size: image.Point{X: trackWidth, Y: trackHeight},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func drawDisc(ops *op.Ops, sz float32, col color.RGBA) {
|
func drawDisc(ops *op.Ops, sz float32, col color.RGBA) {
|
||||||
|
|||||||
Reference in New Issue
Block a user