Files
gio-patched/widget/bool.go
T
Elias Naur 6b1ca4ca7e widget: add semantic descriptions
Some semantic information is automatically extracted, but some must be
provided by UI components. This change enriches the generic and material
widgets with such information.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-12-01 17:57:04 +01:00

52 lines
1005 B
Go

// SPDX-License-Identifier: Unlicense OR MIT
package widget
import (
"gioui.org/io/semantic"
"gioui.org/layout"
)
type Bool struct {
Value bool
clk Clickable
changed bool
}
// Changed reports whether Value has changed since the last
// call to Changed.
func (b *Bool) Changed() bool {
changed := b.changed
b.changed = false
return changed
}
// Hovered returns whether pointer is over the element.
func (b *Bool) Hovered() bool {
return b.clk.Hovered()
}
// Pressed returns whether pointer is pressing the element.
func (b *Bool) Pressed() bool {
return b.clk.Pressed()
}
func (b *Bool) History() []Press {
return b.clk.History()
}
func (b *Bool) Layout(gtx layout.Context, w layout.Widget) layout.Dimensions {
dims := b.clk.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
for b.clk.Clicked() {
b.Value = !b.Value
b.changed = true
}
semantic.SelectedOp(b.Value).Add(gtx.Ops)
semantic.DisabledOp(gtx.Queue == nil).Add(gtx.Ops)
return w(gtx)
})
return dims
}