From 7dc4972a63f14ce10eb3ffac926f08611274a0bd Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 16 May 2019 11:42:28 -0700 Subject: [PATCH] playing around with Destroy() & Delete() Signed-off-by: Jeff Carr --- example-splash/Makefile | 2 + example-splash/main.go | 92 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 example-splash/Makefile create mode 100644 example-splash/main.go diff --git a/example-splash/Makefile b/example-splash/Makefile new file mode 100644 index 0000000..e07773d --- /dev/null +++ b/example-splash/Makefile @@ -0,0 +1,2 @@ +run: + go run *.go diff --git a/example-splash/main.go b/example-splash/main.go new file mode 100644 index 0000000..ef147bc --- /dev/null +++ b/example-splash/main.go @@ -0,0 +1,92 @@ +package main + +import "time" +import "log" +import "fmt" + +import "github.com/andlabs/ui" +import _ "github.com/andlabs/ui/winmanifest" + +var mainwin *ui.Window +var hbox *ui.Box +var vbox *ui.Box +var newgroup *ui.Group + +func makeSplashPage() ui.Control { + hbox = ui.NewHorizontalBox() + hbox.SetPadded(true) + + group := ui.NewGroup("Numbers") + group.SetMargined(true) + hbox.Append(group, true) + + vbox = ui.NewVerticalBox() + vbox.SetPadded(true) + group.SetChild(vbox) + + spinbox := ui.NewSpinbox(47, 100) + slider := ui.NewSlider(21, 100) + pbar := ui.NewProgressBar() + + spinbox.OnChanged(func(*ui.Spinbox) { + slider.SetValue(spinbox.Value()) + pbar.SetValue(spinbox.Value()) + }) + slider.OnChanged(func(*ui.Slider) { + spinbox.SetValue(slider.Value()) + pbar.SetValue(slider.Value()) + }) + vbox.Append(spinbox, false) + vbox.Append(slider, false) + vbox.Append(pbar, false) + + return hbox +} + +func setupUI() { + mainwin = ui.NewWindow("gui-example1", 300, 200, false) + mainwin.OnClosing(func(*ui.Window) bool { + ui.Quit() + return true + }) + ui.OnShouldQuit(func() bool { + mainwin.Destroy() + return true + }) + + tab := ui.NewTab() + mainwin.SetChild(tab) + mainwin.SetMargined(true) + + tab.Append("WIT Splash", makeSplashPage()) + tab.SetMargined(0, true) + + mainwin.Show() +} + +func main() { + go ui.Main(setupUI) + + time.Sleep(1000 * time.Millisecond) + count := 0 + for { + time.Sleep(300 * time.Millisecond) + log.Println("sleep") + + if (newgroup == nil) { + name := "Test " + fmt.Sprintf("%d", count) + log.Println("name=",name) + newgroup = ui.NewGroup(name) + newgroup.SetMargined(true) + hbox.Append(newgroup, false) + // newgroup = append(newgroup, group) + count += 1 + } else { + hbox.Delete(1) + // newgroup.Delete() + // can't destroy when there is a parent + newgroup.Destroy() + newgroup = nil + } + } +}