mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-02 16:06:19 +00:00
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:
+7
-3
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user