示例#1
0
文件: main.go 项目: xormplus/ui-1
func main() {
	window := ui.NewWindow("", "Vizstra Kitchen Sink", 1570, 60, 450, 450)

	fill := layout.NewFill(window)
	fill.SetMargin(ui.Margin{3, 3, 3, 3})
	table := layout.NewTable(fill)
	fill.SetChild(table)

	table.SetDefaultCellDimensions(50, 50)
	table.SetCellMargin(ui.Margin{2, 2, 2, 2})

	b1 := button.NewImageButton(table, "none", "Click Here!")
	b1.HoverBackground = color.RGBA(10, 10, 10, 50)
	b1.SetImagePath("src/github.com/vizstra/ui/res/img/b.png")
	b1.SetHoverImagePath("src/github.com/vizstra/ui/res/img/a.png")
	table.AddMultiCell(b1, 0, 0, 2, 1)

	b2 := button.NewImageButton(table, "none", "Click Here!")
	b2.HoverBackground = color.RGBA(10, 10, 10, 50)
	b2.SetImagePath("src/github.com/vizstra/ui/res/img/candy-apple-icon.png")
	table.AddMultiCell(b2, 2, 0, 2, 1)

	b := button.NewButton(table, "none", "Normal Button")
	table.AddMultiCell(b, 4, 0, 3, 1)

	text := text.New(table, "", "This is a test")
	table.AddMultiCell(text, 4, 1, 4, 7)

	table2 := layout.NewTable(table)
	bg := color.Orange1
	table2.Background = &bg
	table2.SetDefaultCellDimensions(30, 30)
	table.AddMultiCell(table2, 0, 1, 0, 0)

	activity := button.NewActivityBar(table, "", 100.0, []float64{})
	go func() {
		for {
			activity.Data = append(activity.Data, rand.Float64()*100)
			time.Sleep(1000 * time.Millisecond)
		}
	}()

	activity.Foreground = color.Purple2
	table.AddMultiCell(activity, 0, 5, 4, 1)

	pb := button.NewProgressBar(table2, "", 100)
	pb.HoverBackground = color.RGBA(10, 10, 10, 50)
	pb.Value = 70
	table2.AddMultiCell(pb, 0, 1, 4, 1)

	table.AddMultiCell(BuildChart(table), 0, 3, 4, 2)
	window.SetChild(fill)
	end := window.Start()
	<-end
}
示例#2
0
文件: main.go 项目: xormplus/ui-1
func main() {
	window := ui.NewWindow("", "Button Example", 1570, 60, 240, 60)
	fill := layout.NewFill(window)
	fill.SetMargin(ui.Margin{10, 10, 10, 10})
	b := button.NewButton(fill, "", "Click Here!")
	// b.AddMousePositionCB(func(x, y float64) {
	// 	fmt.Println(x, y)
	// })
	// b.AddMouseClickCB(func(m ui.MouseButtonState) {
	// 	fmt.Println(m)
	// })
	fill.SetChild(b)
	window.SetChild(fill)
	end := window.Start()
	<-end
}
示例#3
0
文件: main.go 项目: xormplus/ui-1
func main() {
	window := ui.NewWindow("", "Calculator", 1940, 0, 228, 335)
	fill := layout.NewFill(window)
	fill.SetMargin(ui.Margin{10, 10, 10, 10})

	table := layout.NewTable(fill)
	table.SetDefaultCellDimensions(50, 50)
	table.SetCellMargin(ui.Margin{3, 3, 3, 3})

	fill.SetChild(table)
	window.SetChild(fill)

	buffer := 0.0
	action := NONE
	bartext := NewBartext(table, "", "")

	makebutton := func(text string, c, r, w, h int, cb func(ui.MouseButtonState)) *button.Button {
		b := button.NewButton(table, text, text)
		b.AddMouseClickCB(cb)
		table.AddMultiCell(b, c, r, w, h)
		return b
	}

	makeDefaultButton := func(text string, c, r, w, h int) *button.Button {
		return makebutton(text, c, r, w, h, func(state ui.MouseButtonState) {
			if state.Action == ui.RELEASE {
				bartext.Text += text
			}
		})
	}

	table.AddMultiCell(bartext, 0, 0, 4, 1)

	makeDefaultButton("7", 0, 2, 1, 1)
	makeDefaultButton("4", 0, 3, 1, 1)
	makeDefaultButton("1", 0, 4, 1, 1)
	makeDefaultButton("0", 0, 5, 2, 1)
	makeDefaultButton("8", 1, 2, 1, 1)
	makeDefaultButton("5", 1, 3, 1, 1)
	makeDefaultButton("2", 1, 4, 1, 1)
	makeDefaultButton("9", 2, 2, 1, 1)
	makeDefaultButton("6", 2, 3, 1, 1)
	makeDefaultButton("3", 2, 4, 1, 1)
	makeDefaultButton(".", 2, 5, 1, 1)

	makebutton("Ce", 3, 2, 1, 1, func(state ui.MouseButtonState) {
		if state.Action == ui.RELEASE {
			bartext.Text = ""
			buffer = 0.0
		}
	})

	makebutton("÷", 3, 1, 1, 1, func(state ui.MouseButtonState) {
		if state.Action == ui.RELEASE {
			bartext.Text += "0"
		}
	})

	makebutton("x", 2, 1, 1, 1, func(state ui.MouseButtonState) {
		if state.Action == ui.RELEASE {
			buffer, _ = strconv.ParseFloat(bartext.Text, 64)
			bartext.Text = ""
		}
	})

	makebutton("+", 0, 1, 1, 1, func(state ui.MouseButtonState) {
		if state.Action == ui.RELEASE {
			b, err := strconv.ParseFloat(bartext.Text, 64)
			fmt.Println(b, buffer)
			text := ""
			if err != nil {
				text = "Malformed Number"
			} else if action == NONE {
				text = ""
			} else if action == ADD {

				text = fmt.Sprintf("%f", b+buffer)
			} else {
				buffer = b
			}
			bartext.Text = text
			action = ADD
		}
	})
	makebutton("-", 1, 1, 1, 1, func(state ui.MouseButtonState) {
		if state.Action == ui.RELEASE {
			buffer, _ = strconv.ParseFloat(bartext.Text, 64)
			bartext.Text = ""
		}
	})
	makebutton("=", 3, 3, 1, 3, func(state ui.MouseButtonState) {
		if state.Action == ui.RELEASE {
			buffer, _ = strconv.ParseFloat(bartext.Text, 64)
			bartext.Text = ""
		}
	})

	end := window.Start()
	<-end
}