New elements; Fixes

This commit is contained in:
Nikita Kruglickiy
2021-01-14 12:48:30 +06:00
parent eaf0a90173
commit d4dd889bb5
9 changed files with 231 additions and 100 deletions

View File

@@ -1,62 +1,58 @@
--@include element.txt
--@include label.txt
--@include /koptilnya/libs/utils.txt
require("element.txt")
require("label.txt")
require("/koptilnya/libs/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)
ECheckbox = class("ECheckbox", Element)
function ECheckbox:initialize()
ELabel.initialize(self)
Element.initialize(self)
self._checked = false
self:setText("Checkbox")
self:setSize(200, 16)
self:setSize(16, 16)
self:setColorScheme({
border = {
Color(209, 209, 209),
hover = Color(255, 255, 255),
disabled = Color(130, 130, 130)
},
mark = {
Color(81, 92, 107),
disabled = Color(40, 46, 53)
}
})
end
function ECheckbox:setChecked(state)
self._checked = state
self:onChange()
self:onChange(state)
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()
function ECheckbox:toggle()
self:setChecked(!self:isChecked())
end
function ECheckbox:onMousePressed(x, y, key, keyName)
if keyName == "MOUSE1" then
self:toggle()
end
]]
end
function ECheckbox:paint(x, y, w, h)
render.setColor(self:isChecked() and self:getColorFromScheme("mark") or Color(0, 0, 0, 0))
render.drawRectFast(x, y, h, h)
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())
render.setColor(self:getColorFromScheme("border"))
render.drawRectOutline(x, y, h, h, 1)
render.drawRectOutline(x + 1, y + 1, h - 2, h - 2, 1)
end
function ECheckbox:onChange(state)
end