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:
+43
-35
@@ -12,9 +12,13 @@ import (
|
||||
)
|
||||
|
||||
type Button struct {
|
||||
click gesture.Click
|
||||
clicks int
|
||||
history []Click
|
||||
click gesture.Click
|
||||
// clicks tracks the number of unreported clicks.
|
||||
clicks int
|
||||
// prevClicks tracks the number of unreported clicks
|
||||
// that belong to the previous frame.
|
||||
prevClicks int
|
||||
history []Click
|
||||
}
|
||||
|
||||
// Click represents a historic click.
|
||||
@@ -24,6 +28,42 @@ type Click struct {
|
||||
}
|
||||
|
||||
func (b *Button) Clicked(gtx *layout.Context) bool {
|
||||
b.processEvents(gtx)
|
||||
if b.clicks > 0 {
|
||||
b.clicks--
|
||||
if b.prevClicks > 0 {
|
||||
b.prevClicks--
|
||||
}
|
||||
if b.clicks > 0 {
|
||||
// Ensure timely delivery of remaining clicks.
|
||||
op.InvalidateOp{}.Add(gtx.Ops)
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (b *Button) History() []Click {
|
||||
return b.history
|
||||
}
|
||||
|
||||
func (b *Button) Layout(gtx *layout.Context) {
|
||||
// Flush clicks from before the previous frame.
|
||||
b.clicks -= b.prevClicks
|
||||
b.prevClicks = 0
|
||||
b.processEvents(gtx)
|
||||
b.click.Add(gtx.Ops)
|
||||
for len(b.history) > 0 {
|
||||
c := b.history[0]
|
||||
if gtx.Now().Sub(c.Time) < 1*time.Second {
|
||||
break
|
||||
}
|
||||
copy(b.history, b.history[1:])
|
||||
b.history = b.history[:len(b.history)-1]
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Button) processEvents(gtx *layout.Context) {
|
||||
for _, e := range b.click.Events(gtx) {
|
||||
switch e.Type {
|
||||
case gesture.TypeClick:
|
||||
@@ -35,36 +75,4 @@ func (b *Button) Clicked(gtx *layout.Context) bool {
|
||||
})
|
||||
}
|
||||
}
|
||||
if b.clicks > 0 {
|
||||
b.clicks--
|
||||
if b.clicks > 0 {
|
||||
// Ensure timely delivery of remaining clicks.
|
||||
op.InvalidateOp{}.Add(gtx.Ops)
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (b *Button) Active() bool {
|
||||
return b.click.Active()
|
||||
}
|
||||
|
||||
func (b *Button) History() []Click {
|
||||
return b.history
|
||||
}
|
||||
|
||||
func (b *Button) Layout(gtx *layout.Context) {
|
||||
b.click.Add(gtx.Ops)
|
||||
if !b.Active() {
|
||||
b.clicks = 0
|
||||
}
|
||||
for len(b.history) > 0 {
|
||||
c := b.history[0]
|
||||
if gtx.Now().Sub(c.Time) < 1*time.Second {
|
||||
break
|
||||
}
|
||||
copy(b.history, b.history[1:])
|
||||
b.history = b.history[:len(b.history)-1]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user