mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 15:45:38 +00:00
a87a520ae8
This introduces a new material.Palette type that captures the color information necessary to render a widget. This type is embedded in the material.Theme to make it easier to swap to a different palette for part of the UI by reassinging the Palette field. Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
39 lines
925 B
Go
39 lines
925 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.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)
|
|
gtx.Constraints.Min = dims.Size
|
|
c.CheckBox.Layout(gtx)
|
|
return dims
|
|
}
|