giu icon indicating copy to clipboard operation
giu copied to clipboard

How to open popup window from context menu

Open aj3423 opened this issue 3 years ago • 2 comments

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

  1. Run my demo
  2. right click the table row, click "popup edit"
  3. nothing happens

Version

master

OS

Kali Linux

aj3423 avatar Feb 26 '22 02:02 aj3423

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

gucio321 avatar Feb 26 '22 10:02 gucio321

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.

Kindred87 avatar Mar 18 '22 01:03 Kindred87

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!

gucio321 avatar May 09 '23 18:05 gucio321