Lots of fixes and improvements
This commit is contained in:
Robert Jelic
2025-02-16 14:33:07 +01:00
parent 19edc4b295
commit cc7b2de51a
27 changed files with 198 additions and 208 deletions

View File

@@ -46,9 +46,8 @@ end
--- @param basalt table The basalt instance
--- @return table The newly created BaseElement instance
--- @usage local element = BaseElement.new("myId", basalt)
function BaseElement.new(props, basalt)
function BaseElement.new()
local self = setmetatable({}, BaseElement):__init()
self:init(props, basalt)
return self
end
@@ -57,11 +56,7 @@ end
--- @param basalt table The basalt instance
--- @return table self The initialized instance
function BaseElement:init(props, basalt)
if(type(props) == "table")then
for k,v in pairs(props)do
self[k] = v
end
end
self._props = props
self._values.id = uuid()
self.basalt = basalt
self._registeredEvents = {}
@@ -80,6 +75,18 @@ function BaseElement:init(props, basalt)
return self
end
--- Post initialization hook
--- @return table self The BaseElement instance
function BaseElement:postInit()
if(self._props)then
for k,v in pairs(self._props)do
self.set(k, v)
end
end
self._props = nil
return self
end
--- Checks if the element is a specific type
--- @param type string The type to check for
--- @return boolean Whether the element is of the specified type

View File

@@ -19,11 +19,10 @@ BaseFrame.defineProperty(BaseFrame, "term", {default = nil, type = "table", sett
return value
end})
function BaseFrame.new(props, basalt)
function BaseFrame.new()
local self = setmetatable({}, BaseFrame):__init()
self.set("term", term.current())
self.set("background", colors.lightGray)
self:init(props, basalt)
return self
end

View File

@@ -13,12 +13,11 @@ Button.defineProperty(Button, "text", {default = "Button", type = "string", canT
Button.listenTo(Button, "mouse_click")
Button.listenTo(Button, "mouse_up")
function Button.new(props, basalt)
function Button.new()
local self = setmetatable({}, Button):__init()
self.set("width", 10)
self.set("height", 3)
self.set("z", 5)
self:init(props, basalt)
return self
end

View File

@@ -13,11 +13,10 @@ Checkbox.defineProperty(Checkbox, "symbol", {default = "x", type = "string"})
Checkbox.listenTo(Checkbox, "mouse_click")
function Checkbox.new(props, basalt)
function Checkbox.new()
local self = setmetatable({}, Checkbox):__init()
self.set("width", 1)
self.set("height", 1)
self:init(props, basalt)
return self
end

View File

@@ -57,6 +57,7 @@ for k, _ in pairs(elementManager:getElementList()) do
expect(1, self, "table")
local element = self.basalt.create(k, ...)
self:addChild(element)
element:postInit()
return element
end
Container["addDelayed"..capitalizedName] = function(self, prop)
@@ -67,9 +68,8 @@ for k, _ in pairs(elementManager:getElementList()) do
end
end
function Container.new(props, basalt)
function Container.new()
local self = setmetatable({}, Container):__init()
self:init(props, basalt)
return self
end

View File

@@ -11,12 +11,11 @@ Dropdown.defineProperty(Dropdown, "dropdownHeight", {default = 5, type = "number
Dropdown.defineProperty(Dropdown, "selectedText", {default = "", type = "string"})
Dropdown.defineProperty(Dropdown, "dropSymbol", {default = "\31", type = "string"}) -- ▼ Symbol
function Dropdown.new(props, basalt)
function Dropdown.new()
local self = setmetatable({}, Dropdown):__init()
self.set("width", 16)
self.set("height", 1) -- Dropdown ist initial nur 1 Zeile hoch
self.set("height", 1)
self.set("z", 8)
self:init(props, basalt)
return self
end

View File

@@ -226,11 +226,9 @@ local function updateLayout(self, direction, spacing, justifyContent, wrap)
end
--- Creates a new Flexbox instance
--- @param props table The properties to initialize the element with
--- @param basalt table The basalt instance
--- @return Flexbox object The newly created Flexbox instance
--- @usage local element = Flexbox.new("myId", basalt)
function Flexbox.new(props, basalt)
function Flexbox.new()
local self = setmetatable({}, Flexbox):__init()
self.set("width", 12)
self.set("height", 6)
@@ -238,7 +236,6 @@ function Flexbox.new(props, basalt)
self.set("z", 10)
self:observe("width", function() self.set("flexUpdateLayout", true) end)
self:observe("height", function() self.set("flexUpdateLayout", true) end)
self:init(props, basalt)
return self
end

View File

@@ -6,17 +6,14 @@ local Frame = setmetatable({}, Container)
Frame.__index = Frame
--- Creates a new Frame instance
--- @param props table The properties to initialize the element with
--- @param basalt table The basalt instance
--- @return Frame object The newly created Frame instance
--- @usage local element = Frame.new("myId", basalt)
function Frame.new(props, basalt)
function Frame.new()
local self = setmetatable({}, Frame):__init()
self.set("width", 12)
self.set("height", 6)
self.set("background", colors.gray)
self.set("z", 10)
self:init(props, basalt)
return self
end

View File

@@ -26,15 +26,12 @@ Input.listenTo(Input, "key")
Input.listenTo(Input, "char")
--- Creates a new Input instance
--- @param props table The properties to initialize the element with
--- @param basalt table The basalt instance
--- @return Input object The newly created Input instance
--- @usage local element = Input.new("myId", basalt)
function Input.new(props, basalt)
function Input.new()
local self = setmetatable({}, Input):__init()
self.set("width", 8)
self.set("z", 3)
self:init(id, basalt)
return self
end

View File

@@ -13,16 +13,13 @@ Label.defineProperty(Label, "text", {default = "Label", type = "string", setter
end})
--- Creates a new Label instance
--- @param props table The properties to initialize the element with
--- @param basalt table The basalt instance
--- @return Label object The newly created Label instance
--- @usage local element = Label.new("myId", basalt)
function Label.new(props, basalt)
function Label.new()
local self = setmetatable({}, Label):__init()
self.set("z", 3)
self.set("foreground", colors.black)
self.set("backgroundEnabled", false)
self:init(props, basalt)
return self
end

View File

@@ -18,12 +18,11 @@ List.defineProperty(List, "selectedColor", {default = colors.blue, type = "numbe
List.listenTo(List, "mouse_click")
List.listenTo(List, "mouse_scroll")
function List.new(props, basalt)
function List.new()
local self = setmetatable({}, List):__init()
self.set("width", 16)
self.set("height", 8)
self.set("background", colors.gray)
self:init(props, basalt)
return self
end

View File

@@ -8,12 +8,11 @@ Menu.__index = Menu
Menu.defineProperty(Menu, "separatorColor", {default = colors.gray, type = "number"})
function Menu.new(props, basalt)
function Menu.new()
local self = setmetatable({}, Menu):__init()
self.set("width", 30)
self.set("height", 1)
self.set("background", colors.gray)
self:init(props, basalt)
return self
end

View File

@@ -108,16 +108,13 @@ function BasaltProgram:stop()
end
--- Creates a new Program instance
--- @param props table The properties to initialize the element with
--- @param basalt table The basalt instance
--- @return Program object The newly created Program instance
--- @usage local element = Program.new("myId", basalt)
function Program.new(props, basalt)
function Program.new()
local self = setmetatable({}, Program):__init()
self.set("z", 5)
self.set("width", 30)
self.set("height", 12)
self:init(props, basalt)
return self
end

View File

@@ -11,11 +11,10 @@ ProgressBar.defineProperty(ProgressBar, "showPercentage", {default = false, type
---@property progressColor color Progress bar color
ProgressBar.defineProperty(ProgressBar, "progressColor", {default = colors.lime, type = "number"})
function ProgressBar.new(props, basalt)
function ProgressBar.new()
local self = setmetatable({}, ProgressBar):__init()
self.set("width", 10)
self.set("height", 1)
self:init(props, basalt)
return self
end

View File

@@ -19,12 +19,11 @@ Slider.listenTo(Slider, "mouse_click")
Slider.listenTo(Slider, "mouse_drag")
Slider.listenTo(Slider, "mouse_up")
function Slider.new(props, basalt)
function Slider.new()
local self = setmetatable({}, Slider):__init()
self.set("width", 8)
self.set("height", 1)
self.set("backgroundEnabled", false)
self:init(props, basalt)
return self
end

View File

@@ -18,12 +18,11 @@ Table.defineProperty(Table, "scrollOffset", {default = 0, type = "number", canTr
Table.listenTo(Table, "mouse_click")
Table.listenTo(Table, "mouse_scroll")
function Table.new(props, basalt)
function Table.new()
local self = setmetatable({}, Table):__init()
self.set("width", 30)
self.set("height", 10)
self.set("z", 5)
self:init(props, basalt)
return self
end

View File

@@ -15,12 +15,11 @@ Tree.defineProperty(Tree, "selectedColor", {default = colors.lightBlue, type = "
Tree.listenTo(Tree, "mouse_click")
Tree.listenTo(Tree, "mouse_scroll")
function Tree.new(props, basalt)
function Tree.new()
local self = setmetatable({}, Tree):__init()
self.set("width", 30)
self.set("height", 10)
self.set("z", 5)
self:init(props, basalt)
return self
end

View File

@@ -75,9 +75,8 @@ local max, min = math.max, math.min
--- @param basalt table The basalt instance
--- @return VisualElement object The newly created VisualElement instance
--- @usage local element = VisualElement.new("myId", basalt)
function VisualElement.new(props, basalt)
function VisualElement.new()
local self = setmetatable({}, VisualElement):__init()
self:init(props, basalt)
return self
end