Esempio n. 1
0
func ui_main() {
	exit := make(chan bool)
	go func() {
		fmt.Println("vfc/ui")
		ui.OnInsertObject(func(v interface{}) {
			fmt.Println("add item", v)
		})
		ui.OnRemoveObject(func(v interface{}) {
			fmt.Println("remove item", v)
		})
		w := new(MainWindow).Init()
		defer w.Close()

		w.SetSizev(400, 300)
		w.OnCloseEvent(func(e *ui.CloseEvent) {
			fmt.Println("close", e)
		})
		w.Show()
		<-exit
	}()
	ui.Run()
	exit <- true
}
Esempio n. 2
0
func main_ui() {
	ui.OnInsertObject(func(item interface{}) {
		fmt.Println("add item", item)
	})
	ui.OnRemoveObject(func(item interface{}) {
		fmt.Println("remove item", item)
	})

	w := ui.NewWidget()
	defer w.Close()

	w.SetWindowTitle("This is a test")
	fmt.Println(w.WindowTitle())

	vbox := ui.NewVBoxLayout()
	fmt.Println(vbox)
	w.SetLayout(vbox)

	lbl := ui.NewLabel()
	lbl.SetText("<h2><i>Hello</i> <font color=blue><a href=\"ui\">UI</a></font></h2>")
	lbl.OnLinkActivated(fnTEST)
	vbox.AddWidget(lbl)
	vbox.AddStretch(0)

	//runtime.GC()

	btn := ui.NewButton()
	btn.SetText("WbcdefgwqABCDEFQW")
	font := btn.Font()
	defer font.Close()
	font.SetPointSize(16)
	btn.SetFont(font)
	fmt.Println("f3->", btn.Font())

	btn2 := ui.NewButton()
	font.SetPointSize(18)
	btn2.SetAttr("text", "WbcdefgwqABCDEFQW")
	btn2.SetAttr("font", font)

	btn.OnClicked(func() {
		fmt.Println(btn)
		btn.Close()
	})
	btn.OnCloseEvent(func(e *ui.CloseEvent) {
		fmt.Println("Close", e)
	})
	btn3 := ui.NewButton()
	btn3.SetText("Exit")
	btn3.OnClicked(func() {
		ui.Exit(0)
	})

	l := w.Layout()
	fmt.Println("ll", l)
	l.AddWidget(btn)
	l.AddWidget(btn2)
	l.AddWidget(btn3)
	//vbox.AddWidget(btn)
	f := btn2.Attr("parent")
	fmt.Println("parent->", f, f == nil)

	fmt.Println(btn.Font())

	w.OnResizeEvent(func(e *ui.ResizeEvent) {
		fmt.Println(e)
	})

	w.OnPaintEvent(func(ev *ui.PaintEvent) {
		fnPaint(ev, w)
	})

	//w.Show()
	w.SetVisible(true)
	<-exit
}
Esempio n. 3
0
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()
}