Files
Basalt2/src/elements/Label.lua
Robert Jelic cc7b2de51a Update
Lots of fixes and improvements
2025-02-16 14:33:07 +01:00

37 lines
1.1 KiB
Lua

local elementManager = require("elementManager")
local VisualElement = elementManager.getElement("VisualElement")
---@class Label : VisualElement
local Label = setmetatable({}, VisualElement)
Label.__index = Label
---@property text string Label Label text to be displayed
Label.defineProperty(Label, "text", {default = "Label", type = "string", setter = function(self, value)
if(type(value)=="function")then value = value() end
self.set("width", #value)
return value
end})
--- Creates a new Label instance
--- @return Label object The newly created Label instance
--- @usage local element = Label.new("myId", basalt)
function Label.new()
local self = setmetatable({}, Label):__init()
self.set("z", 3)
self.set("foreground", colors.black)
self.set("backgroundEnabled", false)
return self
end
function Label:init(props, basalt)
VisualElement.init(self, props, basalt)
self.set("type", "Label")
end
function Label:render()
VisualElement.render(self)
local text = self.get("text")
self:textFg(1, 1, text, self.get("foreground"))
end
return Label