andlabs / ui

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

combobox doesn't render on windows? #380

Open markgician opened 4 years ago

markgician commented 4 years ago

Is it a known issue that combobox only render itself after mouse hoover over? This only happens in windows build, is there way to force to redraw the UI? Thanks!

andlabs commented 4 years ago

It is a known issue but I can't figure out on what configurations it happens... keep this open until further notice.

kfsone commented 3 years ago

This reproduces consistently for me: Go 1.16, Windows 10 x64:

https://gist.github.com/fbd4d52084621c49b5bf0b569b9195b4

    package main

    import (
        "fmt"
        "github.com/andlabs/ui"
        _ "github.com/andlabs/ui/winmanifest"
    )

    func makePage1() ui.Control {
        return ui.NewLabel("Page 1")
    }

    func makePage2() ui.Control {
        vb := ui.NewVerticalBox()
        vb.SetPadded(true)

        vb.Append(ui.NewLabel("Choose"), false)

        strings := make([]string, 300)
        for i := 0; i < len(strings); i++ {
            strings[i] = fmt.Sprintf("This is a string to choose %d", i)
        }
        cbox := ui.NewCombobox()
        for _, entry := range strings {
            cbox.Append(entry)
        }
        vb.Append(cbox, false)

        return vb
    }

    func setupUI() {
        win := ui.NewWindow("Test", 800, 600, true)
        win.OnClosing(func(*ui.Window) bool {
            ui.Quit()
            return true
        })
        ui.OnShouldQuit(func() bool {
            win.Destroy()
            return true
        })

        tabCtrl := ui.NewTab()
        win.SetChild(tabCtrl)
        win.SetMargined(true)

        tabCtrl.Append("Tab 1", makePage1())
        tabCtrl.SetMargined(0, true)

        tabCtrl.Append("Tab 2", makePage2())
        tabCtrl.SetMargined(1, true)

        win.Show()
    }

    func main() {
        ui.Main(setupUI)
    }

When you switch to Page 2, the combobox appears invisible until you mouse over it.

kfsone commented 3 years ago

After switching & mousing over, it remains rendered if you switch away & back or to a 3rd tab.

kfsone commented 3 years ago

Thinking it might be related, but there doesn't appear to be a way to prime a ComboBox with a selection:

  cbox := ui.NewComboBox()
  addEntries(cbox)
  cbox.OnSelected(func(_ *ui.Combobox) { panic("on selected") })
  parent.Append(cbox, false)
  cbox.SetSelected(0)
  win.Show()

edit: my bad, cbox.SetSelected never calls OnSelected.