NkGenie - checkbox

From Riftui Wiki

Jump to: navigation, search

This widget is used for defining a checkbox widget. This is a complete custom widget individually supplied by nkGenie. It will create the checkbox ui element and place a label in front or behind the checkbox element. It is not possible to create a checkbox without label. You could set the label width to 0 though.

UI.CreateFrame('nkExtCheckbox', name, parent, {})

Contents

Supported parameters

Due to the nature of the checkbox widget you cannot change it as dynamically as other widgets after creation. The following parameters are supported for UI:CreateFrame(). The method :update() only supports the parameter 'text' and will then also acceppt the parameter 'labelwidth'.

Parameter Description
checked The initial checked state of the widget (true or false)
labelwidth The width of the label of the checkbox. The total width of the widgt is: labelwidth + fontsize + 7
fontsize The fontsize used for the label of the checkbox
labelinfront Defines if the label is shown in front or behind the checkbox element (true = front, false = behind)
text Text text of the label
color Specifies the color of the widget. See below.
anchors The position of the mask widget. See How to position widgets
func An optional function which is automatically called if the checked status of the widget changes. See below.

Supported Methods

getElement()

This method retrieves the underlying Rift UI element.

toggle(flag)

This method changes the checked state of the checkbox (true = checked, false = not checked). The status change function will not be called.

Other supported methods

Parameter Description
getChecked() Returns the checked state of the widget
getLabel(object) Returns the text of the label
SetVisible() Sets the visibility state of the widget (true / false)
IsVisible() Returns the visibility status of the widget. Actually inconsistent and will eventually be changed to GetVisible()

Calling a function on status change

If you provide the paramter func at creation time the widget will call this function if the checked state of the widget changes (e.g. user clicks widget). The library will call the supplied function and transfer the widget itself as parameter. You can then call the method :getChecked() on the supplied widget to find out if it's new state is checked or not. For example:

local myFunc = function (checkbox) 
 if checkbox:getChecked() == true print ('checked') else print ('not checked) end
end
 
local checkbox = UI.CreateFrame('nkExtCheckbox', 'myCheckbox', UI.Parent, { func = myFunc, checked = false, labelwidth = 75, fontsize = 12, labelinfront = true, text = 'my checkbox:', color = { body = '000000', border = 'FFFFFF' }}, 
anchors = {{ from = 'CENTER', object = UI.Parent, to = 'CENTER' }} })

Setting the color of the checkbox

You will have to supply a color LUA table with at least the two parameters 'body' and 'border'. For example: color = { body = '0000000', border = 'FFFFFF' }. The border color will also be used for the box indicating the checked state of the widget.

The label of the checbkox will automatically use the border color unless you specificy the option color parameter 'label'. For example. color = { body = '0000000', border = '555555', label = 'FFFFFF' }

Personal tools
Namespaces
Variants
Actions
Menu
Wiki
Toolbox