mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 17:35:36 +00:00
widget,widget/material: rename widget.Click to widget.Press
Press tracks pointer presses, not clicks, and we're about to add a Click type that does. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+2
-2
@@ -8,7 +8,7 @@ import (
|
|||||||
type Bool struct {
|
type Bool struct {
|
||||||
Value bool
|
Value bool
|
||||||
// Last is the last registered click.
|
// Last is the last registered click.
|
||||||
Last Click
|
Last Press
|
||||||
|
|
||||||
// changeVal tracks Value from the most recent call to Changed.
|
// changeVal tracks Value from the most recent call to Changed.
|
||||||
changeVal bool
|
changeVal bool
|
||||||
@@ -28,7 +28,7 @@ func (b *Bool) Layout(gtx layout.Context) {
|
|||||||
for _, e := range b.gesture.Events(gtx) {
|
for _, e := range b.gesture.Events(gtx) {
|
||||||
switch e.Type {
|
switch e.Type {
|
||||||
case gesture.TypeClick:
|
case gesture.TypeClick:
|
||||||
b.Last = Click{
|
b.Last = Press{
|
||||||
Time: gtx.Now(),
|
Time: gtx.Now(),
|
||||||
Position: e.Position,
|
Position: e.Position,
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-5
@@ -18,11 +18,11 @@ type Clickable struct {
|
|||||||
click gesture.Click
|
click gesture.Click
|
||||||
// clicks tracks the number of unreported clicks.
|
// clicks tracks the number of unreported clicks.
|
||||||
clicks int
|
clicks int
|
||||||
history []Click
|
history []Press
|
||||||
}
|
}
|
||||||
|
|
||||||
// Click represents a past click.
|
// Press represents a past pointer press.
|
||||||
type Click struct {
|
type Press struct {
|
||||||
Position f32.Point
|
Position f32.Point
|
||||||
Time time.Time
|
Time time.Time
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@ func (b *Clickable) Clicked() bool {
|
|||||||
|
|
||||||
// History is the past pointer presses useful for drawing markers.
|
// History is the past pointer presses useful for drawing markers.
|
||||||
// History is retained for a short duration (about a second).
|
// History is retained for a short duration (about a second).
|
||||||
func (b *Clickable) History() []Click {
|
func (b *Clickable) History() []Press {
|
||||||
return b.history
|
return b.history
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ func (b *Clickable) update(gtx layout.Context) {
|
|||||||
case gesture.TypeClick:
|
case gesture.TypeClick:
|
||||||
b.clicks++
|
b.clicks++
|
||||||
case gesture.TypePress:
|
case gesture.TypePress:
|
||||||
b.history = append(b.history, Click{
|
b.history = append(b.history, Press{
|
||||||
Position: e.Position,
|
Position: e.Position,
|
||||||
Time: gtx.Now(),
|
Time: gtx.Now(),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ func (b IconButtonStyle) Layout(gtx layout.Context) layout.Dimensions {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func drawInk(gtx layout.Context, c widget.Click) {
|
func drawInk(gtx layout.Context, c widget.Press) {
|
||||||
d := gtx.Now().Sub(c.Time)
|
d := gtx.Now().Sub(c.Time)
|
||||||
t := float32(d.Seconds())
|
t := float32(d.Seconds())
|
||||||
const duration = 0.5
|
const duration = 0.5
|
||||||
|
|||||||
Reference in New Issue
Block a user