#24 - add docs for Radio

This commit is contained in:
Vladimir Markelov 2015-10-29 10:36:18 -07:00
parent 4751c7f9a8
commit ab4b6c0259
6 changed files with 29 additions and 14 deletions

View File

@ -23,7 +23,7 @@ type Button struct {
NewButton creates a new Button.
view - is a View that manages the control
parent - is container that keeps the control. The same View can be a view and a parent at the same time.
width and heith - are minimal size of the control.
width and heigth - are minimal size of the control.
title - button title.
scale - the way of scaling the control when the parent is resized. Use DoNotScale constant if the
control should keep its original size.

View File

@ -19,7 +19,7 @@ type CheckBox struct {
NewCheckBox creates a new CheckBox control.
view - is a View that manages the control.
parent - is container that keeps the control. The same View can be a view and a parent at the same time.
width and heith - are minimal size of the control.
width - is minimal width of the control.
title - button title.
scale - the way of scaling the control when the parent is resized. Use DoNotScale constant if the
control should keep its original size.

View File

@ -17,7 +17,7 @@ type Frame struct {
NewFrame creates a new frame.
view - is a View that manages the control
parent - is container that keeps the control. The same View can be a view and a parent at the same time.
width and heith - are minimal size of the control.
width and heigth - are minimal size of the control.
bs - type of border: no border, single or double.
scale - the way of scaling the control when the parent is resized. Use DoNotScale constant if the
control should keep its original size.

View File

@ -32,7 +32,7 @@ type ListBox struct {
NewListBox creates a new frame.
view - is a View that manages the control
parent - is container that keeps the control. The same View can be a view and a parent at the same time.
width and heith - are minimal size of the control.
width and heigth - are minimal size of the control.
scale - the way of scaling the control when the parent is resized. Use DoNotScale constant if the
control should keep its original size.
*/

View File

@ -24,7 +24,7 @@ type ProgressBar struct {
NewProgressBar creates a new ProgressBar.
view - is a View that manages the control
parent - is container that keeps the control. The same View can be a view and a parent at the same time.
width and heith - are minimal size of the control.
width and heigth - are minimal size of the control.
scale - the way of scaling the control when the parent is resized. Use DoNotScale constant if the
control should keep its original size.
*/

View File

@ -6,11 +6,8 @@ import (
)
/*
CheckBox control. It can be two-state one(on and off) - it is default mode - or tree-state.
State values are 0=off, 1=on, 2=third state
Minimal width of a checkbox cannot be less than 3
Own methods:
Get3State, Set3State, GetState, SetState
Radio button control. Unite a few radios in one radio group to
make a user select one of available choices.
*/
type Radio struct {
ControlBase
@ -18,6 +15,15 @@ type Radio struct {
selected bool
}
/*
NewRadio creates a new radio button.
view - is a View that manages the control
parent - is container that keeps the control. The same View can be a view and a parent at the same time.
width - is minimal width of the control.
title - radio title.
scale - the way of scaling the control when the parent is resized. Use DoNotScale constant if the
control should keep its original size.
*/
func NewRadio(view View, parent Control, width int, title string, scale int) *Radio {
c := new(Radio)
@ -28,7 +34,7 @@ func NewRadio(view View, parent Control, width int, title string, scale int) *Ra
c.view = view
c.parent = parent
c.SetSize(width, 1) // TODO: only one line checkboxes are supported at that moment
c.SetSize(width, 1) // TODO: only one line heigth is supported at that moment
c.SetConstraints(width, 1)
c.SetTitle(title)
c.SetTabStop(true)
@ -40,6 +46,7 @@ func NewRadio(view View, parent Control, width int, title string, scale int) *Ra
return c
}
// Repaint draws the control on its View surface
func (c *Radio) Repaint() {
x, y := c.Pos()
w, h := c.Size()
@ -78,6 +85,13 @@ func (c *Radio) Repaint() {
canvas.PutText(x+4+shift, y, text, fg, bg)
}
/*
ProcessEvent processes all events come from the control parent. If a control
processes an event it should return true. If the method returns false it means
that the control do not want or cannot process the event and the caller sends
the event to the control parent.
The control processes only space button and mouse clicks to make control selected. Deselecting control is not possible: one has to click another radio of the radio group to deselect this button
*/
func (c *Radio) ProcessEvent(event Event) bool {
if (!c.Active() && event.Type == EventKey) || !c.Enabled() {
return false
@ -95,17 +109,18 @@ func (c *Radio) ProcessEvent(event Event) bool {
return false
}
// Sets the current state of CheckBox
// Value must be 0/1 if 3State is off
// or 0/1/2 if 3State is on
// SetSelected makes the button selected. One should not use
// the method directly, it is for RadioGroup control
func (c *Radio) SetSelected(val bool) {
c.selected = val
}
// Selected returns if the radio is selected
func (c *Radio) Selected() bool {
return c.selected
}
// SetGroup sets the radio group to which the radio belongs
func (c *Radio) SetGroup(group *RadioGroup) {
c.group = group
}