mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 15:45:38 +00:00
665e23693f
To make the semantic relation between the clickable area and its content clear, it will be important for the clickable clip operation to cover all of the clickable content. API change: users of widget.Clickable must now pass the clickable content to Layout. Signed-off-by: Elias Naur <mail@eliasnaur.com>
47 lines
817 B
Go
47 lines
817 B
Go
// SPDX-License-Identifier: Unlicense OR MIT
|
|
|
|
package widget
|
|
|
|
import (
|
|
"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, w)
|
|
for b.clk.Clicked() {
|
|
b.Value = !b.Value
|
|
b.changed = true
|
|
}
|
|
return dims
|
|
}
|