New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
keyboard controllable popup menu #2056
keyboard controllable popup menu #2056
Conversation
… to avoid dependencies down the package tree.
Making this public would address fyne-io#709.
There are no internal tests inside.
I can’t figure out why the new type was needed, it looks like a huge change for something that should have been less far-reaching.
But as I said above these questions probably stem from me not understanding why the wrapped objects were required. |
|
OK, The |
I don't think that the diff --git a/widget/popup_menu.go b/widget/popup_menu.go
index 83345530..902db094 100644
--- a/widget/popup_menu.go
+++ b/widget/popup_menu.go
@@ -19,7 +19,7 @@ func NewPopUpMenu(menu *fyne.Menu, c fyne.Canvas) *PopUpMenu {
p := &PopUpMenu{Menu: NewMenu(menu), canvas: c}
p.Menu.Resize(p.Menu.MinSize())
p.Menu.customSized = true
- o := widget.NewOverlayContainer(p.Menu, c, p.Dismiss)
+ o := widget.NewOverlayContainer(p, c, p.Dismiss)
o.Resize(o.MinSize())
p.overlay = o
p.OnDismiss = func() {
@@ -28,6 +28,24 @@ func NewPopUpMenu(menu *fyne.Menu, c fyne.Canvas) *PopUpMenu {
return p
}
+func (p *PopUpMenu) TypedKey(e *fyne.KeyEvent) {
+ switch e.Name {
+ case fyne.KeyEscape:
+ p.Hide()
+ case fyne.KeyDown:
+ p.ActivateNext()
+ case fyne.KeyUp:
+ p.ActivatePrevious()
+ }
+}
+
+func (p *PopUpMenu) TypedRune(rune) {
+}
+
+func (p *PopUpMenu) FocusGained() {}
+
+func (p *PopUpMenu) FocusLost() {}
+
// ShowPopUpMenuAtPosition creates a PopUp menu populated with items from the passed menu structure.
// It will automatically be positioned at the provided location and shown as an overlay on the specified canvas.
func ShowPopUpMenuAtPosition(menu *fyne.Menu, c fyne.Canvas, pos fyne.Position) {
@@ -35,13 +53,6 @@ func ShowPopUpMenuAtPosition(menu *fyne.Menu, c fyne.Canvas, pos fyne.Position)
m.ShowAtPosition(pos)
}
-// CreateRenderer returns a new renderer for the pop-up menu.
-//
-// Implements: fyne.Widget
-func (p *PopUpMenu) CreateRenderer() fyne.WidgetRenderer {
- return p.overlay.CreateRenderer()
-}
-
// Hide hides the pop-up menu.
//
// Implements: fyne.Widget
@@ -72,6 +83,7 @@ func (p *PopUpMenu) Resize(size fyne.Size) {
func (p *PopUpMenu) Show() {
p.overlay.Show()
p.Menu.Show()
+ p.canvas.Focus(p)
}
// ShowAtPosition shows the pop-up menu at the specified position. |
This will be addressed by a new PR based on the current |
Description:
This PR implements keyboard control for pop-up menus.
For this it introduces a simple canvas object wrapper which might be elaborated into a solution for #709.
Checklist: