summaryrefslogtreecommitdiff
path: root/redo/controls.go
blob: b40256a07a06dd4b20d774edbf18f2470fabba5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// 7 july 2014

package ui

// Control represents a control.
// All Controls have event handlers that take a single argument (the Doer active during the event) and return nothing.
type Control interface {
	// TODO reparent (public)
	// TODO enable/disable (public)
	// TODO show/hide (public)
	// TODO sizing (likely private)
}

// Button is a clickable button that performs some task.
type Button interface {
	Control

	// OnClicked creates a Request to set the event handler for when the Button is clicked.
	OnClicked(func(d Doer)) *Request

	// Text and SetText creates a Request that get and set the Button's label text.
	Text() *Request
	SetText(text string) *Request
}

// NewButton creates a Request to create a new Button with the given label text.
func NewButton(text string) *Request {
	return newButton(text)
}

// GetNewButton is like NewButton but sends the Request along the given Doer and returns the resultant Button.
// Example:
// 	b := ui.GetNewButton(ui.Do, "OK")
func GetNewButton(c Doer, text string) Button {
	req := newButton(text)
	c <- req
	return (<-req.resp).(Button)
}