Checkbox

Checkbox without content

Checkbox with TextView as a content

Is an input element that allows to select one item

Create from source

func NewCheckbox(session Session, params Params) Checkbox

Create new checkbox object and return its interface

Create from resource

Checkbox {
    id = checkbox,
    content = TextView {
        id = textView,
        text = "Text",
    },
}

Interface description

Inherit methods, properties and events from ViewsContainer

Properties

"checkbox-horizontal-align"

Horizontal alignment of checkbox inside the checkbox container

Constant: CheckboxHorizontalAlign

Types: int, string

Values

int string Description
0(LeftAlign) "left" Checkbox on the left edge, content on the right
1(RightAlign) "right" Checkbox on the right edge, content on the left
2(CenterAlign) "center" Center horizontally. Content below or above

"checkbox-vertical-align"

Vertical alignment of checkbox inside the checkbox container

Constant: CheckboxVerticalAlign

Types: int, string

Values

int string Description
0(TopAlign) "top" Checkbox on the top, content on the bottom
1(BottomAlign) "bottom" Checkbox on the bottom, content on the top
2(CenterAlign) "center" Checkbox on the top, content on the bottom

"checked"

Current state of the checkbox

Constant: Checked

Types: bool, int, string

Values

bool int string Description
true 1 "true", "yes", "on", "1" Checkbox is checked
false 0 "false", "no", "off", "0" Checkbox is unchecked

"content"

An array of child views

Constant: Content

Types: View, []View, string, []string, []any containing elements of View or string

Internal type is []View, other types converted to it during assignment

Conversion rules

View - converted to []View containing one element

[]View - nil-elements are prohibited, if the array contains nil, then the property will not be set, and the Set function will return false and an error message will be written to the log

string - if the string is a text representation of the View, then the corresponding view is created, otherwise a TextView is created, to which the given string is passed as a text. Then a []View is created containing the resulting view

[]string - each element of an array is converted to View as described above

[]any - this array must contain only View and a string. Each string element is converted to a view as described above. If array contains invalid values, the "content" property will not be set, and the Set function will return false and an error message will be written to the log

Examples

Checkbox {
    content = "Some text",
}
checkbox := rui.NewCheckbox(session, rui.Params{
    rui.Content: "Some text",
})
checkbox := rui.NewCheckbox(session, rui.Params{
    rui.Content: []string {
        "Line1 text",
        "Line2 text",
    },
})
checkbox := rui.NewCheckbox(session, rui.Params{
    rui.Content: rui.NewTextView(session, rui.Params{
        rui.Text:         "Some text",
        rui.NotTranslate: true,
    }),
})
checkbox := rui.NewCheckbox(session, rui.Params{
    rui.Content: []rui.View{
        rui.NewTextView(session, rui.Params{
            rui.Text:         "Line1 text",
            rui.NotTranslate: true,
        }),
        rui.NewTextView(session, rui.Params{
            rui.Text:         "Line2 text",
            rui.NotTranslate: true,
        }),
    },
})
checkbox := rui.NewCheckbox(session, rui.Params{
    rui.Content: "TextView{ text = \"Some text\",}",
})

"horizontal-align"

Sets the horizontal alignment of the content inside a block element

Constant: HorizontalAlign

Types: int, string

Values

int string Description
0(LeftAlign) "left" Content aligned to left side of the content area
1(RightAlign) "right" Content aligned to right side of the content area
2(CenterAlign) "center" Content aligned in the center of the content area
3(StretchAlign) "stretch" Content relaxed to fill all content area

"vertical-align"

Sets the vertical alignment of the content inside a block element

Constant: VerticalAlign

Types: int, string

Values

int string Description
0(TopAlign) "top" Content aligned to top side of the content area
1(BottomAlign) "bottom" Content aligned to bottom side of the content area
2(CenterAlign) "center" Content aligned in the center of the content area
3(StretchAlign) "stretch" Content relaxed to fill all content area

Events

"checkbox-event"

Event occurs when the checkbox becomes checked/unchecked

Constant: CheckboxChangedEvent

General listener format:

func(checkbox rui.Checkbox, checked bool)

where: * checkbox - Interface of a checkbox which generated this event * checked - Checkbox state

Allowed listener formats:

func(checkbox rui.Checkbox)

func(checked bool)

func()

func CheckboxByID(rootView View, id string) Checkbox

CheckboxByID return a Checkbox with id equal to the argument of the function or nil if there is no such View or View is not Checkbox

func GetCheckboxChangedListeners(view View, subviewID ...string) []func(Checkbox, bool)

Returns the CheckboxChangedListener list of an Checkbox subview. If there are no listeners then the empty list is returned. If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.

func GetCheckboxHorizontalAlign(view View, subviewID ...string) int

Return the vertical align of a Checkbox subview: LeftAlign (0), RightAlign (1), CenterAlign (2). If the second argument (subviewID) is not specified or is an empty string then a left position of the first argument (view) is returned

func GetCheckboxVerticalAlign(view View, subviewID ...string) int

Return the vertical align of a Checkbox subview: TopAlign (0), BottomAlign (1), CenterAlign (2). If the second argument (subviewID) is not specified or is an empty string then a left position of the first argument (view) is returned

func IsCheckboxChecked(view View, subviewID ...string) bool

Returns true if the Checkbox is checked, false otherwise. If the second argument (subviewID) is not specified or is an empty string then a value from the first argument (view) is returned.