Canvas test
This commit is contained in:
@@ -109,6 +109,27 @@ function BaseFrame:textBg(x, y, text, bg)
|
||||
self._render:textBg(x, y, text, bg)
|
||||
end
|
||||
|
||||
--- @shortDescription Renders a text with a background color to the render Object
|
||||
--- @param x number The x position to render to
|
||||
--- @param y number The y position to render to
|
||||
--- @param text string The text to render
|
||||
--- @param bg colors The background color
|
||||
--- @protected
|
||||
function BaseFrame:drawText(x, y, text)
|
||||
if x < 1 then text = string.sub(text, 1 - x); x = 1 end
|
||||
self._render:text(x, y, text)
|
||||
end
|
||||
|
||||
function BaseFrame:drawFg(x, y, fg)
|
||||
if x < 1 then fg = string.sub(fg, 1 - x); x = 1 end
|
||||
self._render:fg(x, y, fg)
|
||||
end
|
||||
|
||||
function BaseFrame:drawBg(x, y, bg)
|
||||
if x < 1 then bg = string.sub(bg, 1 - x); x = 1 end
|
||||
self._render:bg(x, y, bg)
|
||||
end
|
||||
|
||||
--- @shortDescription Renders a text with a foreground and background color to the render Object
|
||||
--- @param x number The x position to render to
|
||||
--- @param y number The y position to render to
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
local elementManager = require("elementManager")
|
||||
local errorManager = require("errorManager")
|
||||
local VisualElement = elementManager.getElement("VisualElement")
|
||||
local expect = require("libraries/expect")
|
||||
local split = require("libraries/utils").split
|
||||
@@ -576,6 +577,46 @@ function Container:textBg(x, y, text, bg)
|
||||
return self
|
||||
end
|
||||
|
||||
function Container:drawText(x, y, text)
|
||||
local w, h = self.get("width"), self.get("height")
|
||||
|
||||
if y < 1 or y > h then return self end
|
||||
|
||||
local textStart = x < 1 and (2 - x) or 1
|
||||
local textLen = math.min(#text - textStart + 1, w - math.max(1, x) + 1)
|
||||
|
||||
if textLen <= 0 then return self end
|
||||
|
||||
VisualElement.drawText(self, math.max(1, x), math.max(1, y), text:sub(textStart, textStart + textLen - 1))
|
||||
return self
|
||||
end
|
||||
|
||||
function Container:drawFg(x, y, fg)
|
||||
local w, h = self.get("width"), self.get("height")
|
||||
|
||||
if y < 1 or y > h then return self end
|
||||
|
||||
local textStart = x < 1 and (2 - x) or 1
|
||||
local textLen = math.min(#fg - textStart + 1, w - math.max(1, x) + 1)
|
||||
if textLen <= 0 then return self end
|
||||
|
||||
VisualElement.drawFg(self, math.max(1, x), math.max(1, y), fg:sub(textStart, textStart + textLen - 1))
|
||||
return self
|
||||
end
|
||||
|
||||
function Container:drawBg(x, y, bg)
|
||||
local w, h = self.get("width"), self.get("height")
|
||||
|
||||
if y < 1 or y > h then return self end
|
||||
|
||||
local textStart = x < 1 and (2 - x) or 1
|
||||
local textLen = math.min(#bg - textStart + 1, w - math.max(1, x) + 1)
|
||||
if textLen <= 0 then return self end
|
||||
|
||||
VisualElement.drawBg(self, math.max(1, x), math.max(1, y), bg:sub(textStart, textStart + textLen - 1))
|
||||
return self
|
||||
end
|
||||
|
||||
--- @shortDescription Draws a line of text and fg and bg as colors
|
||||
--- @param x number The x position to draw the text
|
||||
--- @param y number The y position to draw the text
|
||||
@@ -618,13 +659,15 @@ function Container:render()
|
||||
end
|
||||
for _, child in ipairs(self.get("visibleChildren")) do
|
||||
if child == self then
|
||||
self.basalt.LOGGER.error("CIRCULAR REFERENCE DETECTED!")
|
||||
errorManager.error("CIRCULAR REFERENCE DETECTED!")
|
||||
return
|
||||
end
|
||||
child:render()
|
||||
child:postRender()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--- @private
|
||||
function Container:destroy()
|
||||
for _, child in ipairs(self._values.children) do
|
||||
|
||||
@@ -168,6 +168,27 @@ function VisualElement:textBg(x, y, text, bg)
|
||||
self.parent:textBg(x, y, text, bg)
|
||||
end
|
||||
|
||||
function VisualElement:drawText(x, y, text)
|
||||
local xElement, yElement = self:calculatePosition()
|
||||
x = x + xElement - 1
|
||||
y = y + yElement - 1
|
||||
self.parent:drawText(x, y, text)
|
||||
end
|
||||
|
||||
function VisualElement:drawFg(x, y, fg)
|
||||
local xElement, yElement = self:calculatePosition()
|
||||
x = x + xElement - 1
|
||||
y = y + yElement - 1
|
||||
self.parent:drawFg(x, y, fg)
|
||||
end
|
||||
|
||||
function VisualElement:drawBg(x, y, bg)
|
||||
local xElement, yElement = self:calculatePosition()
|
||||
x = x + xElement - 1
|
||||
y = y + yElement - 1
|
||||
self.parent:drawBg(x, y, bg)
|
||||
end
|
||||
|
||||
--- @shortDescription Draws text with both colors
|
||||
--- @param x number The x position to draw
|
||||
--- @param y number The y position to draw
|
||||
@@ -440,4 +461,9 @@ function VisualElement:render()
|
||||
self:multiBlit(1, 1, width, height, " ", tHex[self.get("foreground")], tHex[self.get("background")])
|
||||
end
|
||||
|
||||
--- @shortDescription Post-rendering function for the element
|
||||
--- @protected
|
||||
function VisualElement:postRender()
|
||||
end
|
||||
|
||||
return VisualElement
|
||||
Reference in New Issue
Block a user