mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 15:45:38 +00:00
3e0b72304a
Converted with gofmt -w -r 'pointer.Rect(r) -> clip.Rect(r)' . gofmt -w -r 'pointer.Ellipse(r) -> clip.Ellipse(layout.FRect(r))' . combined with 'goimports -w .' to clean up imports. Signed-off-by: Elias Naur <mail@eliasnaur.com>
43 lines
1.0 KiB
Go
43 lines
1.0 KiB
Go
// SPDX-License-Identifier: Unlicense OR MIT
|
|
|
|
package material
|
|
|
|
import (
|
|
"image"
|
|
|
|
"gioui.org/layout"
|
|
"gioui.org/op/clip"
|
|
"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.Palette.Fg,
|
|
IconColor: th.Palette.ContrastBg,
|
|
TextSize: th.TextSize.Scale(14.0 / 16.0),
|
|
Size: unit.Dp(26),
|
|
shaper: th.Shaper,
|
|
checkedStateIcon: th.Icon.CheckBoxChecked,
|
|
uncheckedStateIcon: th.Icon.CheckBoxUnchecked,
|
|
},
|
|
}
|
|
}
|
|
|
|
// Layout updates the checkBox and displays it.
|
|
func (c CheckBoxStyle) Layout(gtx layout.Context) layout.Dimensions {
|
|
dims := c.layout(gtx, c.CheckBox.Value, c.CheckBox.Hovered())
|
|
defer clip.Rect(image.Rectangle{Max: dims.Size}).Push(gtx.Ops).Pop()
|
|
gtx.Constraints.Min = dims.Size
|
|
c.CheckBox.Layout(gtx)
|
|
return dims
|
|
}
|