~eliasnaur/gio

gio/widget/bool.go -rw-r--r-- 517 bytes
ef7b3e75Jack Mordaunt widget: delete whole words with key modifier 7 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
}

func (b *Bool) History() []Press {
	return b.clk.History()
}

func (b *Bool) Layout(gtx layout.Context) layout.Dimensions {
	dims := b.clk.Layout(gtx)
	for b.clk.Clicked() {
		b.Value = !b.Value
		b.changed = true
	}
	return dims
}