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
-- Simple text widget
function TextWidget:new(menuName, font, label, position)
function TextWidget:new(menuName, font, label, position, padding)
TextWidget.super.new(self, menuName)
self.font = font
self.labels = {}
self.padding = padding or 0
-- We add the first label
local position = position or "center"
@ -59,15 +60,14 @@ function TextWidget:drawCanvas()
local w, h
local font = self.assets:getFont(self.font)
h = math.floor(self.height / 2) - (font:getHeight() / 2)
for _, complexLabel in pairs(self.labels) do
if (complexLabel.position == "center") then
w = math.floor(self.width / 2)
elseif (complexLabel.position == "left") then
w = 0
w = self.padding
elseif (complexLabel.position == "right") then
w = math.floor(self.width)
w = math.floor(self.width - self.padding)
end
font:draw(complexLabel.label, w, h, -1, complexLabel.position)
end