69 lines
1.6 KiB
Plaintext
69 lines
1.6 KiB
Plaintext
--@include element.txt
|
|
--@include checkbox.txt
|
|
--@include label.txt
|
|
--@include /koptilnya/libs/utils.txt
|
|
|
|
require("element.txt")
|
|
require("checkbox.txt")
|
|
require("label.txt")
|
|
require("/koptilnya/libs/utils.txt")
|
|
|
|
ELabeledCheckbox = class("ELabeledCheckbox", Element)
|
|
|
|
accessorFunc(ELabeledCheckbox, "_indent", "Indent", 8)
|
|
|
|
function ELabeledCheckbox:initialize()
|
|
Element.initialize(self)
|
|
|
|
self._checked = false
|
|
|
|
self.checkbox = ECheckbox:new()
|
|
self.checkbox.onChange = function(_, state) self:onChange(state) end
|
|
self:addChild(self.checkbox)
|
|
|
|
self.label = ELabel:new()
|
|
self.label.onMousePressed = function(_, x, y, key, keyName)
|
|
if keyName == "MOUSE1" then
|
|
self:toggle()
|
|
end
|
|
end
|
|
self:addChild(self.label)
|
|
|
|
self:setText("Checkbox")
|
|
end
|
|
|
|
function ELabeledCheckbox:setChecked(state)
|
|
self.checkbox:setChecked(state)
|
|
end
|
|
|
|
function ELabeledCheckbox:isChecked()
|
|
return self.checkbox:isChecked()
|
|
end
|
|
|
|
function ELabeledCheckbox:toggle()
|
|
self.checkbox:toggle()
|
|
end
|
|
|
|
function ELabeledCheckbox:setText(text)
|
|
self.label:setText(text)
|
|
self:sizeToContents()
|
|
end
|
|
|
|
function ELabeledCheckbox:setFont(font)
|
|
self.label:setFont(font)
|
|
self:sizeToContents()
|
|
end
|
|
|
|
function ELabeledCheckbox:sizeToContents()
|
|
self:performLayout(self:getSize())
|
|
self:setWidth(self.label:getX() + self.label:getWidth())
|
|
self:setHeight(math.max(self.checkbox:getHeight(), self.label:getHeight()))
|
|
end
|
|
|
|
function ELabeledCheckbox:performLayout(w, h)
|
|
self.label:sizeToContents()
|
|
self.label:setX(self.checkbox:getWidth() + self:getIndent())
|
|
end
|
|
|
|
function ELabeledCheckbox:onChange(state)
|
|
end |