Complex custom entry widget #5381
Replies: 4 comments
-
Just found canvas.SetOnTypedKey... I'll try that |
Beta Was this translation helpful? Give feedback.
-
Sadly not the canvas TypedKey is stolen by the entry who has focus. So I can still not react on the single F9 keypressed. |
Beta Was this translation helpful? Give feedback.
-
I finally ended up adding a hook on TypedKey in a custom Entry extended widget.. Not the finest but any other ideas are welcome. func (e *Entry) TypedKey(key *fyne.KeyEvent) {
processed := false
if e.OnTypedKey != nil {
processed = e.OnTypedKey(key)
}
if !processed {
e.Entry.TypedKey(key)
}
} |
Beta Was this translation helpful? Give feedback.
-
I don't think you have to choose one over the other - your custom widget would embed an Entry (this is normal), and that entry could be extended to handle additional keypresses / shortcuts. |
Beta Was this translation helpful? Give feedback.
-
Hi,
Let's imagine an Editor widget that will be composed of multiple widget, for example a suggestions list for auto completion.
The fun part is that I should be able to react to a simple "F9" key press.
Multiple possibilities :
If I go with 1), the problem is the focus. If I want my widget to be able to use TypedKey, I need it to be focused. But when the user clicks on the entry that compose the widget, the Entry have the focus and not the custom widget. And this force me to implement all of the interfaces of the Entry to send the event to the entry from the custom widget, and it would not get rid of the focus problem with the mouse click.
If I go with 2), the focus problem is no more. I can override only the TypedKey function and I'm happy. But, I need to create a special renderer to manage the position of the suggestion list based on the current cursors row and col. And if I override the renderer of the Entry... I get into a whole new level of trouble since no renderer are public in Fyne's API.
With 1) I can write my own renderer without any trouble.
I feel I'm kind of trapped with what I trying to accomplish here. Or am I missing a way I could react to my TypedKey "F9" more globally ? Not with a shortcut, because for shortcuts to work a modifier is necessary. Is there any other way ?
Thanks a lot in advance.
Beta Was this translation helpful? Give feedback.
All reactions