mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-04 00:45:35 +00:00
widget/button,widget/material: introduce Clickable for generic click areas
material.Clickable is useful for adding a click response to any widget or area. Rename widget.Button to widget.Clickable to reflect the wider use spectrum. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+6
-6
@@ -13,8 +13,8 @@ import (
|
||||
"gioui.org/op"
|
||||
)
|
||||
|
||||
// Button represents a clickable area.
|
||||
type Button struct {
|
||||
// Clickable represents a clickable area.
|
||||
type Clickable struct {
|
||||
click gesture.Click
|
||||
// clicks tracks the number of unreported clicks.
|
||||
clicks int
|
||||
@@ -30,7 +30,7 @@ type Click struct {
|
||||
// Clicked calls Update and reports whether the button was
|
||||
// clicked since the last call. Multiple clicks result in Clicked
|
||||
// returning true once per click.
|
||||
func (b *Button) Clicked(gtx *layout.Context) bool {
|
||||
func (b *Clickable) Clicked(gtx *layout.Context) bool {
|
||||
b.Update(gtx)
|
||||
if b.clicks > 0 {
|
||||
b.clicks--
|
||||
@@ -45,11 +45,11 @@ func (b *Button) Clicked(gtx *layout.Context) bool {
|
||||
|
||||
// History is the past clicks useful for drawing click markers.
|
||||
// Clicks are retained for a short duration (about a second).
|
||||
func (b *Button) History() []Click {
|
||||
func (b *Clickable) History() []Click {
|
||||
return b.history
|
||||
}
|
||||
|
||||
func (b *Button) Layout(gtx *layout.Context) {
|
||||
func (b *Clickable) Layout(gtx *layout.Context) {
|
||||
// Flush clicks from before the previous frame.
|
||||
b.Update(gtx)
|
||||
var st op.StackOp
|
||||
@@ -69,7 +69,7 @@ func (b *Button) Layout(gtx *layout.Context) {
|
||||
|
||||
// Update the button state by processing events. The underlying
|
||||
// gesture events are returned for use beyond what Clicked offers.
|
||||
func (b *Button) Update(gtx *layout.Context) []gesture.ClickEvent {
|
||||
func (b *Clickable) Update(gtx *layout.Context) []gesture.ClickEvent {
|
||||
evts := b.click.Events(gtx)
|
||||
for _, e := range evts {
|
||||
switch e.Type {
|
||||
|
||||
Reference in New Issue
Block a user