From 4fcd96ac4b4a95563baa598a701442129d0075da Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Sun, 8 Oct 2023 17:58:36 -0500 Subject: [PATCH] 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 --- app/app.go | 6 +++--- app/ime_test.go | 2 +- app/window.go | 4 ++-- layout/context.go | 10 +++++----- layout/list_test.go | 2 +- widget/bool.go | 2 +- widget/button.go | 4 ++-- widget/button_test.go | 2 +- widget/dnd.go | 6 +++--- widget/dnd_test.go | 2 +- widget/editor.go | 2 +- widget/editor_test.go | 20 ++++++++++---------- widget/enum.go | 4 ++-- widget/example_test.go | 4 ++-- widget/material/button.go | 4 ++-- widget/material/checkable.go | 2 +- widget/material/editor.go | 2 +- widget/material/progressbar.go | 2 +- widget/material/slider.go | 2 +- widget/material/switch.go | 2 +- widget/selectable_test.go | 2 +- widget/widget_test.go | 2 +- 22 files changed, 44 insertions(+), 44 deletions(-) diff --git a/app/app.go b/app/app.go index 7d8ab085..071de092 100644 --- a/app/app.go +++ b/app/app.go @@ -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), } diff --git a/app/ime_test.go b/app/ime_test.go index cdab9950..c939a375 100644 --- a/app/ime_test.go +++ b/app/ime_test.go @@ -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) diff --git a/app/window.go b/app/window.go index e21f48f2..440b9c96 100644 --- a/app/window.go +++ b/app/window.go @@ -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), } diff --git a/layout/context.go b/layout/context.go index 7c657e07..4cbb7eaa 100644 --- a/layout/context.go +++ b/layout/context.go @@ -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 } diff --git a/layout/list_test.go b/layout/list_test.go index f5019dbd..65fcc8ef 100644 --- a/layout/list_test.go +++ b/layout/list_test.go @@ -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)} diff --git a/widget/bool.go b/widget/bool.go index 4ed8a6f3..dfed65f6 100644 --- a/widget/bool.go +++ b/widget/bool.go @@ -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 diff --git a/widget/button.go b/widget/button.go index e5e06661..4c3ba365 100644 --- a/widget/button.go +++ b/widget/button.go @@ -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 { diff --git a/widget/button_test.go b/widget/button_test.go index eb8a15c2..fd18684c 100644 --- a/widget/button_test.go +++ b/widget/button_test.go @@ -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)} diff --git a/widget/dnd.go b/widget/dnd.go index 2c0910dc..84027359 100644 --- a/widget/dnd.go +++ b/widget/dnd.go @@ -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 } diff --git a/widget/dnd_test.go b/widget/dnd_test.go index ce57f481..d5474c52 100644 --- a/widget/dnd_test.go +++ b/widget/dnd_test.go @@ -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), } diff --git a/widget/editor.go b/widget/editor.go index e87e8c3e..1e6b1a7d 100644 --- a/widget/editor.go +++ b/widget/editor.go @@ -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 { diff --git a/widget/editor_test.go b/widget/editor_test.go index 7642951f..a13a907c 100644 --- a/widget/editor_test.go +++ b/widget/editor_test.go @@ -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) diff --git a/widget/enum.go b/widget/enum.go index e114f1ae..45359209 100644 --- a/widget/enum.go +++ b/widget/enum.go @@ -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) } diff --git a/widget/example_test.go b/widget/example_test.go index ee99dc09..393190cf 100644 --- a/widget/example_test.go +++ b/widget/example_test.go @@ -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. diff --git a/widget/material/button.go b/widget/material/button.go index 4edab341..e238e432 100644 --- a/widget/material/button.go +++ b/widget/material/button.go @@ -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) diff --git a/widget/material/checkable.go b/widget/material/checkable.go index 35115fa4..d4662eaf 100644 --- a/widget/material/checkable.go +++ b/widget/material/checkable.go @@ -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} diff --git a/widget/material/editor.go b/widget/material/editor.go index db3c7935..b00a48fb 100644 --- a/widget/material/editor.go +++ b/widget/material/editor.go @@ -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 diff --git a/widget/material/progressbar.go b/widget/material/progressbar.go index 2ee9a416..fc17cf0c 100644 --- a/widget/material/progressbar.go +++ b/widget/material/progressbar.go @@ -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) diff --git a/widget/material/slider.go b/widget/material/slider.go index 3f9ab73a..d3283d21 100644 --- a/widget/material/slider.go +++ b/widget/material/slider.go @@ -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) } diff --git a/widget/material/switch.go b/widget/material/switch.go index 1c21581e..62fbb942 100644 --- a/widget/material/switch.go +++ b/widget/material/switch.go @@ -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 diff --git a/widget/selectable_test.go b/widget/selectable_test.go index fdec9829..8b40d2d9 100644 --- a/widget/selectable_test.go +++ b/widget/selectable_test.go @@ -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{} diff --git a/widget/widget_test.go b/widget/widget_test.go index db82d854..6f7aad3a 100644 --- a/widget/widget_test.go +++ b/widget/widget_test.go @@ -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)