widget,widget/material: remove disabled drawing modes

Determining the enabled state of a widget from whether its Clicked method has
been called only works for button-like widgets. For example, it's not clear a
Clicked method is appropriate for a CheckBox.

Remove the feature for now, and let's find a better design in the future.

As a nice side effect, we can now process events in Layout methods, so that
buttons react to user input even when Clicked is not called.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-11-02 12:27:56 +01:00
parent 06aa0da2a2
commit 4107485902
4 changed files with 60 additions and 61 deletions
+7 -3
View File
@@ -60,6 +60,8 @@ type Editor struct {
// events is the list of events not yet processed.
events []EditorEvent
// prevEvents is the number of events from the previous frame.
prevEvents int
}
type EditorEvent interface {
@@ -90,6 +92,7 @@ func (e *Editor) Events(gtx *layout.Context) []EditorEvent {
e.processEvents(gtx)
events := e.events
e.events = nil
e.prevEvents = 0
return events
}
@@ -177,15 +180,16 @@ func (e *Editor) Focus() {
// Layout lays out the editor.
func (e *Editor) Layout(gtx *layout.Context, sh *text.Shaper, font text.Font) {
// Flush events from before the previous frame.
copy(e.events, e.events[e.prevEvents:])
e.events = e.events[:len(e.events)-e.prevEvents]
e.prevEvents = len(e.events)
if e.font != font {
e.invalidate()
e.font = font
}
e.processEvents(gtx)
e.layout(gtx, sh)
if !e.clicker.Active() {
e.events = nil
}
}
func (e *Editor) layout(gtx *layout.Context, sh *text.Shaper) {