Exemplo n.º 1
0
func (p *AlertDialog) Init() *AlertDialog {
	p.Dialog = ui.NewDialog()
	p.SetWindowTitle("Alert Dialog")

	vbox := ui.NewVBoxLayout()

	p.SetLayout(vbox)

	btn := ui.NewButton()
	btn.SetText("OK")
	btn.OnClicked(func() {
		p.Close()
	})

	p.btn = btn

	lbl := ui.NewLabel()
	p.lbl = lbl

	vbox.AddWidget(lbl)
	//	vbox.AddStretch(0)
	vbox.AddWidget(btn)

	return p
}
Exemplo n.º 2
0
func (p *MainWindow) createStdTab() *ui.Widget {
	w := ui.NewWidget()
	vbox := ui.NewVBoxLayout()
	w.SetLayout(vbox)

	ed := ui.NewLineEdit()
	ed.SetInputMask("0000-00-00")
	ed.SetText("2012-01-12")

	lbl := ui.NewLabel()
	lbl.SetText("Label")
	btn := ui.NewButton()
	btn.SetText("Button")
	chk := ui.NewCheckBox()
	chk.SetText("CheckBox")
	radio := ui.NewRadio()
	radio.SetText("Radio")
	cmb := ui.NewComboBox()
	cmb.AddItem("001")
	cmb.AddItem("002")
	cmb.AddItem("003")
	cmb.SetCurrentIndex(2)
	fmt.Println(cmb.CurrentIndex())
	cmb.OnCurrentIndexChanged(func(v int) {
		fmt.Println(cmb.ItemText(v))
	})

	slider := ui.NewSlider()
	slider.SetTickInterval(50)
	slider.SetTickPosition(ui.TicksBothSides)
	slider.SetSingleStep(1)

	scl := ui.NewScrollBar()
	fmt.Println(slider.Range())

	dial := ui.NewDial()

	dial.SetNotchesVisible(true)
	dial.SetNotchTarget(10)
	fmt.Println(dial.NotchSize())

	vbox.AddWidget(ed)
	vbox.AddWidget(lbl)
	vbox.AddWidget(btn)
	vbox.AddWidget(chk)
	vbox.AddWidget(radio)
	vbox.AddWidget(cmb)
	vbox.AddWidget(slider)
	vbox.AddWidget(scl)
	vbox.AddWidget(dial)
	vbox.AddStretch(0)
	return w
}
Exemplo n.º 3
0
func (p *MainWindow) createMyTab() *ui.Widget {
	w := ui.NewWidget()
	vbox := ui.NewVBoxLayout()
	hbox := ui.NewHBoxLayout()
	my := new(MyWidget).Init()
	lbl := ui.NewLabel()
	lbl.SetText("this is custome widget - draw lines")
	btn := ui.NewButton()
	btn.SetText("Clear")
	btn.OnClicked(func() {
		my.Clear()
	})
	hbox.AddWidget(lbl)
	hbox.AddWidgetWith(btn, 0, ui.AlignRight)
	vbox.AddLayout(hbox)
	vbox.AddWidgetWith(my, 1, 0)
	w.SetLayout(vbox)
	return w
}
Exemplo n.º 4
0
func ui_main() {
	w := ui.NewWidget()
	defer w.Close()
	list := ui.NewListWidget()
	vbox := ui.NewVBoxLayout()
	vbox.AddWidget(list)
	w.SetLayout(vbox)
	go func() {
		list.OnCurrentItemChanged(func(item, old *ui.ListWidgetItem) {
			go func() {
				fmt.Println(item.Attr("text"))
			}()
		})

		item := ui.NewListWidgetItem()
		item.SetText("Item1")
		list.AddItem(item)
		list.AddItem(ui.NewListWidgetItemWithText("Item2"))
	}()

	w.Show()

	ui.Run()
}
Exemplo n.º 5
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
}
Exemplo n.º 6
0
func ui_main() {
	w := ui.NewWidget()
	defer w.Close()
	w.SetWindowTitle("Number Place")

	place := ui.NewWidget()
	place.SetMinimumSize(ui.Sz(CELL_WIDTH*10, CELL_WIDTH*10))

	img := ui.NewImageWithSize(CELL_WIDTH*9, CELL_WIDTH*9)
	defer img.Close()

	imgPainter := ui.NewPainterWithImage(img)
	imgPainter.InitFrom(place)
	defer imgPainter.Close()

	place.OnPaintEvent(func(ev *ui.PaintEvent) {
		drawPlace(ev, place)
	})

	vbox := ui.NewVBoxLayout()

	hbox0 := ui.NewHBoxLayout()
	hbox := ui.NewHBoxLayout()
	hboxSelNum := ui.NewHBoxLayout()
	hbox7 := ui.NewHBoxLayout()
	hbox4 := ui.NewHBoxLayout()
	hbox1 := ui.NewHBoxLayout()

	vbox.AddWidget(place)
	vbox.AddLayout(hboxSelNum)
	vbox.AddLayout(hbox7)
	vbox.AddLayout(hbox4)
	vbox.AddLayout(hbox1)
	vbox.AddLayout(hbox0)
	vbox.AddLayout(hbox)

	lblSelectedNum := ui.NewLabelWithText(LBL_SELECTED)
	hboxSelNum.AddWidget(lblSelectedNum)

	Btn1 := ui.NewButtonWithText("1")
	Btn2 := ui.NewButtonWithText("2")
	Btn3 := ui.NewButtonWithText("3")
	Btn4 := ui.NewButtonWithText("4")
	Btn5 := ui.NewButtonWithText("5")
	Btn6 := ui.NewButtonWithText("6")
	Btn7 := ui.NewButtonWithText("7")
	Btn8 := ui.NewButtonWithText("8")
	Btn9 := ui.NewButtonWithText("9")
	BtnCLR := ui.NewButtonWithText("CLR")
	BtnReset := ui.NewButtonWithText("Reset")
	exitBtn := ui.NewButtonWithText("Exit")
	hbox7.AddWidget(Btn7)
	hbox7.AddWidget(Btn8)
	hbox7.AddWidget(Btn9)
	hbox7.AddStretch(0)
	hbox4.AddWidget(Btn4)
	hbox4.AddWidget(Btn5)
	hbox4.AddWidget(Btn6)
	hbox4.AddStretch(0)
	hbox1.AddWidget(Btn1)
	hbox1.AddWidget(Btn2)
	hbox1.AddWidget(Btn3)
	hbox1.AddStretch(0)

	hbox.AddSpacing(10)

	hbox0.AddWidget(BtnCLR)
	hbox0.AddStretch(0)
	hbox.AddStretch(0)
	hbox.AddWidget(BtnReset)
	hbox.AddWidget(exitBtn)

	selectdNumUpdate := func() {
		s := ""
		if selectedNum > 0 {
			s = strconv.Itoa(selectedNum)
		}
		lblSelectedNum.SetText(LBL_SELECTED + s)
	}

	place.OnMousePressEvent(func(ev *ui.MouseEvent) {
		pos := ev.Pos()
		fmt.Println("pos x", pos.X)
		fmt.Println("pos y", pos.Y)
		var ix int = pos.X / CELL_WIDTH
		var iy int = pos.Y / CELL_WIDTH
		if ix < 9 && iy < 9 {
			cursorx = ix
			cursory = iy
			if placeCells[iy][ix].kind != CELL_KIND_FIXED && placeCells[iy][ix].num == 0 {
				placeCells[iy][ix].num = selectedNum
			} else {
				selectedNum = placeCells[iy][ix].num
			}
			placeCheck()
			place.Update()
			selectdNumUpdate()
		}
	})

	numBtnFunc := func(n int) {
		if cursory == -1 {
			return
		}
		if placeCells[cursory][cursorx].kind != CELL_KIND_FIXED {
			placeCells[cursory][cursorx].num = n
			selectedNum = n
			placeCheck()
			place.Update()
			selectdNumUpdate()
		}
	}

	Btn1.OnClicked(func() {
		numBtnFunc(1)
	})
	Btn2.OnClicked(func() {
		numBtnFunc(2)
	})
	Btn3.OnClicked(func() {
		numBtnFunc(3)
	})
	Btn4.OnClicked(func() {
		numBtnFunc(4)
	})
	Btn5.OnClicked(func() {
		numBtnFunc(5)
	})
	Btn6.OnClicked(func() {
		numBtnFunc(6)
	})
	Btn7.OnClicked(func() {
		numBtnFunc(7)
	})
	Btn8.OnClicked(func() {
		numBtnFunc(8)
	})
	Btn9.OnClicked(func() {
		numBtnFunc(9)
	})

	BtnCLR.OnClicked(func() {
		numBtnFunc(0)
	})

	BtnReset.OnClicked(func() {
		selectedNum = 0
		selectdNumUpdate()
		for iy := 0; iy < 9; iy++ {
			for ix := 0; ix < 9; ix++ {
				if placeCells[iy][ix].kind != CELL_KIND_FIXED {
					placeCells[iy][ix].kind = CELL_KIND_NORMAL
					placeCells[iy][ix].num = 0
				}
			}
		}
		place.Update()
	})

	exitBtn.OnClicked(func() {
		w.Close()
	})

	w.SetLayout(vbox)
	w.Show()

	w.OnCloseEvent(func(e *ui.CloseEvent) {
	})

	ui.Run()
}
Exemplo n.º 7
0
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
}