AllenDang / giu

Cross platform rapid GUI framework for golang based on Dear ImGui.
MIT License
2.16k stars 128 forks source link

[bug] internal window overwrites menubar #748

Closed jonfriesen closed 6 months ago

jonfriesen commented 6 months ago

What happend?

I'm running v0.7.0 on a M1 Mac. The menu bar should be showing up, but appears to be covered by the SingleWindow.

image

Code example

main.go ```golang package main import ( "github.com/AllenDang/giu" ) var ( showModal bool inputText string ) func loop() { giu.MainMenuBar().Layout( giu.Menu("File").Layout( giu.MenuItem("Open Modal").OnClick(func() { showModal = true }), giu.Separator(), giu.MenuItem("Exit").OnClick(func() { }), ), ).Build() giu.SingleWindow().Layout( giu.Custom(func() { if showModal { giu.OpenPopup("Modal Popup") } giu.PopupModal("Modal Popup").Layout( giu.Label("Enter some text"), giu.InputText(&inputText).Size(200), giu.Button("OK").OnClick(func() { giu.CloseCurrentPopup() showModal = false // You can add additional actions here after clicking OK }), ).Build() }), giu.Label("You entered: "+inputText), ) } func main() { wnd := giu.NewMasterWindow("Custom Modal Example", 400, 200, 0) wnd.Run(loop) } ```

To Reproduce

  1. Run my demo
  2. Note there's no menu bar.

Version

(latest)

OS

MacOS Sonoma 14.2.1 (23C71)

AllenDang commented 6 months ago

You should use SingleWindowWithMenu

jonfriesen commented 6 months ago

Using SingleWindowWithMenu works, eg the example below.

I'm a bit confused what the purpose of MainMenuBar?

func loop() {
    giu.SingleWindowWithMenuBar().Layout(
        giu.MenuBar().Layout(
            giu.Menu("File").Layout(
                giu.MenuItem("Open Modal").OnClick(func() {
                    showModal = true
                }),
                giu.Separator(),
                giu.MenuItem("Exit").OnClick(func() {

                }),
            ),
        ),
        // ... more layouts
    )
}
gucio321 commented 6 months ago

@jonfriesen When you use multiple WindowWidgets, then you use MainMenuBar. When you decide to use SingleWindowWidget and you want menu bar, then you use SingleWindowWithMenubarWidget and the MenuBarWidget.

jonfriesen commented 6 months ago

Thanks for the explanation! That makes sense!

gucio321 commented 6 months ago

also, here is an example:

package main

import "github.com/AllenDang/giu"

var singleWindow bool

func menubarLayout() giu.Widget {
    return giu.Layout{
        giu.Menu("File").Layout(
            giu.MenuItem("Save"),
        ),
    }
}

func loop() {
    if singleWindow {
        giu.SingleWindowWithMenuBar().Layout(
            giu.MenuBar().Layout(menubarLayout()),
            giu.Checkbox("Show single window", &singleWindow),
        )
    } else {
        giu.MainMenuBar().Layout(
            menubarLayout(),
        ).Build()
        giu.Window("Window 1").Layout(
            giu.Label("I am a window 1"),
        )
        giu.Window("Window 2").Layout(
            giu.Label("I am a window 2"),
            giu.Checkbox("Show single window", &singleWindow),
        )
    }
}

func main() {
    wnd := giu.NewMasterWindow("Menubar usage", 640, 480, 0)
    wnd.Run(loop)
}