From 5ccd201be0ce243ff8aef70450cd059e6b59d388 Mon Sep 17 00:00:00 2001 From: Robert Jelic <36573031+NoryiE@users.noreply.github.com> Date: Thu, 3 Apr 2025 18:03:06 +0200 Subject: [PATCH] Focus fix for list --- src/elements/List.lua | 2 +- src/elements/Switch.lua | 42 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 src/elements/Switch.lua 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