Beispiel #1
0
func main() {
	ui.Main(func() {
		w := ui.NewWidget()

		w.OnPaintEvent(func(e *ui.PaintEvent) {
			paint := ui.NewPainter()
			defer paint.Close()
			paint.Begin(w)
			pen := ui.NewPen()
			pen.SetColor(color.RGBA{255, 128, 0, 0})
			pen.SetWidth(2)
			fmt.Println(pen, pen.Color(), pen.Width())
			paint.SetPen(pen)
			brush := ui.NewBrush()
			brush.SetStyle(ui.SolidPattern)
			brush.SetColor(color.RGBA{128, 128, 0, 255})
			paint.SetBrush(brush)
			paint.DrawRect(ui.Rect{10, 10, 100, 100})
		})

		w.SetSize(ui.Size{400, 400})
		w.Show()

		ui.Run()
	})
}
Beispiel #2
0
func ui_main() {
	w := ui.NewWidget()
	w.SetWindowTitle(ui.Version())
	w.SetSizev(300, 200)
	defer w.Close()
	w.Show()
	<-exit
}
Beispiel #3
0
func main() {
	fmt.Println(ui.Version())
	ui.Main(func() {
		w := ui.NewWidget()
		w.SetWindowTitle(ui.Version())
		w.SetSizev(300, 200)
		defer w.Close()
		w.Show()
		ui.Run()
	})
}
Beispiel #4
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
}
Beispiel #5
0
func ui_main() {

	w := ui.NewWidget()
	w.SetWindowTitle(ui.Version())
	w.SetSizev(300, 200)
	defer w.Close()

	d := alertdialog.NewAlertDialog()
	d.SetMessage("Hello\nWelcome Go lang world!!")

	d.Open()
	defer d.Close()

	w.Show()
	<-exit
}
Beispiel #6
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
}
Beispiel #7
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()
}
Beispiel #8
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
}
Beispiel #9
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()
}