Open FrolovDmitry opened 5 years ago
You can't use time.Sleep()
in the UI thread to wait, because nothing will happen while that function is called, including redrawing. (It only seems to work on Windows because of some Windows-specific tricks that not every control uses.)
You can use a goroutine and ui.QueueMain()
to update the progressbar on an interval. I might add a ui.Timer()
at some point in the future (libui already has it).
thanks, it worked:
type progress func(current int)
pbar := ui.NewProgressBar()
button := ui.NewButton("TEST")
button.OnClicked(func(*ui.Button) {
button.Disable()
pbar.Show()
myFunc(func(value int) {
ui.QueueMain(func() {
pbar.SetValue(value)
})
})
})
func myFunc(p progress) {
go func() {
for i := 1; i <= 100; i++ {
time.Sleep(10 * time.Millisecond)
p(i)
}
}()
}
Keeping open until I add this to the documentation I am now writing.
this code works on windows and not work under linux: