mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-07 02:15:34 +00:00
gesture: [API] rename ClickType to ClickKind
"Kind" is the Go idiomatic name for distinguishing structs outside of the type system. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+18
-18
@@ -87,10 +87,10 @@ type Click struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ClickEvent represent a click action, either a
|
// ClickEvent represent a click action, either a
|
||||||
// TypePress for the beginning of a click or a
|
// KindPress for the beginning of a click or a
|
||||||
// TypeClick for a completed click.
|
// KindClick for a completed click.
|
||||||
type ClickEvent struct {
|
type ClickEvent struct {
|
||||||
Type ClickType
|
Kind ClickKind
|
||||||
Position image.Point
|
Position image.Point
|
||||||
Source pointer.Source
|
Source pointer.Source
|
||||||
Modifiers key.Modifiers
|
Modifiers key.Modifiers
|
||||||
@@ -99,7 +99,7 @@ type ClickEvent struct {
|
|||||||
NumClicks int
|
NumClicks int
|
||||||
}
|
}
|
||||||
|
|
||||||
type ClickType uint8
|
type ClickKind uint8
|
||||||
|
|
||||||
// Drag detects drag gestures in the form of pointer.Drag events.
|
// Drag detects drag gestures in the form of pointer.Drag events.
|
||||||
type Drag struct {
|
type Drag struct {
|
||||||
@@ -136,15 +136,15 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// TypePress is reported for the first pointer
|
// KindPress is reported for the first pointer
|
||||||
// press.
|
// press.
|
||||||
TypePress ClickType = iota
|
KindPress ClickKind = iota
|
||||||
// TypeClick is reported when a click action
|
// KindClick is reported when a click action
|
||||||
// is complete.
|
// is complete.
|
||||||
TypeClick
|
KindClick
|
||||||
// TypeCancel is reported when the gesture is
|
// KindCancel is reported when the gesture is
|
||||||
// cancelled.
|
// cancelled.
|
||||||
TypeCancel
|
KindCancel
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -192,9 +192,9 @@ func (c *Click) Events(q event.Queue) []ClickEvent {
|
|||||||
}
|
}
|
||||||
c.pressed = false
|
c.pressed = false
|
||||||
if !c.entered || c.hovered {
|
if !c.entered || c.hovered {
|
||||||
events = append(events, ClickEvent{Type: TypeClick, Position: e.Position.Round(), Source: e.Source, Modifiers: e.Modifiers, NumClicks: c.clicks})
|
events = append(events, ClickEvent{Kind: KindClick, Position: e.Position.Round(), Source: e.Source, Modifiers: e.Modifiers, NumClicks: c.clicks})
|
||||||
} else {
|
} else {
|
||||||
events = append(events, ClickEvent{Type: TypeCancel})
|
events = append(events, ClickEvent{Kind: KindCancel})
|
||||||
}
|
}
|
||||||
case pointer.Cancel:
|
case pointer.Cancel:
|
||||||
wasPressed := c.pressed
|
wasPressed := c.pressed
|
||||||
@@ -202,7 +202,7 @@ func (c *Click) Events(q event.Queue) []ClickEvent {
|
|||||||
c.hovered = false
|
c.hovered = false
|
||||||
c.entered = false
|
c.entered = false
|
||||||
if wasPressed {
|
if wasPressed {
|
||||||
events = append(events, ClickEvent{Type: TypeCancel})
|
events = append(events, ClickEvent{Kind: KindCancel})
|
||||||
}
|
}
|
||||||
case pointer.Press:
|
case pointer.Press:
|
||||||
if c.pressed {
|
if c.pressed {
|
||||||
@@ -224,7 +224,7 @@ func (c *Click) Events(q event.Queue) []ClickEvent {
|
|||||||
c.clicks = 1
|
c.clicks = 1
|
||||||
}
|
}
|
||||||
c.clickedAt = e.Time
|
c.clickedAt = e.Time
|
||||||
events = append(events, ClickEvent{Type: TypePress, Position: e.Position.Round(), Source: e.Source, Modifiers: e.Modifiers, NumClicks: c.clicks})
|
events = append(events, ClickEvent{Kind: KindPress, Position: e.Position.Round(), Source: e.Source, Modifiers: e.Modifiers, NumClicks: c.clicks})
|
||||||
case pointer.Leave:
|
case pointer.Leave:
|
||||||
if !c.pressed {
|
if !c.pressed {
|
||||||
c.pid = e.PointerID
|
c.pid = e.PointerID
|
||||||
@@ -444,13 +444,13 @@ func (a Axis) String() string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ct ClickType) String() string {
|
func (ct ClickKind) String() string {
|
||||||
switch ct {
|
switch ct {
|
||||||
case TypePress:
|
case KindPress:
|
||||||
return "TypePress"
|
return "TypePress"
|
||||||
case TypeClick:
|
case KindClick:
|
||||||
return "TypeClick"
|
return "TypeClick"
|
||||||
case TypeCancel:
|
case KindCancel:
|
||||||
return "TypeCancel"
|
return "TypeCancel"
|
||||||
default:
|
default:
|
||||||
panic("invalid ClickType")
|
panic("invalid ClickType")
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ func mouseClickEvents(times ...time.Duration) []event.Event {
|
|||||||
func filterMouseClicks(events []ClickEvent) []ClickEvent {
|
func filterMouseClicks(events []ClickEvent) []ClickEvent {
|
||||||
var clicks []ClickEvent
|
var clicks []ClickEvent
|
||||||
for _, ev := range events {
|
for _, ev := range events {
|
||||||
if ev.Type == TypeClick {
|
if ev.Kind == KindClick {
|
||||||
clicks = append(clicks, ev)
|
clicks = append(clicks, ev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -149,8 +149,8 @@ func (b *Clickable) update(gtx layout.Context) {
|
|||||||
b.prevClicks = n
|
b.prevClicks = n
|
||||||
|
|
||||||
for _, e := range b.click.Events(gtx) {
|
for _, e := range b.click.Events(gtx) {
|
||||||
switch e.Type {
|
switch e.Kind {
|
||||||
case gesture.TypeClick:
|
case gesture.KindClick:
|
||||||
b.clicks = append(b.clicks, Click{
|
b.clicks = append(b.clicks, Click{
|
||||||
Modifiers: e.Modifiers,
|
Modifiers: e.Modifiers,
|
||||||
NumClicks: e.NumClicks,
|
NumClicks: e.NumClicks,
|
||||||
@@ -158,14 +158,14 @@ func (b *Clickable) update(gtx layout.Context) {
|
|||||||
if l := len(b.history); l > 0 {
|
if l := len(b.history); l > 0 {
|
||||||
b.history[l-1].End = gtx.Now
|
b.history[l-1].End = gtx.Now
|
||||||
}
|
}
|
||||||
case gesture.TypeCancel:
|
case gesture.KindCancel:
|
||||||
for i := range b.history {
|
for i := range b.history {
|
||||||
b.history[i].Cancelled = true
|
b.history[i].Cancelled = true
|
||||||
if b.history[i].End.IsZero() {
|
if b.history[i].End.IsZero() {
|
||||||
b.history[i].End = gtx.Now
|
b.history[i].End = gtx.Now
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case gesture.TypePress:
|
case gesture.KindPress:
|
||||||
if e.Source == pointer.Mouse {
|
if e.Source == pointer.Mouse {
|
||||||
key.FocusOp{Tag: &b.keyTag}.Add(gtx.Ops)
|
key.FocusOp{Tag: &b.keyTag}.Add(gtx.Ops)
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -238,8 +238,8 @@ func (e *Editor) processPointer(gtx layout.Context) {
|
|||||||
switch evt := evt.(type) {
|
switch evt := evt.(type) {
|
||||||
case gesture.ClickEvent:
|
case gesture.ClickEvent:
|
||||||
switch {
|
switch {
|
||||||
case evt.Type == gesture.TypePress && evt.Source == pointer.Mouse,
|
case evt.Kind == gesture.KindPress && evt.Source == pointer.Mouse,
|
||||||
evt.Type == gesture.TypeClick && evt.Source != pointer.Mouse:
|
evt.Kind == gesture.KindClick && evt.Source != pointer.Mouse:
|
||||||
prevCaretPos, _ := e.text.Selection()
|
prevCaretPos, _ := e.text.Selection()
|
||||||
e.blinkStart = gtx.Now
|
e.blinkStart = gtx.Now
|
||||||
e.text.MoveCoord(image.Point{
|
e.text.MoveCoord(image.Point{
|
||||||
|
|||||||
+3
-3
@@ -74,12 +74,12 @@ func (e *Enum) Layout(gtx layout.Context, k string, content layout.Widget) layou
|
|||||||
}
|
}
|
||||||
clk := &state.click
|
clk := &state.click
|
||||||
for _, ev := range clk.Events(gtx) {
|
for _, ev := range clk.Events(gtx) {
|
||||||
switch ev.Type {
|
switch ev.Kind {
|
||||||
case gesture.TypePress:
|
case gesture.KindPress:
|
||||||
if ev.Source == pointer.Mouse {
|
if ev.Source == pointer.Mouse {
|
||||||
key.FocusOp{Tag: &state.tag}.Add(gtx.Ops)
|
key.FocusOp{Tag: &state.tag}.Add(gtx.Ops)
|
||||||
}
|
}
|
||||||
case gesture.TypeClick:
|
case gesture.KindClick:
|
||||||
if state.key != e.Value {
|
if state.key != e.Value {
|
||||||
e.Value = state.key
|
e.Value = state.key
|
||||||
e.changed = true
|
e.changed = true
|
||||||
|
|||||||
+1
-1
@@ -62,7 +62,7 @@ func (s *Scrollbar) Layout(gtx layout.Context, axis layout.Axis, viewportStart,
|
|||||||
|
|
||||||
// Jump to a click in the track.
|
// Jump to a click in the track.
|
||||||
for _, event := range s.track.Events(gtx) {
|
for _, event := range s.track.Events(gtx) {
|
||||||
if event.Type != gesture.TypeClick ||
|
if event.Kind != gesture.KindClick ||
|
||||||
event.Modifiers != key.Modifiers(0) ||
|
event.Modifiers != key.Modifiers(0) ||
|
||||||
event.NumClicks > 1 {
|
event.NumClicks > 1 {
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -236,8 +236,8 @@ func (e *Selectable) processPointer(gtx layout.Context) {
|
|||||||
switch evt := evt.(type) {
|
switch evt := evt.(type) {
|
||||||
case gesture.ClickEvent:
|
case gesture.ClickEvent:
|
||||||
switch {
|
switch {
|
||||||
case evt.Type == gesture.TypePress && evt.Source == pointer.Mouse,
|
case evt.Kind == gesture.KindPress && evt.Source == pointer.Mouse,
|
||||||
evt.Type == gesture.TypeClick && evt.Source != pointer.Mouse:
|
evt.Kind == gesture.KindClick && evt.Source != pointer.Mouse:
|
||||||
prevCaretPos, _ := e.text.Selection()
|
prevCaretPos, _ := e.text.Selection()
|
||||||
e.text.MoveCoord(image.Point{
|
e.text.MoveCoord(image.Point{
|
||||||
X: int(math.Round(float64(evt.Position.X))),
|
X: int(math.Round(float64(evt.Position.X))),
|
||||||
|
|||||||
Reference in New Issue
Block a user