feat(textwidget): extend API
This commit is contained in:
parent
92c10440a1
commit
772becc1a8
1 changed files with 11 additions and 3 deletions
|
@ -52,22 +52,30 @@ function TextWidget:setSelectedColor(r, g, b)
|
||||||
self.selectedColor.b = b
|
self.selectedColor.b = b
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function TextWidget:getFont()
|
||||||
|
return self.assets:getFont(self.font)
|
||||||
|
end
|
||||||
|
|
||||||
function TextWidget:getSelectedColor()
|
function TextWidget:getSelectedColor()
|
||||||
return self.selectedColor.r, self.selectedColor.g, self.selectedColor.b
|
return self.selectedColor.r, self.selectedColor.g, self.selectedColor.b
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function TextWidget:getPadding()
|
||||||
|
return self.padding
|
||||||
|
end
|
||||||
|
|
||||||
function TextWidget:drawCanvas()
|
function TextWidget:drawCanvas()
|
||||||
local w, h
|
local w, h
|
||||||
local font = self.assets:getFont(self.font)
|
local font = self:getFont()
|
||||||
h = math.floor(self.height / 2) - (font:getHeight() / 2)
|
h = math.floor(self.height / 2) - (font:getHeight() / 2)
|
||||||
|
|
||||||
for _, complexLabel in pairs(self.labels) do
|
for _, complexLabel in pairs(self.labels) do
|
||||||
if (complexLabel.position == "center") then
|
if (complexLabel.position == "center") then
|
||||||
w = math.floor(self.width / 2)
|
w = math.floor(self.width / 2)
|
||||||
elseif (complexLabel.position == "left") then
|
elseif (complexLabel.position == "left") then
|
||||||
w = self.padding
|
w = self:getPadding()
|
||||||
elseif (complexLabel.position == "right") then
|
elseif (complexLabel.position == "right") then
|
||||||
w = math.floor(self.width - self.padding)
|
w = math.floor(self.width - self:getPadding())
|
||||||
end
|
end
|
||||||
font:draw(complexLabel.label, w, h, -1, complexLabel.position)
|
font:draw(complexLabel.label, w, h, -1, complexLabel.position)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue