AllenDang / giu

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

After upgrading to giu 0.8.0, you cannot use g.Row() to arrange Button widgets horizontally #807

Open wsczx opened 1 week ago

wsczx commented 1 week ago

What happend?

After upgrading to giu 0.8.0, I cannot use g.Row() to arrange Button widgets horizontally. 0.7.0 has no problem at all

Code example

main.go ```golang g.Row( g.Button("Save").OnClick(func() { if err := conf.SaveConfig(conf.Cfg); err != nil { log.Printf("Configuration save failed: %s", err) g.Msgbox("Warning", "Configuration save failed, please check the log!") } else { g.Msgbox("Tip:", "Configuration saved successfully!") } }), g.Button("Exit").OnClick(func() { systray.Quit() os.Exit(0) }), ), ```

To Reproduce

  1. Run my demo
  2. will see the crash...

Version

(latest)

OS

Windows11

gucio321 commented 1 week ago

I need more code, because this one works for me image

package main

import (
    "github.com/AllenDang/giu"

    g "github.com/AllenDang/giu"
)

func loop() {
    giu.SingleWindow().Layout(
        g.Row(
            g.Button("Save").OnClick(func() {
                /*
                    if err := conf.SaveConfig(conf.Cfg); err != nil {
                        log.Printf("Configuration save failed: %s", err)
                        g.Msgbox("Warning", "Configuration save failed, please check the log!")
                    } else {
                        g.Msgbox("Tip:", "Configuration saved successfully!")
                    }
                */
            }),
            g.Button("Exit").OnClick(func() {
                /*
                    systray.Quit()
                    os.Exit(0)
                */
            }),
        ),
    )
}

func main() {
    wnd := giu.NewMasterWindow("Issue 807", 640, 480, 0)
    wnd.Run(loop)
}
wsczx commented 1 week ago
package main

import (
    g "github.com/AllenDang/giu"
)

func main() {
    w := g.NewMasterWindow("Test", 400, 350, g.MasterWindowFlagsNotResizable)
    w.Run(loop)
}

func loop() {
    g.SingleWindow().Layout(
        // g.Align(g.AlignCenter).To(
        g.Row(
            g.Button("Save").OnClick(func() {}),
            g.Button("Exit").OnClick(func() {}),
        ),
        // ),
        g.PrepareMsgbox(),
    )
}

It seems that the Align (g. AlignCenter) was caused by the use of centering Using g.Align(g.AlignCenter). To will cause the buttons to not be arranged horizontally