func (p *MainWindow) Init() *MainWindow { if p.Widget.Init() == nil { return nil } p.SetWindowTitle("MainWindow") p.tab = ui.NewTabWidget() p.tab.AddTab(p.createStdTab(), "Standard", nil) p.tab.AddTab(p.createMyTab(), "Custom", nil) p.tab.AddTab(p.createToolBox(), "ToolBox", nil) p.sbar = ui.NewStatusBar() menubar := ui.NewMenuBar() menu := ui.NewMenuWithTitle("&File") //menu.SetTitle("&File") menubar.AddMenu(menu) act := ui.NewAction() act.SetText("&Quit") act.OnTriggered(func(bool) { p.Close() }) ic := ui.NewIconWithFile("images/close.png") //defer ic.Close() act.SetIcon(ic) menu.AddAction(act) toolBar := ui.NewToolBar() toolBar.AddAction(act) toolBar.AddSeparator() cmb := ui.NewComboBox() cmb.AddItem("test1") cmb.AddItem("test2") cmb.SetToolTip("ComboBox") cmbAct := toolBar.AddWidget(cmb) fmt.Println(cmbAct) vbox := ui.NewVBoxLayout() vbox.SetMargin(0) vbox.SetSpacing(0) vbox.SetMenuBar(menubar) vbox.AddWidget(toolBar) vbox.AddWidget(p.tab) vbox.AddWidget(p.sbar) p.SetLayout(vbox) p.tab.OnCurrentChanged(func(index int) { p.sbar.ShowMessage("current: "+p.tab.TabText(index), 0) }) systray := ui.NewSystemTray() systray.SetContextMenu(menu) systray.SetIcon(ic) systray.SetVisible(true) systray.ShowMessage("hello", "this is a test", ui.Information, 1000) ic2 := systray.Icon() fmt.Println(ic2) p.SetWindowIcon(ic2) return p }
func main_ui() { ui.OnInsertObject(func(v interface{}) { fmt.Println("add item", v) }) ui.OnRemoveObject(func(v interface{}) { fmt.Println("remove item", v) }) w := ui.NewMainWindow() defer w.Close() go func() { dock := ui.NewDockWidgetWithTitle("Dock") dock.SetDock(ui.NewButtonWithText("Hello")) w.AddDockWidget(ui.LeftDockWidgetArea, dock) btn := ui.NewButtonWithText("HideDock") w.SetCentralWidget(btn) w.SetSize(ui.Sz(200, 200)) tb := ui.NewToolBarWithTitle("Standard") tb.AddWidget(ui.NewButtonWithText("ok")) w.AddToolBar(tb) tb.OnCloseEvent(func(e *ui.CloseEvent) { fmt.Println("tb close", e) }) sb := ui.NewStatusBar() w.SetStatusBar(sb) sb.OnCloseEvent(func(e *ui.CloseEvent) { fmt.Println("sb close", e) }) btn.OnClicked(func() { dock.Hide() runtime.GC() btn.SetText(btn.Text()) }) dock.OnCloseEvent(func(e *ui.CloseEvent) { fmt.Println(e) }) go func() { for { timer := time.NewTimer(1) select { case <-timer.C: btn.SetText(btn.Text()) btn.SetText(btn.Text()) btn.SetText(btn.Text()) fmt.Println(">", btn.Text()) if btn.Text() != "HideDock" { panic("close") } } } }() dock.OnVisibilityChanged(func(b bool) { fmt.Println(b) if !b { time.AfterFunc(1e9, func() { if dock.IsValid() { dock.Show() } }) } }) w.Show() }() ui.Run() }