layout,app: [API] rename FrameEvent.Queue and Context.Queue to Source

We're about to replace the interface Queue with a concrete input.Source.
This change renames the field accordingly.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2023-10-08 17:58:36 -05:00
parent d5a0d2cf60
commit 4fcd96ac4b
22 changed files with 44 additions and 44 deletions
+3 -3
View File
@@ -53,8 +53,8 @@ type FrameEvent struct {
// Frame completes the FrameEvent by drawing the graphical operations
// from ops into the window.
Frame func(frame *op.Ops)
// Queue supplies the events for event handlers.
Queue event.Queue
// Source supplies the events for event handlers.
Source event.Queue
}
// Insets is the space taken up by
@@ -96,7 +96,7 @@ func NewContext(ops *op.Ops, e FrameEvent) layout.Context {
return layout.Context{
Ops: ops,
Now: e.Now,
Queue: e.Queue,
Source: e.Source,
Metric: e.Metric,
Constraints: layout.Exact(size),
}
+1 -1
View File
@@ -34,7 +34,7 @@ func FuzzIME(f *testing.F) {
e.Focus()
var r input.Router
gtx := layout.Context{Ops: new(op.Ops), Queue: &r}
gtx := layout.Context{Ops: new(op.Ops), Source: &r}
// Layout once to register focus.
e.Layout(gtx, cache, font.Font{}, unit.Sp(10), op.CallOp{}, op.CallOp{})
r.Frame(gtx.Ops)
+2 -2
View File
@@ -832,7 +832,7 @@ func (w *Window) processEvent(d driver, e event.Event) bool {
w.metric = e2.Metric
w.hasNextFrame = false
e2.Frame = w.update
e2.Queue = &w.queue
e2.Source = &w.queue
// Prepare the decorations and update the frame insets.
wrapper := &w.decorations.Ops
@@ -1014,7 +1014,7 @@ func (w *Window) decorate(d driver, e FrameEvent, o *op.Ops) (size, offset image
gtx := layout.Context{
Ops: o,
Now: e.Now,
Queue: e.Queue,
Source: e.Source,
Metric: e.Metric,
Constraints: layout.Exact(e.Size),
}
+5 -5
View File
@@ -20,9 +20,9 @@ type Context struct {
Constraints Constraints
Metric unit.Metric
// By convention, a nil Queue is a signal to widgets to draw themselves
// By convention, a nil Source is a signal to widgets to draw themselves
// in a disabled state.
Queue event.Queue
Source event.Queue
// Now is the animation time.
Now time.Time
@@ -47,10 +47,10 @@ func (c Context) Sp(v unit.Sp) int {
// Events returns the events available for the key. If no
// queue is configured, Events returns nil.
func (c Context) Events(k event.Tag) []event.Event {
if c.Queue == nil {
if c.Source == nil {
return nil
}
return c.Queue.Events(k)
return c.Source.Events(k)
}
// Disabled returns a copy of this context with a nil Queue,
@@ -59,6 +59,6 @@ func (c Context) Events(k event.Tag) []event.Event {
// By convention, a nil Queue is a signal to widgets to draw themselves
// in a disabled state.
func (c Context) Disabled() Context {
c.Queue = nil
c.Source = nil
return c
}
+1 -1
View File
@@ -70,7 +70,7 @@ func TestListPosition(t *testing.T) {
Constraints: Constraints{
Max: image.Pt(20, 10),
},
Queue: r,
Source: r,
}
el := func(gtx Context, idx int) Dimensions {
return Dimensions{Size: image.Pt(10, 10)}
+1 -1
View File
@@ -46,7 +46,7 @@ func (b *Bool) Layout(gtx layout.Context, w layout.Widget) layout.Dimensions {
b.Update(gtx)
dims := b.clk.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
semantic.SelectedOp(b.Value).Add(gtx.Ops)
semantic.EnabledOp(gtx.Queue != nil).Add(gtx.Ops)
semantic.EnabledOp(gtx.Source != nil).Add(gtx.Ops)
return w(gtx)
})
return dims
+2 -2
View File
@@ -101,7 +101,7 @@ func (b *Clickable) Layout(gtx layout.Context, w layout.Widget) layout.Dimension
dims := w(gtx)
c := m.Stop()
defer clip.Rect(image.Rectangle{Max: dims.Size}).Push(gtx.Ops).Pop()
enabled := gtx.Queue != nil
enabled := gtx.Source != nil
semantic.EnabledOp(enabled).Add(gtx.Ops)
b.click.Add(gtx.Ops)
if enabled {
@@ -119,7 +119,7 @@ func (b *Clickable) Layout(gtx layout.Context, w layout.Widget) layout.Dimension
// clicks, if any.
func (b *Clickable) Update(gtx layout.Context) []Click {
b.clicks = nil
if gtx.Queue == nil {
if gtx.Source == nil {
b.focused = false
}
if b.requestFocus {
+1 -1
View File
@@ -21,7 +21,7 @@ func TestClickable(t *testing.T) {
b1 widget.Clickable
b2 widget.Clickable
)
gtx := app.NewContext(&ops, app.FrameEvent{Queue: &r})
gtx := app.NewContext(&ops, app.FrameEvent{Source: &r})
layout := func() {
b1.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
return layout.Dimensions{Size: image.Pt(100, 100)}
+3 -3
View File
@@ -24,7 +24,7 @@ type Draggable struct {
}
func (d *Draggable) Layout(gtx layout.Context, w, drag layout.Widget) layout.Dimensions {
if gtx.Queue == nil {
if gtx.Source == nil {
return w(gtx)
}
dims := w(gtx)
@@ -56,7 +56,7 @@ func (d *Draggable) Dragging() bool {
// requested to offer data, if any
func (d *Draggable) Update(gtx layout.Context) (mime string, requested bool) {
pos := d.pos
for _, ev := range d.drag.Update(gtx.Metric, gtx.Queue, gesture.Both) {
for _, ev := range d.drag.Update(gtx.Metric, gtx.Source, gesture.Both) {
switch ev.Kind {
case pointer.Press:
d.click = ev.Position
@@ -67,7 +67,7 @@ func (d *Draggable) Update(gtx layout.Context) (mime string, requested bool) {
}
d.pos = pos
for _, ev := range gtx.Queue.Events(&d.handle) {
for _, ev := range gtx.Source.Events(&d.handle) {
if e, ok := ev.(transfer.RequestEvent); ok {
return e.Type, true
}
+1 -1
View File
@@ -17,7 +17,7 @@ func TestDraggable(t *testing.T) {
var r input.Router
gtx := layout.Context{
Constraints: layout.Exact(image.Pt(100, 100)),
Queue: &r,
Source: &r,
Ops: new(op.Ops),
}
+1 -1
View File
@@ -677,7 +677,7 @@ func (e *Editor) layout(gtx layout.Context, textMaterial, selectMaterial op.Call
}
e.showCaret = e.focused && (!blinking || dt%timePerBlink < timePerBlink/2)
}
disabled := gtx.Queue == nil
disabled := gtx.Source == nil
semantic.Editor.Add(gtx.Ops)
if e.Len() > 0 {
+10 -10
View File
@@ -103,7 +103,7 @@ func TestEditorReadOnly(t *testing.T) {
Max: image.Pt(100, 100),
},
Locale: english,
Queue: r,
Source: r,
}
cache := text.NewShaper(text.NoSystemFonts(), text.WithCollection(gofont.Collection()))
fontSize := unit.Sp(10)
@@ -505,7 +505,7 @@ func TestEditorDimensions(t *testing.T) {
gtx := layout.Context{
Ops: new(op.Ops),
Constraints: layout.Constraints{Max: image.Pt(100, 100)},
Queue: r,
Source: r,
Locale: english,
}
cache := text.NewShaper(text.NoSystemFonts(), text.WithCollection(gofont.Collection()))
@@ -891,7 +891,7 @@ g 2 4 6 8 g
gtx := layout.Context{
Ops: new(op.Ops),
Locale: english,
Queue: r,
Source: r,
}
cache := text.NewShaper(text.NoSystemFonts(), text.WithCollection(gofont.Collection()))
font := font.Font{}
@@ -900,13 +900,13 @@ g 2 4 6 8 g
var tim time.Duration
selected := func(start, end int) string {
// Layout once with no events; populate e.lines.
gtx.Queue = nil
gtx.Source = nil
e.Layout(gtx, cache, font, fontSize, op.CallOp{}, op.CallOp{})
e.Events() // throw away any events from this layout
e.Focus()
r.Frame(gtx.Ops)
gtx.Queue = r
gtx.Source = r
// Build the selection events
startPos := e.text.closestToRune(start)
endPos := e.text.closestToRune(end)
@@ -972,7 +972,7 @@ g 2 4 6 8 g
// Constrain the editor to roughly 6 columns wide and redraw
gtx.Constraints = layout.Exact(image.Pt(36, 36))
// Keep existing selection
gtx.Queue = nil
gtx.Source = nil
e.Layout(gtx, cache, font, fontSize, op.CallOp{}, op.CallOp{})
caretStart := e.text.closestToRune(e.text.caret.start)
@@ -991,7 +991,7 @@ func TestSelectMove(t *testing.T) {
gtx := layout.Context{
Ops: new(op.Ops),
Locale: english,
Queue: r,
Source: r,
}
cache := text.NewShaper(text.NoSystemFonts(), text.WithCollection(gofont.Collection()))
font := font.Font{}
@@ -1080,7 +1080,7 @@ func TestEditor_MaxLen(t *testing.T) {
gtx := layout.Context{
Ops: new(op.Ops),
Constraints: layout.Exact(image.Pt(100, 100)),
Queue: r,
Source: r,
}
cache := text.NewShaper(text.NoSystemFonts(), text.WithCollection(gofont.Collection()))
fontSize := unit.Sp(10)
@@ -1116,7 +1116,7 @@ func TestEditor_Filter(t *testing.T) {
gtx := layout.Context{
Ops: new(op.Ops),
Constraints: layout.Exact(image.Pt(100, 100)),
Queue: r,
Source: r,
}
cache := text.NewShaper(text.NoSystemFonts(), text.WithCollection(gofont.Collection()))
fontSize := unit.Sp(10)
@@ -1146,7 +1146,7 @@ func TestEditor_Submit(t *testing.T) {
gtx := layout.Context{
Ops: new(op.Ops),
Constraints: layout.Exact(image.Pt(100, 100)),
Queue: r,
Source: r,
}
cache := text.NewShaper(text.NoSystemFonts(), text.WithCollection(gofont.Collection()))
fontSize := unit.Sp(10)
+2 -2
View File
@@ -40,7 +40,7 @@ func (e *Enum) index(k string) *enumKey {
// Update the state and report whether Value has changed by user interaction.
func (e *Enum) Update(gtx layout.Context) bool {
if gtx.Queue == nil {
if gtx.Source == nil {
e.focused = false
}
e.hovering = false
@@ -117,7 +117,7 @@ func (e *Enum) Layout(gtx layout.Context, k string, content layout.Widget) layou
}
clk := &state.click
clk.Add(gtx.Ops)
enabled := gtx.Queue != nil
enabled := gtx.Source != nil
if enabled {
key.InputOp{Tag: &state.tag, Keys: "⏎|Space"}.Add(gtx.Ops)
}
+2 -2
View File
@@ -25,7 +25,7 @@ func ExampleClickable_passthrough() {
gtx := layout.Context{
Ops: new(op.Ops),
Constraints: layout.Exact(image.Pt(100, 100)),
Queue: &r,
Source: &r,
}
// widget lays out two buttons on top of each other.
@@ -75,7 +75,7 @@ func ExampleDraggable_Layout() {
gtx := layout.Context{
Ops: new(op.Ops),
Constraints: layout.Exact(image.Pt(100, 100)),
Queue: &r,
Source: &r,
}
// mime is the type used to match drag and drop operations.
// It could be left empty in this example.
+2 -2
View File
@@ -133,7 +133,7 @@ func (b ButtonLayoutStyle) Layout(gtx layout.Context, w layout.Widget) layout.Di
defer clip.UniformRRect(image.Rectangle{Max: gtx.Constraints.Min}, rr).Push(gtx.Ops).Pop()
background := b.Background
switch {
case gtx.Queue == nil:
case gtx.Source == nil:
background = f32color.Disabled(b.Background)
case b.Button.Hovered() || b.Button.Focused():
background = f32color.Hovered(b.Background)
@@ -165,7 +165,7 @@ func (b IconButtonStyle) Layout(gtx layout.Context) layout.Dimensions {
defer clip.UniformRRect(image.Rectangle{Max: gtx.Constraints.Min}, rr).Push(gtx.Ops).Pop()
background := b.Background
switch {
case gtx.Queue == nil:
case gtx.Source == nil:
background = f32color.Disabled(b.Background)
case b.Button.Hovered() || b.Button.Focused():
background = f32color.Hovered(b.Background)
+1 -1
View File
@@ -60,7 +60,7 @@ func (c *checkable) layout(gtx layout.Context, checked, hovered bool) layout.Dim
return layout.UniformInset(2).Layout(gtx, func(gtx layout.Context) layout.Dimensions {
size := gtx.Dp(c.Size)
col := c.IconColor
if gtx.Queue == nil {
if gtx.Source == nil {
col = f32color.Disabled(col)
}
gtx.Constraints.Min = image.Point{X: size}
+1 -1
View File
@@ -61,7 +61,7 @@ func (e EditorStyle) Layout(gtx layout.Context) layout.Dimensions {
paint.ColorOp{Color: e.HintColor}.Add(gtx.Ops)
hintColor := hintColorMacro.Stop()
selectionColorMacro := op.Record(gtx.Ops)
paint.ColorOp{Color: blendDisabledColor(gtx.Queue == nil, e.SelectionColor)}.Add(gtx.Ops)
paint.ColorOp{Color: blendDisabledColor(gtx.Source == nil, e.SelectionColor)}.Add(gtx.Ops)
selectionColor := selectionColorMacro.Stop()
var maxlines int
+1 -1
View File
@@ -51,7 +51,7 @@ func (p ProgressBarStyle) Layout(gtx layout.Context) layout.Dimensions {
layout.Stacked(func(gtx layout.Context) layout.Dimensions {
fillWidth := int(float32(progressBarWidth) * clamp1(p.Progress))
fillColor := p.Color
if gtx.Queue == nil {
if gtx.Source == nil {
fillColor = f32color.Disabled(fillColor)
}
return shader(fillWidth, fillColor)
+1 -1
View File
@@ -56,7 +56,7 @@ func (s SliderStyle) Layout(gtx layout.Context) layout.Dimensions {
trans.Pop()
color := s.Color
if gtx.Queue == nil {
if gtx.Source == nil {
color = f32color.Disabled(color)
}
+1 -1
View File
@@ -55,7 +55,7 @@ func (s SwitchStyle) Layout(gtx layout.Context) layout.Dimensions {
if s.Switch.Value {
col = s.Color.Enabled
}
if gtx.Queue == nil {
if gtx.Source == nil {
col = f32color.Disabled(col)
}
trackColor := s.Color.Track
+1 -1
View File
@@ -38,7 +38,7 @@ func TestSelectableMove(t *testing.T) {
gtx := layout.Context{
Ops: new(op.Ops),
Locale: english,
Queue: r,
Source: r,
}
cache := text.NewShaper(text.NoSystemFonts(), text.WithCollection(gofont.Collection()))
fnt := font.Font{}
+1 -1
View File
@@ -22,7 +22,7 @@ func TestBool(t *testing.T) {
r input.Router
b widget.Bool
)
gtx := app.NewContext(&ops, app.FrameEvent{Queue: &r})
gtx := app.NewContext(&ops, app.FrameEvent{Source: &r})
layout := func() {
b.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
semantic.CheckBox.Add(gtx.Ops)