mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
io: [API] introduce event filters; convert pointer input to use them
Instead of having to supply the predicates for event filtering at the
time of layout, the new Filter type allows widgets to filter at the time
of calling Source.Events. There is then only the need for a single input
op type, in package event.
Filters most importantly allow the use of one tag for several event types,
and we can define that a widget w has &w as its primary tag, by convention.
This allows the replacement of per-widget Focus methods with direct uses
of FocusCmd{&w}, and the later addition of Source.Focused(&w) queries.
Note that the TestCursor test needed restructuring to avoid its use of
InputOps.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+20
-20
@@ -144,7 +144,25 @@ func (l *List) Dragging() bool {
|
||||
}
|
||||
|
||||
func (l *List) update(gtx Context) {
|
||||
d := l.scroll.Update(gtx.Metric, gtx.Source, gtx.Now, gesture.Axis(l.Axis))
|
||||
min, max := int(-inf), int(inf)
|
||||
if l.Position.First == 0 {
|
||||
// Use the size of the invisible part as scroll boundary.
|
||||
min = -l.Position.Offset
|
||||
if min > 0 {
|
||||
min = 0
|
||||
}
|
||||
}
|
||||
if l.Position.First+l.Position.Count == l.len {
|
||||
max = -l.Position.OffsetLast
|
||||
if max < 0 {
|
||||
max = 0
|
||||
}
|
||||
}
|
||||
scrollRange := image.Rectangle{
|
||||
Min: l.Axis.Convert(image.Pt(min, 0)),
|
||||
Max: l.Axis.Convert(image.Pt(max, 0)),
|
||||
}
|
||||
d := l.scroll.Update(gtx.Metric, gtx.Source, gtx.Now, gesture.Axis(l.Axis), scrollRange)
|
||||
l.scrollDelta = d
|
||||
l.Position.Offset += d
|
||||
}
|
||||
@@ -332,25 +350,7 @@ func (l *List) layout(ops *op.Ops, macro op.MacroOp) Dimensions {
|
||||
call := macro.Stop()
|
||||
defer clip.Rect(image.Rectangle{Max: dims}).Push(ops).Pop()
|
||||
|
||||
min, max := int(-inf), int(inf)
|
||||
if l.Position.First == 0 {
|
||||
// Use the size of the invisible part as scroll boundary.
|
||||
min = -l.Position.Offset
|
||||
if min > 0 {
|
||||
min = 0
|
||||
}
|
||||
}
|
||||
if l.Position.First+l.Position.Count == l.len {
|
||||
max = -l.Position.OffsetLast
|
||||
if max < 0 {
|
||||
max = 0
|
||||
}
|
||||
}
|
||||
scrollRange := image.Rectangle{
|
||||
Min: l.Axis.Convert(image.Pt(min, 0)),
|
||||
Max: l.Axis.Convert(image.Pt(max, 0)),
|
||||
}
|
||||
l.scroll.Add(ops, scrollRange)
|
||||
l.scroll.Add(ops)
|
||||
|
||||
call.Add(ops)
|
||||
return Dimensions{Size: dims}
|
||||
|
||||
Reference in New Issue
Block a user