io/key: improve InputOp focus and blur

The existing implementation cannot remove the focus of some widget,
doesn't have an option to focus without display the on-screen keyboard
and it automatically focuses the first InputOp, aggressively.

That change aims to make possible: remove focus from any widget. Add
focus without displaying the on-screen-keyboard/soft keyboard. Don't
automatically focus any widget. Don't recover focus when the widget is
visible again.

Fixes gio#180.

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
This commit is contained in:
Inkeliz
2020-11-30 23:40:20 +00:00
committed by Elias Naur
parent e9cd8958de
commit cd3b4561cf
5 changed files with 430 additions and 76 deletions
+5 -1
View File
@@ -399,7 +399,11 @@ func (e *Editor) layout(gtx layout.Context) layout.Dimensions {
e.shapes = append(e.shapes, line{off, path})
}
key.InputOp{Tag: &e.eventKey, Focus: e.requestFocus}.Add(gtx.Ops)
key.InputOp{Tag: &e.eventKey}.Add(gtx.Ops)
if e.requestFocus {
key.FocusOp{Focus: true}.Add(gtx.Ops)
key.SoftKeyboardOp{Show: true}.Add(gtx.Ops)
}
e.requestFocus = false
pointerPadding := gtx.Px(unit.Dp(4))
r := image.Rectangle{Max: e.viewSize}