andlabs / ui

Platform-native GUI library for Go.
Other
8.33k stars 651 forks source link

Click on the button to open a new window? #322

Open cgsunshine opened 5 years ago

cgsunshine commented 5 years ago

How to implement

killernova commented 5 years ago

Maybe you can destroy the current window and create a new window. Here is an example:

func SetupSettingUI(w *ui.Window) *ui.Box {
    vbox := ui.NewVerticalBox()
    vbox.SetPadded(true)

    grid := ui.NewGrid()
    grid.SetPadded(true)
    vbox.Append(grid, false)
    button := ui.NewButton("OK")
    button.OnClicked(func(*ui.Button) {
        w.Destroy()
        SetupUI()
    })
    grid.Append(button,
        1, 3, 1, 1,
        false, ui.AlignFill, false, ui.AlignFill)

    return vbox
}

SetupUI function will call function like SetupSettingUI(w *ui.Window) *ui.Box {} to render a new window.

andlabs commented 5 years ago

To open a new window, use ui.NewWindow() and then the Show method on that window. Use OnClicked() to decide what a button does.