added bigfonts api for labels

Added bigfonts to labels
just use :setFontSize(number) (1,2, 3 or 4)
This commit is contained in:
Robert Jelic
2022-05-29 16:22:28 +02:00
parent 1f97eeacd1
commit 7871d7205c
7 changed files with 4837 additions and 13 deletions

View File

@@ -4,12 +4,15 @@ local function Label(name)
local objectType = "Label"
base:setZIndex(3)
base.fgColor = colors.white
base.bgcolor = colors.black
local autoWidth = true
base:setValue("")
local textHorizontalAlign = "left"
local textVerticalAlign = "top"
local fontsize = 0
local object = {
getType = function(self)
@@ -31,6 +34,17 @@ local function Label(name)
return self
end;
setFontSize = function(self, size)
if(size>0)and(size<=4)then
fontsize = size-1 or 0
end
return self
end;
getFontSize = function(self)
return fontsize+1
end;
setSize = function(self, width, height)
base.setSize(self, width, height)
autoWidth = false
@@ -46,9 +60,27 @@ local function Label(name)
self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor)
self.parent:drawForegroundBox(obx, oby, self.width, self.height, self.fgColor)
self.parent:drawTextBox(obx, oby, self.width, self.height, " ")
for n = 1, self.height do
if (n == verticalAlign) then
self.parent:writeText(obx, oby + (n - 1), getTextHorizontalAlign(self:getValue(), self.width, textHorizontalAlign), self.bgColor, self.fgColor)
if(fontsize==0)then
for n = 1, self.height do
if (n == verticalAlign) then
self.parent:writeText(obx, oby + (n - 1), getTextHorizontalAlign(self:getValue(), self.width, textHorizontalAlign), self.bgColor, self.fgColor)
end
end
else
local tData = makeText(fontsize, self:getValue(), self.fgColor, self.bgColor)
for n = 1, self.height do
if (n == verticalAlign) then
local oX, oY = self.parent:getSize()
local cX, cY = #tData[1][1], #tData[1]
obx = obx or math.floor((oX - cX) / 2) + 1
oby = oby or math.floor((oY - cY) / 2) + 1
for i = 1, cY do
self.parent:setFG(obx, oby + i + n - 2, getTextHorizontalAlign(tData[2][i], self.width, textHorizontalAlign))
self.parent:setBG(obx, oby + i + n - 2, getTextHorizontalAlign(tData[3][i], self.width, textHorizontalAlign, tHex[self.bgColor]))
self.parent:setText(obx, oby + i + n - 2, getTextHorizontalAlign(tData[1][i], self.width, textHorizontalAlign))
end
end
end
end
end

View File

@@ -4,7 +4,7 @@ local function Example(name) -- you can call this function how you want, doesn't
-- here you could set some default values, but its not necessary, it doesn't matter if you call the functions or change the values directly, maybe i should change that
--i guess its better if you call functions base:setBackground, base:setSize and so on.
base.width = 3
base.width = 12
base.height = 1
base.bgColor = colors.lightGray
base.fgColor = colors.gray
@@ -31,8 +31,8 @@ local function Example(name) -- you can call this function how you want, doesn't
if (base.draw(self)) then
if (self.parent ~= nil) then
local obx, oby = self:getAnchorPosition()
--self.parent:setBackground(obx, oby, self.width, self.height, self.bgColor) -- changes the background color of that object
--self.parent:setForeground(obx, oby, self.width, self.height, self.fgColor) -- changes the foreground (textcolor) color of that object
--self.parent:drawBackgroundbox(obx, oby, self.width, self.height, self.bgColor) -- changes the background color of that object
--self.parent:drawForegroundbox(obx, oby, self.width, self.height, self.fgColor) -- changes the foreground (textcolor) color of that object
--self.parent:writeText(obx, oby, "Some Text", self.bgColor, self.fgColor) -- writes something on the screen, also able to change its bgcolor and fgcolor
--the draw functions always gets called after something got visually changed. I am always redrawing the entire screen, but only if something has changed.