Initial commit
This commit is contained in:
62
koptilnya/gui/elements/checkbox.txt
Normal file
62
koptilnya/gui/elements/checkbox.txt
Normal file
@@ -0,0 +1,62 @@
|
||||
--@include element.txt
|
||||
--@include label.txt
|
||||
--@include ../utils.txt
|
||||
|
||||
require("element.txt")
|
||||
require("label.txt")
|
||||
require("../utils.txt")
|
||||
|
||||
ECheckbox = class("ECheckbox", ELabel)
|
||||
|
||||
accessorFunc(ECheckbox, "_textColor", "TextColor", Color(255, 255, 255))
|
||||
accessorFunc(ECheckbox, "_hoveredColor", "HoveredColor", Color(66, 66, 66))
|
||||
accessorFunc(ECheckbox, "_hoveredTextColor", "HoveredTextColor", Color(255, 255, 255))
|
||||
accessorFunc(ECheckbox, "_disabledColor", "DisabledColor", Color(32, 32, 32))
|
||||
accessorFunc(ECheckbox, "_disabledTextColor", "DisabledTextColor", Color(80, 80, 80))
|
||||
accessorFunc(ECheckbox, "_indent", "Indent", 8)
|
||||
|
||||
function ECheckbox:initialize()
|
||||
ELabel.initialize(self)
|
||||
|
||||
self._checked = false
|
||||
|
||||
self:setText("Checkbox")
|
||||
self:setSize(200, 16)
|
||||
end
|
||||
|
||||
function ECheckbox:setChecked(state)
|
||||
self._checked = state
|
||||
|
||||
self:onChange()
|
||||
end
|
||||
|
||||
function ECheckbox:isChecked()
|
||||
return self._checked
|
||||
end
|
||||
|
||||
function ECheckbox:paint()
|
||||
local x, y = self:getAbsolutePos()
|
||||
local w, h = self:getSize()
|
||||
local textW, textH = self:getTextSize()
|
||||
--[[
|
||||
local bgColor, textColor
|
||||
if self:isEnabled() then
|
||||
bgColor = self:isHovered() and self:getHoveredColor() or self:getColor()
|
||||
textColor = self:isHovered() and self:getHoveredTextColor() or self:getTextColor()
|
||||
else
|
||||
bgColor = self:getDisabledColor()
|
||||
textColor = self:getDisabledTextColor()
|
||||
end
|
||||
]]
|
||||
|
||||
render.setColor(Color(209, 209, 209))
|
||||
render.drawCircle(x, y, h / 2)
|
||||
--render.drawRectOutline(x, y, h, h, -8)
|
||||
|
||||
--render.setColor(Color(209, 209, 209, 0))
|
||||
--render.drawRectFast(x, y, h - 2, h - 2)
|
||||
|
||||
render.setFont(self:getFont())
|
||||
render.setColor(Color(255, 255, 255))
|
||||
render.drawSimpleText(x + h + self:getIndent(), y + h / 2 - textH / 2, self:getText())
|
||||
end
|
||||
Reference in New Issue
Block a user