andlabs-ui/redo/basicctrls.go

92 lines
2.7 KiB
Go
Raw Normal View History

2014-07-07 08:43:01 -05:00
// 7 july 2014
package ui
// Button is a clickable button that performs some task.
type Button interface {
Control
// OnClicked sets the event handler for when the Button is clicked.
OnClicked(func())
2014-07-07 08:43:01 -05:00
// Text and SetText get and set the Button's label text.
Text() string
SetText(text string)
2014-07-07 08:43:01 -05:00
}
// NewButton creates a new Button with the given label text.
func NewButton(text string) Button {
2014-07-07 08:43:01 -05:00
return newButton(text)
}
// Checkbox is a clickable box that indicates some Boolean value.
type Checkbox interface {
Control
// OnClicked sets the event handler for when the Checkbox is clicked (to change its toggle state).
// TODO change to OnToggled() or OnChecked()?
OnClicked(func())
// Text and SetText get and set the Checkbox's label text.
Text() string
SetText(text string)
// Checked and SetChecked get and set the Checkbox's check state.
Checked() bool
SetChecked(checked bool)
}
// NewCheckbox creates a new Checkbox with the given label text.
// The Checkbox will be initially unchecked.
func NewCheckbox(text string) Checkbox {
return newCheckbox(text)
}
2014-07-26 05:43:59 -05:00
// TextField is a Control in which the user can enter a single line of text.
2014-08-01 20:49:44 -05:00
// TODO rename private implementations from textField to textfield
2014-07-26 05:43:59 -05:00
type TextField interface {
Control
// TODO figure out what events are appropriate
2014-07-26 05:43:59 -05:00
// Text and SetText are Requests that get and set the TextField's text.
Text() string
SetText(text string)
}
2014-07-26 05:43:59 -05:00
// NewTextField creates a new TextField.
func NewTextField() TextField {
return newTextField()
}
// NewPasswordField creates a new TextField for entering passwords; that is, it hides the text being entered.
func NewPasswordField() TextField {
return newPasswordField()
}
// Label is a Control that shows a static line of text.
// Label shows one line of text; any text that does not fit is truncated.
// A Label can either have smart vertical alignment relative to the control to its right or just be vertically aligned to the top (standalone).
// The effect of placing a non-standalone Label in any context other than to the immediate left of a Control (TODO currently basic Control only? recheck Stack/Grid code) is undefined.
type Label interface {
Control
// Text and SetText get and set the Label's text.
Text() string
SetText(text string)
}
// NewLabel creates a new Label with the given text.
// The Label will smartly vertically position itself relative to the control to its immediate right.
// TODO Grids on GTK+ will not respect this unless SetFilling()
func NewLabel(text string) Label {
return newLabel(text)
}
// NewStandaloneLabel creates a new Label with the given text.
// The Label will be vertically positioned at the top of its allocated space.
func NewStandaloneLabel(text string) Label {
return newStandaloneLabel(text)
}