mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
acab582487
This commit introduces the material.Theme.Face field, which will automatically populate the Font.Typeface in every text widget created using a constructor function in package material. Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
41 lines
1.0 KiB
Go
41 lines
1.0 KiB
Go
// SPDX-License-Identifier: Unlicense OR MIT
|
|
|
|
package material
|
|
|
|
import (
|
|
"gioui.org/io/semantic"
|
|
"gioui.org/layout"
|
|
"gioui.org/widget"
|
|
)
|
|
|
|
type CheckBoxStyle struct {
|
|
checkable
|
|
CheckBox *widget.Bool
|
|
}
|
|
|
|
func CheckBox(th *Theme, checkBox *widget.Bool, label string) CheckBoxStyle {
|
|
c := CheckBoxStyle{
|
|
CheckBox: checkBox,
|
|
checkable: checkable{
|
|
Label: label,
|
|
Color: th.Palette.Fg,
|
|
IconColor: th.Palette.ContrastBg,
|
|
TextSize: th.TextSize * 14.0 / 16.0,
|
|
Size: 26,
|
|
shaper: th.Shaper,
|
|
checkedStateIcon: th.Icon.CheckBoxChecked,
|
|
uncheckedStateIcon: th.Icon.CheckBoxUnchecked,
|
|
},
|
|
}
|
|
c.checkable.Font.Typeface = th.Face
|
|
return c
|
|
}
|
|
|
|
// Layout updates the checkBox and displays it.
|
|
func (c CheckBoxStyle) Layout(gtx layout.Context) layout.Dimensions {
|
|
return c.CheckBox.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
|
|
semantic.CheckBox.Add(gtx.Ops)
|
|
return c.layout(gtx, c.CheckBox.Value, c.CheckBox.Hovered() || c.CheckBox.Focused())
|
|
})
|
|
}
|