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 }
func main() { gtk.Init(nil) window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL) window.SetPosition(gtk.WIN_POS_CENTER) window.SetTitle("GTK Go!") window.Connect("destroy", func(ctx *glib.CallbackContext) { fmt.Println("got destroy!", ctx.Data().(string)) gtk.MainQuit() }, "foo") //-------------------------------------------------------- // GtkHBox //-------------------------------------------------------- fixed := gtk.NewFixed() //-------------------------------------------------------- // GtkSpinButton //-------------------------------------------------------- spinbutton1 := gtk.NewSpinButtonWithRange(1.0, 10.0, 1.0) spinbutton1.SetDigits(3) spinbutton1.Spin(gtk.SPIN_STEP_FORWARD, 7.0) fixed.Put(spinbutton1, 40, 50) spinbutton1.OnValueChanged(func() { val := spinbutton1.GetValueAsInt() fval := spinbutton1.GetValue() fmt.Println("SpinButton changed, new value: " + strconv.Itoa(val) + " | " + strconv.FormatFloat(fval, 'f', 2, 64)) min, max := spinbutton1.GetRange() fmt.Println("Range: " + strconv.FormatFloat(min, 'f', 2, 64) + " " + strconv.FormatFloat(max, 'f', 2, 64)) fmt.Println("Digits: " + strconv.Itoa(int(spinbutton1.GetDigits()))) }) adjustment := gtk.NewAdjustment(2.0, 1.0, 8.0, 2.0, 0.0, 0.0) spinbutton2 := gtk.NewSpinButton(adjustment, 1.0, 1) spinbutton2.SetRange(0.0, 20.0) spinbutton2.SetValue(18.0) spinbutton2.SetIncrements(2.0, 4.0) fixed.Put(spinbutton2, 150, 50) //-------------------------------------------------------- // Event //-------------------------------------------------------- window.Add(fixed) window.SetSizeRequest(600, 600) window.ShowAll() gtk.Main() }