widget,widget/material: add CheckBox

This commit is contained in:
Alexander Arin
2019-11-03 18:11:19 +03:00
committed by Elias Naur
parent 2a06f3d3b2
commit 0f5b94a483
2 changed files with 113 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
package widget
import (
"gioui.org/gesture"
"gioui.org/layout"
)
type CheckBox struct {
click gesture.Click
checked bool
}
func (c *CheckBox) Checked(gtx *layout.Context) bool {
for _, e := range c.click.Events(gtx) {
switch e.Type {
case gesture.TypeClick:
c.checked = !c.checked
}
}
return c.checked
}
func (c *CheckBox) Layout(gtx *layout.Context) {
c.click.Add(gtx.Ops)
}