コード例 #1
0
ファイル: example.go プロジェクト: mattn/gui
func LabelledCheckbox(l string) interface {
	gui.Widget
	gui.String
	gui.Changeable
	gui.Bool
} {
	cb := gui.Checkbox()
	label := gui.Text(l)
	table := gui.Row(cb, label)
	label.OnClick(func() gui.Refresh {
		cb.Toggle()
		return cb.HandleChange()
	})
	out := labelledcheckbox{table, label, cb, cb}
	return &out
}
コード例 #2
0
ファイル: example.go プロジェクト: mattn/gui
func main() {
	http.HandleFunc("/style.css", styleServer)
	buttonA := gui.Button("A")
	buttonB := gui.Button("B")
	buttonA.OnClick(func() gui.Refresh {
		fmt.Println("I clicked on button A")
		buttonB.SetString(buttonB.GetString() + buttonB.GetString())
		return gui.StillClean
	})
	buttonB.OnClick(func() gui.Refresh {
		fmt.Println("I clicked on button A")
		t := buttonB.GetString()
		buttonB.SetString(t[:len(t)/2+1])
		return gui.StillClean
	})
	iscool := gui.Checkbox()
	name := gui.EditText("Enter name here")
	hello := gui.Text("Hello world!")
	name.OnChange(func() gui.Refresh {
		hello.SetString("Hello " + name.GetString() + "!")
		return gui.StillClean
	})
	testing_checkbox := LabelledCheckbox("testing")
	testing_checkbox.OnChange(func() gui.Refresh {
		fmt.Println("Hello world")
		if testing_checkbox.GetBool() {
			testing_checkbox.SetString("this test is currently true")
		} else {
			testing_checkbox.SetString("this test is now false")
		}
		return gui.NeedsRefresh
	})

	// Now let's test out a set of radio buttons
	radio := RadioButtons("apples", "lemons", "oranges", "pears")
	radio_report := gui.Text("I like to eat tasty fruit")
	menu := gui.Menu("apples", "lemons", "oranges", "pears")
	radio.OnChange(func() gui.Refresh {
		menu.SetString(radio.GetString())
		radio_report.SetString("I like to eat " + radio.GetString())
		return gui.NeedsRefresh
	})

	menu.OnChange(func() gui.Refresh {
		radio.SetString(menu.GetString())
		radio_report.SetString("I like to eat " + radio.GetString())
		return radio.HandleChange()
	})

	err := gui.Run(12346,
		gui.Column(
			iscool,
			testing_checkbox,
			gui.Row(buttonA, buttonB),
			gui.Row(gui.Text("Name:"), name),
			hello,
			gui.Text("Goodbye world!"),
			radio,
			radio_report,
			menu,
		))
	if err != nil {
		panic("ListenAndServe: " + err.String())
	}
}