How to open popup window from context menu
What happend?
I'm trying to open an PopupModal from ContextMenu item, but it doesn't popup.
Code example
main.go
package main
import (
g "github.com/AllenDang/giu"
)
func loop() {
g.SingleWindow().Layout(
// ---- Popup ----
g.PopupModal("edit").Layout(
g.Custom(func() {
g.Label("...").Build()
}),
),
// ---- table ----
g.Custom(func() {
rows := []*g.TableRowWidget{}
rows = append(rows, g.TableRow(
g.Row(
g.Label("row 0"),
g.Selectable("").Selected(true),
g.ContextMenu().Layout(
g.Selectable("popup edit").OnClick(func() {
g.OpenPopup("edit")
}),
),
),
))
g.Table().Columns(
g.TableColumn(``),
).Rows(rows...).Build()
}),
)
}
func main() {
wnd := g.NewMasterWindow("", 400, 300, 0)
wnd.Run(loop)
}
To Reproduce
- Run my demo
- right click the table row, click "popup edit"
- nothing happens
Version
master
OS
Kali Linux
meh, popups... It is IMO the most tricky part of giu. @AllenDang you should refactor it ASAP. IIRC, We had some nice impl of this system in HellSpawner: https://github.com/OpenDiablo2/HellSpawner/blob/master/hswindow/hsdialog/dialog.go. Maybe something like that should work better? (Yah, I know that such a solution isn't prefect, but it at least fixes these strange open state issues) OR maybe something like that:
type PopupMonalWidget struct {
isOpen *bool
isVisible bool
// ...
}
func (p *PopupModalWidget) IsOpen(isOpen *bool) { ... }
func (p *PopupModalWidget) Build() {
if p.isOpen != p.isVisible {
switch p.isOpen {
case true:
OpenPopup(p.id)
case false:
CloseCurrentPopup()
}
p.isVisible = p.isOpen
}
}
the code above should allow user to manage popup's state with IsOpen pointer
I'm experiencing this issue when opening a PopupModal from a MenuItem as well.
I assume the fix proposed by @gucio321 will cover this case as well, but just wanted to report it.
Due to longer inactivity and a full demo code posted above I think it could be closed. Feel free to ping me for any details!