Files
Basalt2/docs/references/elements/Label.md
2025-02-16 14:12:49 +00:00

1.1 KiB

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