Ejemplo n.º 1
0
func main() {
	ui.Main(func() {
		go ui_main()
		ui.Run()
		exit <- true
	})
}
Ejemplo n.º 2
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()
	})
}
Ejemplo n.º 3
0
func main() {
	fmt.Println(ui.Version())
	ui.Main(func() {
		go main_ui()
		ui.Run()
		exit <- true
	})
}
Ejemplo n.º 4
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()
	})
}
Ejemplo n.º 5
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
}
Ejemplo n.º 6
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()
}
Ejemplo n.º 7
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()
}
Ejemplo n.º 8
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()
}