Esempio n. 1
0
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
}
Esempio n. 2
0
func main() {
	window := ui.NewWindow("", "Text Example", 2650, 25, 1637, 580)
	table := layout.NewTable(window)
	table.SetCellMargin(ui.Margin{3, 3, 10, 3})
	table.SetRowHeight(0, 40)
	table.SetRowHeight(1, 400)
	table.SetRowHeight(2, 40)
	table.SetRowHeight(3, 80)

	addText := func(a text.Alignment, atxt string, c color.Color, col, row, w, h int) {
		table.SetColWidth(col, 400)
		txt := text.New(table, "", atxt)
		txt.Background = color.Gray10
		txt.Foreground = color.White
		txt.Alignment = text.CENTER
		table.AddMultiCell(txt, col, row-1, w, h)

		txt = text.New(table, "", TEXT)
		txt.Alignment = a
		txt.Foreground = c
		table.AddMultiCell(txt, col, row, w, h)

	}

	addText(text.LEFT, "Left", color.Gray13, 0, 1, 1, 1)
	addText(text.JUSTIFY, "Justify", color.Purple2, 1, 1, 1, 1)
	addText(text.CENTER, "Center", color.Green2, 2, 1, 1, 1)
	addText(text.RIGHT, "Right", color.Blue4, 3, 1, 1, 1)
	addText(text.NOWRAP, "No Wrapping", color.Red2, 0, 3, 4, 1)

	window.SetChild(table)
	end := window.Start()
	<-end
}
Esempio n. 3
0
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
}