Example #1
0
File: main.go Project: kch42/biomed
func (g *GUI) mkSidebar() *gtk.ScrolledWindow {
	sbVBox := gtk.NewVBox(false, 0)

	sbVBox.PackStart(labelCustomFont("Tools", "Sans Bold 14"), false, false, 3)

	g.showbiomes = gtk.NewCheckButtonWithLabel("Show Biomes")
	g.showbiomes.SetActive(true)
	g.showbiomes.Connect("toggled", g.showbiomesToggled)
	sbVBox.PackStart(g.showbiomes, false, false, 3)

	g.fixSnowIce = gtk.NewCheckButtonWithLabel("Fix Snow/Ice")
	g.fixSnowIce.SetTooltipText("Add Snow/Ice for Taiga/Ice Plains. Remove Snow/Ice for other biomes.")
	g.fixSnowIce.Connect("toggled", g.fixSnowIceToggled)
	sbVBox.PackStart(g.fixSnowIce, false, false, 3)

	fill := gtk.NewRadioButtonWithLabel(nil, "Fill")
	fill.SetActive(true)
	fill.Connect("toggled", g.mkUpdateToolFx(fill, NewFillTool()))

	draw := gtk.NewRadioButtonWithLabel(fill.GetGroup(), "Draw")
	drawRadius := gtk.NewSpinButtonWithRange(1, 20, 1)
	drawHBox := gtk.NewHBox(false, 0)
	drawHBox.PackStart(draw, true, true, 0)
	drawHBox.PackStart(gtk.NewLabel("Radius:"), false, false, 3)
	drawHBox.PackEnd(drawRadius, false, false, 3)
	draw.Connect("toggled", g.mkUpdateToolFx(draw, NewDrawTool(func() int { return drawRadius.GetValueAsInt() })))

	sbVBox.PackStart(fill, false, false, 3)
	sbVBox.PackStart(drawHBox, false, false, 3)

	sbVBox.PackStart(gtk.NewHSeparator(), false, false, 3)
	bioHeaderHBox := gtk.NewHBox(false, 0)
	bioHeaderHBox.PackStart(labelCustomFont("Biomes", "Sans Bold 14"), true, false, 0)
	editBiomesBtn := gtk.NewButton()
	editBiomesBtn.Add(gtk.NewImageFromStock(gtk.STOCK_EDIT, gtk.ICON_SIZE_SMALL_TOOLBAR))
	editBiomesBtn.Connect("clicked", g.biomeEditor)
	editBiomesBtn.SetTooltipText("Configure Biomes")
	bioHeaderHBox.PackStart(editBiomesBtn, false, false, 0)
	sbVBox.PackStart(bioHeaderHBox, false, false, 3)

	g.bioVBoxWrap = gtk.NewVBox(false, 0)
	g.bioVBox = gtk.NewVBox(false, 0)
	g.bioVBoxWrap.PackStart(g.bioVBox, false, false, 0)
	sbVBox.PackStart(g.bioVBoxWrap, false, false, 3)
	g.updateBiomeInfo()

	scrolled := gtk.NewScrolledWindow(nil, nil)
	scrolled.SetPolicy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
	scrolled.AddWithViewPort(sbVBox)
	return scrolled
}
Example #2
0
func main() {
	gtk.Init(nil)
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetPosition(gtk.WIN_POS_CENTER)
	window.SetTitle("Lab 1")
	window.Connect("destroy",
		func(ctx *glib.CallbackContext) {
			gtk.MainQuit()
		},
		"Window destroyed")

	all_boxes := gtk.NewVBox(false, 0)
	base_conversion_box := gtk.NewHBox(false, 0)

	left_label_vbox := gtk.NewVBox(false, 5)
	number_entry_label := gtk.NewLabel("Input:")
	output_number_label := gtk.NewLabel("Output:")
	left_label_vbox.PackStart(number_entry_label, true, true, 0)
	left_label_vbox.PackStart(output_number_label, true, true, 0)

	left_input_vbox := gtk.NewVBox(false, 5)
	number_entry := gtk.NewEntry()
	output_number := gtk.NewEntry()
	left_input_vbox.PackStart(number_entry, true, true, 0)
	left_input_vbox.PackStart(output_number, true, true, 0)

	middle_label_vbox := gtk.NewVBox(false, 5)
	base_entry_label := gtk.NewLabel("Input base:")
	output_number_base10_label := gtk.NewLabel("Output (base 10):")
	middle_label_vbox.PackStart(base_entry_label, true, true, 0)
	middle_label_vbox.PackStart(output_number_base10_label, true, true, 0)

	middle_input_vbox := gtk.NewVBox(false, 5)
	base_entry := gtk.NewEntry()
	output_number_base10 := gtk.NewEntry()
	middle_input_vbox.PackStart(base_entry, true, true, 0)
	middle_input_vbox.PackStart(output_number_base10, true, true, 0)

	right_box := gtk.NewVBox(false, 5)
	output_base_box := gtk.NewHBox(false, 5)
	base_output_entry_label := gtk.NewLabel("Output base:")
	base_output_entry := gtk.NewEntry()
	base_output_entry.SetWidthChars(4)
	output_base_box.PackStart(base_output_entry_label, true, true, 0)
	output_base_box.PackStart(base_output_entry, true, true, 0)
	calculate_button := gtk.NewButtonWithLabel("Calculate")
	right_box.PackStart(output_base_box, true, true, 0)
	right_box.PackStart(calculate_button, true, true, 0)

	base_conversion_box.PackStart(left_label_vbox, true, true, 5)
	base_conversion_box.PackStart(left_input_vbox, true, true, 5)
	base_conversion_box.PackStart(middle_label_vbox, true, true, 5)
	base_conversion_box.PackStart(middle_input_vbox, true, true, 5)
	base_conversion_box.PackStart(right_box, true, true, 5)

	calculate_button.Clicked(func() {
		starting_number := number_entry.GetText()
		starting_base := base_entry.GetText()
		integer := string_to_int(starting_number, starting_base)
		output_number_base10.SetText(strconv.Itoa(integer))
		converted_number := int_to_string(integer, char_to_int(base_output_entry.GetText()))
		output_number.SetText(converted_number)
	})

	string_conversion_box := gtk.NewHBox(false, 5)
	input_label := gtk.NewLabel("Input string:")
	input_string := gtk.NewEntry()
	caps_label := gtk.NewLabel("Captial:")
	all_caps := gtk.NewEntry()
	lower_label := gtk.NewLabel("Lower case:")
	all_lower := gtk.NewEntry()
	convert_button := gtk.NewButtonWithLabel("Convert")
	string_conversion_box.PackStart(input_label, true, true, 0)
	string_conversion_box.PackStart(input_string, true, true, 0)
	string_conversion_box.PackStart(caps_label, true, true, 0)
	string_conversion_box.PackStart(all_caps, true, true, 0)
	string_conversion_box.PackStart(lower_label, true, true, 0)
	string_conversion_box.PackStart(all_lower, true, true, 0)
	string_conversion_box.PackStart(convert_button, true, true, 0)

	convert_button.Clicked(func() {
		string_to_convert := input_string.GetText()
		all_caps.SetText(caps(string_to_convert))
		all_lower.SetText(lowers(string_to_convert))
	})

	all_boxes.PackStart(base_conversion_box, true, true, 0)
	all_boxes.PackStart(gtk.NewHSeparator(), true, true, 10)
	all_boxes.PackStart(string_conversion_box, true, true, 0)
	window.Add(all_boxes)
	window.ShowAll()
	gtk.Main()
}