forked from joejulian/gio
widget: [API] replace Focus methods with explicit FocusCmds
Now that widgets by convention may be focused by issuing FocusCmd directly, remove the now redundant Focus methods on Clickable, Editor, Selectable. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+1
-1
@@ -34,7 +34,7 @@ func FuzzIME(f *testing.F) {
|
||||
|
||||
var r input.Router
|
||||
gtx := layout.Context{Ops: new(op.Ops), Source: r.Source()}
|
||||
e.Focus(gtx)
|
||||
gtx.Execute(key.FocusCmd{Tag: e})
|
||||
// Layout once to register focus.
|
||||
e.Layout(gtx, cache, font.Font{}, unit.Sp(10), op.CallOp{}, op.CallOp{})
|
||||
r.Frame(gtx.Ops)
|
||||
|
||||
@@ -66,11 +66,6 @@ func (b *Clickable) Pressed() bool {
|
||||
return b.click.Pressed()
|
||||
}
|
||||
|
||||
// Focus requests the input focus for the element.
|
||||
func (b *Clickable) Focus(gtx layout.Context) {
|
||||
gtx.Execute(key.FocusCmd{Tag: b})
|
||||
}
|
||||
|
||||
// Focused reports whether b has focus.
|
||||
func (b *Clickable) Focused() bool {
|
||||
return b.focused
|
||||
|
||||
@@ -38,7 +38,7 @@ func TestClickable(t *testing.T) {
|
||||
r.Frame(gtx.Ops)
|
||||
}
|
||||
// frame: request focus for button 1
|
||||
b1.Focus(gtx)
|
||||
gtx.Execute(key.FocusCmd{Tag: &b1})
|
||||
frame()
|
||||
// frame: gain focus for button 1
|
||||
frame()
|
||||
@@ -78,7 +78,7 @@ func TestClickable(t *testing.T) {
|
||||
t.Error("button 1 got clicked, even if it only got return press")
|
||||
}
|
||||
// frame: request focus for button 2
|
||||
b2.Focus(gtx)
|
||||
gtx.Execute(key.FocusCmd{Tag: &b2})
|
||||
frame()
|
||||
// frame: gain focus for button 2
|
||||
frame()
|
||||
|
||||
+1
-6
@@ -257,7 +257,7 @@ func (e *Editor) processPointer(gtx layout.Context) {
|
||||
X: int(math.Round(float64(evt.Position.X))),
|
||||
Y: int(math.Round(float64(evt.Position.Y))),
|
||||
})
|
||||
e.Focus(gtx)
|
||||
gtx.Execute(key.FocusCmd{Tag: e})
|
||||
if e.scroller.State() != gesture.StateFlinging {
|
||||
e.scrollCaret = true
|
||||
}
|
||||
@@ -560,11 +560,6 @@ func (e *Editor) command(gtx layout.Context, k key.Event) {
|
||||
}
|
||||
}
|
||||
|
||||
// Focus requests the input focus for the Editor.
|
||||
func (e *Editor) Focus(gtx layout.Context) {
|
||||
gtx.Execute(key.FocusCmd{Tag: e})
|
||||
}
|
||||
|
||||
// Focused returns whether the editor is focused or not.
|
||||
func (e *Editor) Focused() bool {
|
||||
return e.focused
|
||||
|
||||
@@ -115,7 +115,7 @@ func TestEditorReadOnly(t *testing.T) {
|
||||
if cStart != cEnd {
|
||||
t.Errorf("unexpected initial caret positions")
|
||||
}
|
||||
e.Focus(gtx)
|
||||
gtx.Execute(key.FocusCmd{Tag: e})
|
||||
layoutEditor := func() layout.Dimensions {
|
||||
return e.Layout(gtx, cache, font, fontSize, op.CallOp{}, op.CallOp{})
|
||||
}
|
||||
@@ -514,7 +514,7 @@ func TestEditorDimensions(t *testing.T) {
|
||||
cache := text.NewShaper(text.NoSystemFonts(), text.WithCollection(gofont.Collection()))
|
||||
fontSize := unit.Sp(10)
|
||||
font := font.Font{}
|
||||
e.Focus(gtx)
|
||||
gtx.Execute(key.FocusCmd{Tag: e})
|
||||
e.Layout(gtx, cache, font, fontSize, op.CallOp{}, op.CallOp{})
|
||||
r.Frame(gtx.Ops)
|
||||
r.Queue(key.EditEvent{Text: "A"})
|
||||
@@ -906,7 +906,7 @@ g 2 4 6 8 g
|
||||
e.Layout(gtx, cache, font, fontSize, op.CallOp{}, op.CallOp{})
|
||||
e.Events() // throw away any events from this layout
|
||||
|
||||
e.Focus(gtx)
|
||||
gtx.Execute(key.FocusCmd{Tag: e})
|
||||
r.Frame(gtx.Ops)
|
||||
gtx.Source = r.Source()
|
||||
// Build the selection events
|
||||
@@ -1000,7 +1000,7 @@ func TestSelectMove(t *testing.T) {
|
||||
fontSize := unit.Sp(10)
|
||||
|
||||
// Layout once to populate e.lines and get focus.
|
||||
e.Focus(gtx)
|
||||
gtx.Execute(key.FocusCmd{Tag: e})
|
||||
e.Layout(gtx, cache, font, fontSize, op.CallOp{}, op.CallOp{})
|
||||
r.Frame(gtx.Ops)
|
||||
// Set up selecton so the Editor key handler filters for all 4 directional keys.
|
||||
@@ -1090,7 +1090,7 @@ func TestEditor_MaxLen(t *testing.T) {
|
||||
cache := text.NewShaper(text.NoSystemFonts(), text.WithCollection(gofont.Collection()))
|
||||
fontSize := unit.Sp(10)
|
||||
font := font.Font{}
|
||||
e.Focus(gtx)
|
||||
gtx.Execute(key.FocusCmd{Tag: e})
|
||||
e.Layout(gtx, cache, font, fontSize, op.CallOp{}, op.CallOp{})
|
||||
r.Frame(gtx.Ops)
|
||||
r.Queue(
|
||||
@@ -1126,7 +1126,7 @@ func TestEditor_Filter(t *testing.T) {
|
||||
cache := text.NewShaper(text.NoSystemFonts(), text.WithCollection(gofont.Collection()))
|
||||
fontSize := unit.Sp(10)
|
||||
font := font.Font{}
|
||||
e.Focus(gtx)
|
||||
gtx.Execute(key.FocusCmd{Tag: e})
|
||||
e.Layout(gtx, cache, font, fontSize, op.CallOp{}, op.CallOp{})
|
||||
r.Frame(gtx.Ops)
|
||||
r.Queue(
|
||||
@@ -1156,7 +1156,7 @@ func TestEditor_Submit(t *testing.T) {
|
||||
cache := text.NewShaper(text.NoSystemFonts(), text.WithCollection(gofont.Collection()))
|
||||
fontSize := unit.Sp(10)
|
||||
font := font.Font{}
|
||||
e.Focus(gtx)
|
||||
gtx.Execute(key.FocusCmd{Tag: e})
|
||||
e.Layout(gtx, cache, font, fontSize, op.CallOp{}, op.CallOp{})
|
||||
r.Frame(gtx.Ops)
|
||||
r.Queue(
|
||||
|
||||
@@ -98,12 +98,6 @@ func (l *Selectable) initialize() {
|
||||
}
|
||||
}
|
||||
|
||||
// Focus requests the input focus for the label.
|
||||
func (l *Selectable) Focus(gtx layout.Context) {
|
||||
gtx.Execute(key.FocusCmd{Tag: l})
|
||||
gtx.Execute(key.SoftKeyboardCmd{Show: true})
|
||||
}
|
||||
|
||||
// Focused returns whether the label is focused or not.
|
||||
func (l *Selectable) Focused() bool {
|
||||
return l.focused
|
||||
@@ -240,7 +234,7 @@ func (e *Selectable) processPointer(gtx layout.Context) {
|
||||
X: int(math.Round(float64(evt.Position.X))),
|
||||
Y: int(math.Round(float64(evt.Position.Y))),
|
||||
})
|
||||
e.Focus(gtx)
|
||||
gtx.Execute(key.FocusCmd{Tag: e})
|
||||
if evt.Modifiers == key.ModShift {
|
||||
start, end := e.text.Selection()
|
||||
// If they clicked closer to the end, then change the end to
|
||||
|
||||
@@ -49,7 +49,7 @@ func TestSelectableMove(t *testing.T) {
|
||||
// Layout once to populate e.lines and get focus.
|
||||
s := new(Selectable)
|
||||
|
||||
s.Focus(gtx)
|
||||
gtx.Execute(key.FocusCmd{Tag: s})
|
||||
s.SetText(str)
|
||||
// Set up selection so the Selectable filters for all 4 directional keys.
|
||||
s.Layout(gtx, cache, font.Font{}, fontSize, op.CallOp{}, op.CallOp{})
|
||||
|
||||
Reference in New Issue
Block a user