-- import "github.com/andlabs/ui/redo"
var Do = make(Doer)Do is the main way to issue requests to package ui. Requests returned by the various functions and methods of package ui should be sent across Do to have them performed. When an event is dispatched to an event handler, that event handler will receive a new Doer which is active for the life of the event handler, and any requests made to Do will block until the event handler returns.
func Bool(c Doer, r *Request) boolBool is a convenience function that performs a Request that returns a bool, waits for that request to be processed, and returns the result. For example:
if ui.Bool(ui.Do, checkbox.Checked()) { /* do stuff */ }
func Int(c Doer, r *Request) intInt is like Bool, but for int.
func IntSlice(c Doer, r *Request) []intIntSlice is like Bool, but for []int.
func String(c Doer, r *Request) stringString is like Bool, but for string.
func StringSlice(c Doer, r *Request) []stringStringSlice is like Bool, but for []string.
func Wait(c Doer, r *Request)Wait is a convenience function that performs a Request and waits for that request to be processed. If the request returns a value, it is discarded. You should generally use Wait on functions that do not return a value. See the documentation of Bool for an example.
type Button interface {
Control
// OnClicked sets the event handler for when the Button is clicked.
OnClicked(func(d Doer))
// Text and SetText are Requests that get and set the Button's label text.
Text() *Request
SetText(text string) *Request
}Button is a clickable button that performs some task.
func NewButton(text string) ButtonNewButton creates a new Button with the given label text.
type Checkbox interface {
Control
// OnClicked sets the event handler for when the Checkbox is clicked (to change its toggle state).
// TODO change to OnCheckChanged or OnToggled?
OnClicked(func(d Doer))
// Text and SetText are Requests that get and set the Checkbox's label text.
Text() *Request
SetText(text string) *Request
// Checked and SetChecked are Requests that get and set the Checkbox's check state.
Checked() *Request
SetChecked(checked bool) *Request
}Checkbox is a clickable box that indicates some Boolean value.
func NewCheckbox(text string) CheckboxNewCheckbox creates a new Checkbox with the given label text. The Checkbox will be initially unchecked.
type Combobox interface {
Control
// Append, InsertBefore, and Delete are Requests that change the Combobox's list.
// InsertBefore and Delete panic if the index passed in is out of range.
Append(item string) *Request
InsertBefore(item string, before int) *Request
Delete(index int) *Request
// SelectedIndex and SelectedText are Requests that return the current Combobox selection, either as the index into the list or as its label.
// SelectedIndex returns -1 and SelectedText returns an empty string if no selection has been made.
// If the Combobox is editable, SelectedIndex returns -1 if the user has entered their own string, in which case SelectedText will return that string.
SelectedIndex() *Request
SelectedText() *Request
// SelectIndex is a Request that selects an index from the list.
// SelectIndex panics if the given index is out of range.
// [TODO SelectText or SetCustomText]
SelectIndex(index int) *Request
// Len is a Request that returns the number of items in the list.
// At is a Request that returns a given item's text.
// At panics if the given index is out of range.
Len() *Request
At(index int) *Request
}Combobox is a drop-down list from which one item can be selected. Each item of a Combobox is a text string. The Combobox can optionally be editable, in which case the user can type in a selection not in the list. [TODO If an item is selected in an editable Combobox, the edit field will be changed ot reflect the selection.]
func NewCombobox(items ...string) ComboboxNewCombobox creates a new Combobox with the given items. The Checkbox will have nothing selected initially.
func NewEditableCombobox(items ...string) ComboboxNewEditableCombobox creates a new editable Combobox with the given items. The Combobox will have nothing selected initially and no custom text initially.
type Control interface {
}Control represents a control. All Controls have event handlers that take a single argument (the Doer active during the event) and return nothing.
type Doer chan *RequestDoer is a channel that takes Requests returned by the various functions and methods of package ui. There are two main Doers: ui.Do, which is for outside event handlers, and the Doer passed into an event handler function. You should not create or use your own Doers; these are meaningless.
type Request struct {
}Request represents a request issued to the package. These are returned by the various functions and methods of package ui and are sent to either Do or to the currently active event handler channel. There are also several convenience functions that perfrom common operations with requests.
func (r *Request) Response() <-chan interface{}Response returns a channel which is pulsed exactly once, then immeidately closed, with the response from the function that issued the request. If the function does not return a value, this value will be the zero value of struct{}. Otherwise, the type of this value depends on the function that created the Request.