feat: add padding to text widgets

This commit is contained in:
Kazhnuz 2020-12-05 21:20:20 +01:00
parent 72829eb02a
commit 0f4b6daf73

View file

@ -26,10 +26,11 @@ local TextWidget = BaseWidget:extend()
-- TEXT WIDGET -- TEXT WIDGET
-- Simple text widget -- Simple text widget
function TextWidget:new(menuName, font, label, position) function TextWidget:new(menuName, font, label, position, padding)
TextWidget.super.new(self, menuName) TextWidget.super.new(self, menuName)
self.font = font self.font = font
self.labels = {} self.labels = {}
self.padding = padding or 0
-- We add the first label -- We add the first label
local position = position or "center" local position = position or "center"
@ -60,14 +61,13 @@ function TextWidget:drawCanvas()
local font = self.assets:getFont(self.font) local font = self.assets:getFont(self.font)
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 = 0 w = self.padding
elseif (complexLabel.position == "right") then elseif (complexLabel.position == "right") then
w = math.floor(self.width) w = math.floor(self.width - self.padding)
end end
font:draw(complexLabel.label, w, h, -1, complexLabel.position) font:draw(complexLabel.label, w, h, -1, complexLabel.position)
end end