-
|
I do it like this: options := fyne.NewMenu("",
fyne.NewMenuItemWithIcon(t("Clear history"), theme.DeleteIcon(), func(){}),
fyne.NewMenuItemWithIcon(t("Show inactive accounts"), theme.VisibilityIcon(), func(){}),
)
optionsBtn.OnTapped = func() {
popup := widget.NewPopUpMenu(options, mainWindow.Canvas())
popup.ShowAtPosition(fyne.NewPos(mainWindow.Canvas().Size().Width - popup.MinSize().Width - 10, 60))
}But you have to admit, this is a bit of a hack, since the coordinates are manually entered "by eye." Is there a built-in way to position the menu? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
|
The buttons default callback does not provide mouse info - you'll want to use the desktop extension for mouse events - extend the button and implement the |
Beta Was this translation helpful? Give feedback.
-
|
I would do optionsBtn.OnTapped = func() {
origin := fyne.CurrentApp().Driver().AbsolutePositionForObject(optionsBtn) // edit: not CanvasForObject
popup := widget.NewPopUpMenu(options, mainWindow.Canvas())
popup.ShowAtPosition(fyne.NewPos(origin.X, origin.Y + optionsBtn.Size().Height))
}This is similar to how the Select widget positions its dropdown if you look at that code |
Beta Was this translation helpful? Give feedback.
Thanks, this code (below) works! It's apparently better than what andydotxyz suggested.