2014-07-07 08:43:01 -05:00
|
|
|
// 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
|
|
|
|
|
2014-07-07 15:51:17 -05:00
|
|
|
// OnClicked creates a Request to set the event handler for when the Button is clicked.
|
|
|
|
OnClicked(func(d Doer)) *Request
|
2014-07-07 08:43:01 -05:00
|
|
|
|
2014-07-07 15:51:17 -05:00
|
|
|
// Text and SetText creates a Request that get and set the Button's label text.
|
2014-07-07 08:43:01 -05:00
|
|
|
Text() *Request
|
|
|
|
SetText(text string) *Request
|
|
|
|
}
|
|
|
|
|
2014-07-07 15:51:17 -05:00
|
|
|
// NewButton creates a Request to create a new Button with the given label text.
|
2014-07-07 12:40:51 -05:00
|
|
|
func NewButton(text string) *Request {
|
2014-07-07 08:43:01 -05:00
|
|
|
return newButton(text)
|
|
|
|
}
|
|
|
|
|
2014-07-07 12:40:51 -05:00
|
|
|
// 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 {
|
2014-07-07 21:46:23 -05:00
|
|
|
req := newButton(text)
|
|
|
|
c <- req
|
|
|
|
return (<-req.resp).(Button)
|
2014-07-07 08:43:01 -05:00
|
|
|
}
|