Class rename

This commit is contained in:
Robert Jelic
2025-09-14 12:19:36 +02:00
parent dd6a1209a1
commit 264b1b9425
5 changed files with 81 additions and 81 deletions

View File

@@ -1378,7 +1378,7 @@ self:textFg(1,y,
bd..string.rep(" ",self.get("width")-#bd),self.get("foreground"))else bd..string.rep(" ",self.get("width")-#bd),self.get("foreground"))else
self:textFg(1,y,string.rep(" ",self.get("width")),self.get("foreground"),self.get("background"))end end end;return ba end self:textFg(1,y,string.rep(" ",self.get("width")),self.get("foreground"),self.get("background"))end end end;return ba end
project["elements/ComboBox.lua"] = function(...) local _a=require("elements/VisualElement") project["elements/ComboBox.lua"] = function(...) local _a=require("elements/VisualElement")
local aa=require("elements/Dropdown")local ba=require("libraries/colorHex") local aa=require("src.elements.DropDown")local ba=require("libraries/colorHex")
local ca=setmetatable({},aa)ca.__index=ca local ca=setmetatable({},aa)ca.__index=ca
ca.defineProperty(ca,"editable",{default=true,type="boolean",canTriggerRender=true}) ca.defineProperty(ca,"editable",{default=true,type="boolean",canTriggerRender=true})
ca.defineProperty(ca,"text",{default="",type="string",canTriggerRender=true}) ca.defineProperty(ca,"text",{default="",type="string",canTriggerRender=true})

View File

@@ -1,15 +1,15 @@
local VisualElement = require("elements/VisualElement") local VisualElement = require("elements/VisualElement")
---@cofnigDescription This is a checkbox. It is a visual element that can be checked. ---@cofnigDescription This is a checkbox. It is a visual element that can be checked.
--- The Checkbox is a visual element that can be checked. --- The CheckBox is a visual element that can be checked.
---@class Checkbox : VisualElement ---@class CheckBox : VisualElement
local Checkbox = setmetatable({}, VisualElement) local CheckBox = setmetatable({}, VisualElement)
Checkbox.__index = Checkbox CheckBox.__index = CheckBox
---@property checked boolean Whether checkbox is checked ---@property checked boolean Whether checkbox is checked
Checkbox.defineProperty(Checkbox, "checked", {default = false, type = "boolean", canTriggerRender = true}) CheckBox.defineProperty(CheckBox, "checked", {default = false, type = "boolean", canTriggerRender = true})
---@property text string empty Text to display ---@property text string empty Text to display
Checkbox.defineProperty(Checkbox, "text", {default = " ", type = "string", canTriggerRender = true, setter=function(self, value) CheckBox.defineProperty(CheckBox, "text", {default = " ", type = "string", canTriggerRender = true, setter=function(self, value)
local checkedText = self.get("checkedText") local checkedText = self.get("checkedText")
local width = math.max(#value, #checkedText) local width = math.max(#value, #checkedText)
if(self.get("autoSize"))then if(self.get("autoSize"))then
@@ -18,7 +18,7 @@ Checkbox.defineProperty(Checkbox, "text", {default = " ", type = "string", canTr
return value return value
end}) end})
---@property checkedText string Text when checked ---@property checkedText string Text when checked
Checkbox.defineProperty(Checkbox, "checkedText", {default = "x", type = "string", canTriggerRender = true, setter=function(self, value) CheckBox.defineProperty(CheckBox, "checkedText", {default = "x", type = "string", canTriggerRender = true, setter=function(self, value)
local text = self.get("text") local text = self.get("text")
local width = math.max(#value, #text) local width = math.max(#value, #text)
if(self.get("autoSize"))then if(self.get("autoSize"))then
@@ -27,28 +27,28 @@ Checkbox.defineProperty(Checkbox, "checkedText", {default = "x", type = "string"
return value return value
end}) end})
---@property autoSize boolean true Whether to automatically size the checkbox ---@property autoSize boolean true Whether to automatically size the checkbox
Checkbox.defineProperty(Checkbox, "autoSize", {default = true, type = "boolean"}) CheckBox.defineProperty(CheckBox, "autoSize", {default = true, type = "boolean"})
Checkbox.defineEvent(Checkbox, "mouse_click") CheckBox.defineEvent(CheckBox, "mouse_click")
Checkbox.defineEvent(Checkbox, "mouse_up") CheckBox.defineEvent(CheckBox, "mouse_up")
--- @shortDescription Creates a new Checkbox instance --- @shortDescription Creates a new CheckBox instance
--- @return Checkbox self The created instance --- @return CheckBox self The created instance
--- @protected --- @protected
function Checkbox.new() function CheckBox.new()
local self = setmetatable({}, Checkbox):__init() local self = setmetatable({}, CheckBox):__init()
self.class = Checkbox self.class = CheckBox
self.set("backgroundEnabled", false) self.set("backgroundEnabled", false)
return self return self
end end
--- @shortDescription Initializes the Checkbox instance --- @shortDescription Initializes the CheckBox instance
--- @param props table The properties to initialize the element with --- @param props table The properties to initialize the element with
--- @param basalt table The basalt instance --- @param basalt table The basalt instance
--- @protected --- @protected
function Checkbox:init(props, basalt) function CheckBox:init(props, basalt)
VisualElement.init(self, props, basalt) VisualElement.init(self, props, basalt)
self.set("type", "Checkbox") self.set("type", "CheckBox")
end end
--- @shortDescription Handles mouse click events --- @shortDescription Handles mouse click events
@@ -57,7 +57,7 @@ end
--- @param y number The y position of the click --- @param y number The y position of the click
--- @return boolean Clicked Whether the event was handled --- @return boolean Clicked Whether the event was handled
--- @protected --- @protected
function Checkbox:mouse_click(button, x, y) function CheckBox:mouse_click(button, x, y)
if VisualElement.mouse_click(self, button, x, y) then if VisualElement.mouse_click(self, button, x, y) then
self.set("checked", not self.get("checked")) self.set("checked", not self.get("checked"))
return true return true
@@ -65,9 +65,9 @@ function Checkbox:mouse_click(button, x, y)
return false return false
end end
--- @shortDescription Renders the Checkbox --- @shortDescription Renders the CheckBox
--- @protected --- @protected
function Checkbox:render() function CheckBox:render()
VisualElement.render(self) VisualElement.render(self)
local checked = self.get("checked") local checked = self.get("checked")
@@ -78,4 +78,4 @@ function Checkbox:render()
self:textFg(1, 1, text, self.get("foreground")) self:textFg(1, 1, text, self.get("foreground"))
end end
return Checkbox return CheckBox

View File

@@ -1,5 +1,5 @@
local VisualElement = require("elements/VisualElement") local VisualElement = require("elements/VisualElement")
local Dropdown = require("elements/Dropdown") local Dropdown = require("src.elements.DropDown")
local tHex = require("libraries/colorHex") local tHex = require("libraries/colorHex")
---@configDescription A ComboBox that combines dropdown selection with editable text input ---@configDescription A ComboBox that combines dropdown selection with editable text input

View File

@@ -2,50 +2,50 @@ local VisualElement = require("elements/VisualElement")
local List = require("elements/List") local List = require("elements/List")
local tHex = require("libraries/colorHex") local tHex = require("libraries/colorHex")
---@configDescription A dropdown menu that shows a list of selectable items ---@configDescription A DropDown menu that shows a list of selectable items
---@configDefault false ---@configDefault false
--- This is the dropdown class. It is a visual element that can show a list of selectable items in a dropdown menu. --- This is the DropDown class. It is a visual element that can show a list of selectable items in a DropDown menu.
--- @usage local dropdown = main:addDropdown() --- @usage local DropDown = main:addDropdown()
--- @usage dropdown:setItems({ --- @usage DropDown:setItems({
--- @usage {text = "Item 1", callback = function() basalt.LOGGER.debug("Item 1 selected") end}, --- @usage {text = "Item 1", callback = function() basalt.LOGGER.debug("Item 1 selected") end},
--- @usage {text = "Item 2", callback = function() basalt.LOGGER.debug("Item 2 selected") end}, --- @usage {text = "Item 2", callback = function() basalt.LOGGER.debug("Item 2 selected") end},
--- @usage {text = "Item 3", callback = function() basalt.LOGGER.debug("Item 3 selected") end}, --- @usage {text = "Item 3", callback = function() basalt.LOGGER.debug("Item 3 selected") end},
--- @usage }) --- @usage })
---@class Dropdown : List ---@class DropDown : List
local Dropdown = setmetatable({}, List) local DropDown = setmetatable({}, List)
Dropdown.__index = Dropdown DropDown.__index = DropDown
---@property isOpen boolean false Whether the dropdown menu is currently open ---@property isOpen boolean false Whether the DropDown menu is currently open
Dropdown.defineProperty(Dropdown, "isOpen", {default = false, type = "boolean", canTriggerRender = true}) DropDown.defineProperty(DropDown, "isOpen", {default = false, type = "boolean", canTriggerRender = true})
---@property dropdownHeight number 5 Maximum height of the dropdown menu when open ---@property dropdownHeight number 5 Maximum height of the DropDown menu when open
Dropdown.defineProperty(Dropdown, "dropdownHeight", {default = 5, type = "number"}) DropDown.defineProperty(DropDown, "dropdownHeight", {default = 5, type = "number"})
---@property selectedText string "" The text to show when no item is selected ---@property selectedText string "" The text to show when no item is selected
Dropdown.defineProperty(Dropdown, "selectedText", {default = "", type = "string"}) DropDown.defineProperty(DropDown, "selectedText", {default = "", type = "string"})
---@property dropSymbol string "\31" The symbol to show for dropdown indication ---@property dropSymbol string "\31" The symbol to show for DropDown indication
Dropdown.defineProperty(Dropdown, "dropSymbol", {default = "\31", type = "string"}) DropDown.defineProperty(DropDown, "dropSymbol", {default = "\31", type = "string"})
--- Creates a new Dropdown instance --- Creates a new DropDown instance
--- @shortDescription Creates a new Dropdown instance --- @shortDescription Creates a new DropDown instance
--- @return Dropdown self The newly created Dropdown instance --- @return DropDown self The newly created DropDown instance
--- @private --- @private
function Dropdown.new() function DropDown.new()
local self = setmetatable({}, Dropdown):__init() local self = setmetatable({}, DropDown):__init()
self.class = Dropdown self.class = DropDown
self.set("width", 16) self.set("width", 16)
self.set("height", 1) self.set("height", 1)
self.set("z", 8) self.set("z", 8)
return self return self
end end
--- @shortDescription Initializes the Dropdown instance --- @shortDescription Initializes the DropDown instance
--- @param props table The properties to initialize the element with --- @param props table The properties to initialize the element with
--- @param basalt table The basalt instance --- @param basalt table The basalt instance
--- @return Dropdown self The initialized instance --- @return DropDown self The initialized instance
--- @protected --- @protected
function Dropdown:init(props, basalt) function DropDown:init(props, basalt)
List.init(self, props, basalt) List.init(self, props, basalt)
self.set("type", "Dropdown") self.set("type", "DropDown")
return self return self
end end
@@ -55,7 +55,7 @@ end
--- @param y number The y position of the click --- @param y number The y position of the click
--- @return boolean handled Whether the event was handled --- @return boolean handled Whether the event was handled
--- @protected --- @protected
function Dropdown:mouse_click(button, x, y) function DropDown:mouse_click(button, x, y)
if not VisualElement.mouse_click(self, button, x, y) then return false end if not VisualElement.mouse_click(self, button, x, y) then return false end
local relX, relY = self:getRelativePosition(x, y) local relX, relY = self:getRelativePosition(x, y)
@@ -103,9 +103,9 @@ function Dropdown:mouse_click(button, x, y)
return false return false
end end
--- @shortDescription Renders the Dropdown --- @shortDescription Renders the DropDown
--- @protected --- @protected
function Dropdown:render() function DropDown:render()
VisualElement.render(self) VisualElement.render(self)
local text = self.get("selectedText") local text = self.get("selectedText")
@@ -165,4 +165,4 @@ function Dropdown:render()
end end
end end
return Dropdown return DropDown

View File

@@ -2,7 +2,7 @@ local elementManager = require("elementManager")
local Container = elementManager.getElement("Container") local Container = elementManager.getElement("Container")
---@configDescription A flexbox container that arranges its children in a flexible layout. ---@configDescription A flexbox container that arranges its children in a flexible layout.
--- This is the Flexbox class. It is a container that arranges its children in a flexible layout. --- This is the FlexBox class. It is a container that arranges its children in a flexible layout.
--- @usage local flex = main:addFlexbox({background=colors.black, width=30, height=10}) --- @usage local flex = main:addFlexbox({background=colors.black, width=30, height=10})
--- @usage flex:addButton():setFlexGrow(1) --- @usage flex:addButton():setFlexGrow(1)
--- @usage flex:addButton():setFlexGrow(1) --- @usage flex:addButton():setFlexGrow(1)
@@ -12,16 +12,16 @@ local Container = elementManager.getElement("Container")
--- @usage flex:addButton():setFlexGrow(1) -- The flex-grow property defines the ability for a flex item to grow if necessary. --- @usage flex:addButton():setFlexGrow(1) -- The flex-grow property defines the ability for a flex item to grow if necessary.
--- @usage flex:addButton():setFlexShrink(1) -- The flex-shrink property defines the ability for a flex item to shrink if necessary. --- @usage flex:addButton():setFlexShrink(1) -- The flex-shrink property defines the ability for a flex item to shrink if necessary.
--- @usage flex:addButton():setFlexBasis(1) -- The flex-basis property defines the default size of an element before the remaining space is distributed. --- @usage flex:addButton():setFlexBasis(1) -- The flex-basis property defines the default size of an element before the remaining space is distributed.
---@class Flexbox : Container ---@class FlexBox : Container
local Flexbox = setmetatable({}, Container) local FlexBox = setmetatable({}, Container)
Flexbox.__index = Flexbox FlexBox.__index = FlexBox
---@property flexDirection string "row" The direction of the flexbox layout "row" or "column" ---@property flexDirection string "row" The direction of the flexbox layout "row" or "column"
Flexbox.defineProperty(Flexbox, "flexDirection", {default = "row", type = "string"}) FlexBox.defineProperty(FlexBox, "flexDirection", {default = "row", type = "string"})
---@property flexSpacing number 1 The spacing between flex items ---@property flexSpacing number 1 The spacing between flex items
Flexbox.defineProperty(Flexbox, "flexSpacing", {default = 1, type = "number"}) FlexBox.defineProperty(FlexBox, "flexSpacing", {default = 1, type = "number"})
---@property flexJustifyContent string "flex-start" The alignment of flex items along the main axis ---@property flexJustifyContent string "flex-start" The alignment of flex items along the main axis
Flexbox.defineProperty(Flexbox, "flexJustifyContent", { FlexBox.defineProperty(FlexBox, "flexJustifyContent", {
default = "flex-start", default = "flex-start",
type = "string", type = "string",
setter = function(self, value) setter = function(self, value)
@@ -32,7 +32,7 @@ Flexbox.defineProperty(Flexbox, "flexJustifyContent", {
end end
}) })
---@property flexAlignItems string "flex-start" The alignment of flex items along the cross axis ---@property flexAlignItems string "flex-start" The alignment of flex items along the cross axis
Flexbox.defineProperty(Flexbox, "flexAlignItems", { FlexBox.defineProperty(FlexBox, "flexAlignItems", {
default = "flex-start", default = "flex-start",
type = "string", type = "string",
setter = function(self, value) setter = function(self, value)
@@ -43,11 +43,11 @@ Flexbox.defineProperty(Flexbox, "flexAlignItems", {
end end
}) })
---@property flexCrossPadding number 0 The padding on both sides of the cross axis ---@property flexCrossPadding number 0 The padding on both sides of the cross axis
Flexbox.defineProperty(Flexbox, "flexCrossPadding", {default = 0, type = "number"}) FlexBox.defineProperty(FlexBox, "flexCrossPadding", {default = 0, type = "number"})
---@property flexWrap boolean false Whether to wrap flex items onto multiple lines ---@property flexWrap boolean false Whether to wrap flex items onto multiple lines
---@property flexUpdateLayout boolean false Whether to update the layout of the flexbox ---@property flexUpdateLayout boolean false Whether to update the layout of the flexbox
Flexbox.defineProperty(Flexbox, "flexWrap", {default = false, type = "boolean"}) FlexBox.defineProperty(FlexBox, "flexWrap", {default = false, type = "boolean"})
Flexbox.defineProperty(Flexbox, "flexUpdateLayout", {default = false, type = "boolean"}) FlexBox.defineProperty(FlexBox, "flexUpdateLayout", {default = false, type = "boolean"})
local lineBreakElement = { local lineBreakElement = {
getHeight = function(self) return 0 end, getHeight = function(self) return 0 end,
@@ -715,12 +715,12 @@ local function updateLayout(self, direction, spacing, justifyContent, wrap)
self.set("flexUpdateLayout", false) self.set("flexUpdateLayout", false)
end end
--- @shortDescription Creates a new Flexbox instance --- @shortDescription Creates a new FlexBox instance
--- @return Flexbox object The newly created Flexbox instance --- @return FlexBox object The newly created FlexBox instance
--- @private --- @private
function Flexbox.new() function FlexBox.new()
local self = setmetatable({}, Flexbox):__init() local self = setmetatable({}, FlexBox):__init()
self.class = Flexbox self.class = FlexBox
self.set("width", 12) self.set("width", 12)
self.set("height", 6) self.set("height", 6)
self.set("background", colors.blue) self.set("background", colors.blue)
@@ -741,22 +741,22 @@ function Flexbox.new()
return self return self
end end
--- @shortDescription Initializes the Flexbox instance --- @shortDescription Initializes the FlexBox instance
--- @param props table The properties to initialize the element with --- @param props table The properties to initialize the element with
--- @param basalt table The basalt instance --- @param basalt table The basalt instance
--- @return Flexbox self The initialized instance --- @return FlexBox self The initialized instance
--- @protected --- @protected
function Flexbox:init(props, basalt) function FlexBox:init(props, basalt)
Container.init(self, props, basalt) Container.init(self, props, basalt)
self.set("type", "Flexbox") self.set("type", "FlexBox")
return self return self
end end
--- Adds a child element to the flexbox --- Adds a child element to the flexbox
--- @shortDescription Adds a child element to the flexbox --- @shortDescription Adds a child element to the flexbox
--- @param element Element The child element to add --- @param element Element The child element to add
--- @return Flexbox self The flexbox instance --- @return FlexBox self The flexbox instance
function Flexbox:addChild(element) function FlexBox:addChild(element)
Container.addChild(self, element) Container.addChild(self, element)
if(element~=lineBreakElement)then if(element~=lineBreakElement)then
@@ -789,9 +789,9 @@ end
--- @shortDescription Removes a child element from the flexbox --- @shortDescription Removes a child element from the flexbox
--- @param element Element The child element to remove --- @param element Element The child element to remove
--- @return Flexbox self The flexbox instance --- @return FlexBox self The flexbox instance
--- @protected --- @protected
function Flexbox:removeChild(element) function FlexBox:removeChild(element)
Container.removeChild(self, element) Container.removeChild(self, element)
if(element~=lineBreakElement)then if(element~=lineBreakElement)then
@@ -812,20 +812,20 @@ end
--- Adds a new line break to the flexbox --- Adds a new line break to the flexbox
--- @shortDescription Adds a new line break to the flexbox. --- @shortDescription Adds a new line break to the flexbox.
---@param self Flexbox The element itself ---@param self FlexBox The element itself
---@return Flexbox ---@return FlexBox
function Flexbox:addLineBreak() function FlexBox:addLineBreak()
self:addChild(lineBreakElement) self:addChild(lineBreakElement)
return self return self
end end
--- @shortDescription Renders the flexbox and its children --- @shortDescription Renders the flexbox and its children
--- @protected --- @protected
function Flexbox:render() function FlexBox:render()
if(self.get("flexUpdateLayout"))then if(self.get("flexUpdateLayout"))then
updateLayout(self, self.get("flexDirection"), self.get("flexSpacing"), self.get("flexJustifyContent"), self.get("flexWrap")) updateLayout(self, self.get("flexDirection"), self.get("flexSpacing"), self.get("flexJustifyContent"), self.get("flexWrap"))
end end
Container.render(self) Container.render(self)
end end
return Flexbox return FlexBox