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

@@ -8,37 +8,40 @@ require("/koptilnya/libs/utils.txt")
EButton = class("EButton", ELabel)
EButton:include(require("radius_mixin.txt"))
accessorFunc(EButton, "_textColor", "TextColor", Color(230, 230, 230))
accessorFunc(EButton, "_hoveredColor", "HoveredColor", Color(66, 66, 66))
accessorFunc(EButton, "_hoveredTextColor", "HoveredTextColor", Color(230, 230, 230))
accessorFunc(EButton, "_disabledColor", "DisabledColor", Color(32, 32, 32))
accessorFunc(EButton, "_disabledTextColor", "DisabledTextColor", Color(80, 80, 80))
function EButton:initialize()
ELabel.initialize(self)
self:setText("Button")
self:setColor(Color(46, 46, 46))
self:setSize(100, 32)
self:setRoundedCorners(true)
self:setRadius(5)
self:setColorScheme({
bg = {
Color(46, 46, 46),
hover = Color(66, 66, 66),
disabled = Color(32, 32, 32)
},
text = {
Color(230, 230, 230),
disabled = Color(80, 80, 80)
}
})
end
function EButton:paint()
local x, y = self:getAbsolutePos()
local w, h = self:getSize()
function EButton:onClick()
end
function EButton:onMousePressed(x, y, key, keyName)
if keyName == "MOUSE1" then
self:onClick()
end
end
function EButton:paint(x, y, w, h)
local textW, textH = self:getTextSize()
local rTL, rTR, rBR, rBL = self:getRoundedCorners()
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(bgColor)
render.setColor(self:getColorFromScheme("bg"))
if self:getRadius() > 0 and (rTL or rTR or rBR or rBL) then
render.drawRoundedBoxEx(self:getRadius(), x, y, w, h, rTL, rTR, rBL, rBR)
else
@@ -46,6 +49,6 @@ function EButton:paint()
end
render.setFont(self:getFont())
render.setColor(textColor)
render.setColor(self:getColorFromScheme("text"))
render.drawSimpleText(x + w / 2 - textW / 2, y + h / 2 - textH / 2, self:getText())
end