mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
31d722d9eb
Just like Clickable, Bool.Layout should respect constraints and return its dimensions. Signed-off-by: Elias Naur <mail@eliasnaur.com>
39 lines
918 B
Go
39 lines
918 B
Go
// SPDX-License-Identifier: Unlicense OR MIT
|
|
|
|
package material
|
|
|
|
import (
|
|
"gioui.org/layout"
|
|
"gioui.org/unit"
|
|
"gioui.org/widget"
|
|
)
|
|
|
|
type CheckBoxStyle struct {
|
|
checkable
|
|
CheckBox *widget.Bool
|
|
}
|
|
|
|
func CheckBox(th *Theme, checkBox *widget.Bool, label string) CheckBoxStyle {
|
|
return CheckBoxStyle{
|
|
CheckBox: checkBox,
|
|
checkable: checkable{
|
|
Label: label,
|
|
Color: th.Color.Text,
|
|
IconColor: th.Color.Primary,
|
|
TextSize: th.TextSize.Scale(14.0 / 16.0),
|
|
Size: unit.Dp(26),
|
|
shaper: th.Shaper,
|
|
checkedStateIcon: th.checkBoxCheckedIcon,
|
|
uncheckedStateIcon: th.checkBoxUncheckedIcon,
|
|
},
|
|
}
|
|
}
|
|
|
|
// Layout updates the checkBox and displays it.
|
|
func (c CheckBoxStyle) Layout(gtx layout.Context) layout.Dimensions {
|
|
dims := c.layout(gtx, c.CheckBox.Value)
|
|
gtx.Constraints.Min = dims.Size
|
|
c.CheckBox.Layout(gtx)
|
|
return dims
|
|
}
|