mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 23:55:39 +00:00
widget,widget/material: export CheckBox.Checked
Similar to the previous change to Enum, expose the current state of the CheckBox. Rename the Checked method to just Update and get rid of the SetChecked method. Fixes gio#100 Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+6
-9
@@ -6,22 +6,19 @@ import (
|
||||
)
|
||||
|
||||
type CheckBox struct {
|
||||
click gesture.Click
|
||||
checked bool
|
||||
Checked bool
|
||||
|
||||
click gesture.Click
|
||||
}
|
||||
|
||||
func (c *CheckBox) SetChecked(value bool) {
|
||||
c.checked = value
|
||||
}
|
||||
|
||||
func (c *CheckBox) Checked(gtx *layout.Context) bool {
|
||||
// Update the checked state according to incoming events.
|
||||
func (c *CheckBox) Update(gtx *layout.Context) {
|
||||
for _, e := range c.click.Events(gtx) {
|
||||
switch e.Type {
|
||||
case gesture.TypeClick:
|
||||
c.checked = !c.checked
|
||||
c.Checked = !c.Checked
|
||||
}
|
||||
}
|
||||
return c.checked
|
||||
}
|
||||
|
||||
func (c *CheckBox) Layout(gtx *layout.Context) {
|
||||
|
||||
@@ -27,7 +27,9 @@ func CheckBox(th *Theme, label string) CheckBoxStyle {
|
||||
}
|
||||
}
|
||||
|
||||
// Layout updates the checkBox and displays it.
|
||||
func (c CheckBoxStyle) Layout(gtx *layout.Context, checkBox *widget.CheckBox) {
|
||||
c.layout(gtx, checkBox.Checked(gtx))
|
||||
checkBox.Update(gtx)
|
||||
c.layout(gtx, checkBox.Checked)
|
||||
checkBox.Layout(gtx)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user