diff --git a/src/elements/List.lua b/src/elements/List.lua index f9c7d70..efbdf74 100644 --- a/src/elements/List.lua +++ b/src/elements/List.lua @@ -147,8 +147,8 @@ function List:mouse_click(button, x, y) self:fireEvent("mouse_click", button, x, y) self:fireEvent("select", adjustedIndex, item) self:updateRender() - return true end + return true end return false end diff --git a/src/elements/Switch.lua b/src/elements/Switch.lua new file mode 100644 index 0000000..b7df6a0 --- /dev/null +++ b/src/elements/Switch.lua @@ -0,0 +1,42 @@ +local elementManager = require("elementManager") +local VisualElement = elementManager.getElement("VisualElement") +---@cofnigDescription The Switch is a standard Switch element with click handling and state management. + +--- The Switch is a standard Switch element with click handling and state management. +---@class Switch : VisualElement +local Switch = setmetatable({}, VisualElement) +Switch.__index = Switch + +---@property checked boolean Whether switch is checked +Switch.defineProperty(Switch, "checked", {default = false, type = "boolean", canTriggerRender = true}) + +Switch.defineEvent(Switch, "mouse_click") +Switch.defineEvent(Switch, "mouse_up") + +--- @shortDescription Creates a new Switch instance +--- @return table self The created instance +--- @private +function Switch.new() + local self = setmetatable({}, Switch):__init() + self.set("width", 2) + self.set("height", 1) + self.set("z", 5) + return self +end + +--- @shortDescription Initializes the Switch instance +--- @param props table The properties to initialize the element with +--- @param basalt table The basalt instance +--- @protected +function Switch:init(props, basalt) + VisualElement.init(self, props, basalt) + self.set("type", "Switch") +end + +--- @shortDescription Renders the Switch +--- @protected +function Switch:render() + VisualElement.render(self) +end + +return Switch \ No newline at end of file