UI docs
This commit is contained in:
@@ -21,21 +21,20 @@ UI.Checkbox.defaults = {
|
||||
mouse_click = 'checkbox_toggle',
|
||||
}
|
||||
}
|
||||
UI.Checkbox.inherits = {
|
||||
labelBackgroundColor = 'backgroundColor',
|
||||
}
|
||||
function UI.Checkbox:postInit()
|
||||
self.width = self.label and #self.label + 4 or 3
|
||||
end
|
||||
|
||||
function UI.Checkbox:draw()
|
||||
local bg = self.backgroundColor
|
||||
if self.focused then
|
||||
bg = self.backgroundFocusColor
|
||||
end
|
||||
if type(self.value) == 'string' then
|
||||
self.value = nil -- TODO: fix form
|
||||
end
|
||||
local text = string.format('[%s]', not self.value and ' ' or self.checkedIndicator)
|
||||
local bg = self.focused and self.backgroundFocusColor or self.backgroundColor
|
||||
local x = 1
|
||||
if self.label then
|
||||
self:write(1, 1, self.label)
|
||||
self:write(1, 1, self.label, self.labelBackgroundColor)
|
||||
x = #self.label + 2
|
||||
end
|
||||
self:write(x, 1, text, bg)
|
||||
self:write(x, 1, self.leftMarker, self.backgroundColor, self.textColor)
|
||||
self:write(x + 1, 1, not self.value and ' ' or self.checkedIndicator, bg)
|
||||
self:write(x + 2, 1, self.rightMarker, self.backgroundColor, self.textColor)
|
||||
@@ -46,11 +45,12 @@ function UI.Checkbox:focus()
|
||||
end
|
||||
|
||||
function UI.Checkbox:setValue(v)
|
||||
self.value = v
|
||||
self.value = not not v
|
||||
end
|
||||
|
||||
function UI.Checkbox:reset()
|
||||
self.value = false
|
||||
self:draw()
|
||||
end
|
||||
|
||||
function UI.Checkbox:eventHandler(event)
|
||||
@@ -63,7 +63,13 @@ function UI.Checkbox:eventHandler(event)
|
||||
end
|
||||
|
||||
function UI.Checkbox.example()
|
||||
return UI.Checkbox {
|
||||
x = 2, y = 2,
|
||||
return UI.Window {
|
||||
ex1 = UI.Checkbox {
|
||||
label = 'test',
|
||||
x = 2, y = 2,
|
||||
},
|
||||
ex2 = UI.Checkbox {
|
||||
x = 2, y = 4,
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user