Docs test
This commit is contained in:
@@ -13,6 +13,8 @@ Button.defineProperty(Button, "text", {default = "Button", type = "string", canT
|
|||||||
Button.listenTo(Button, "mouse_click")
|
Button.listenTo(Button, "mouse_click")
|
||||||
Button.listenTo(Button, "mouse_up")
|
Button.listenTo(Button, "mouse_up")
|
||||||
|
|
||||||
|
--- Creates a new Button instance
|
||||||
|
--- @return table self The created instance
|
||||||
function Button.new()
|
function Button.new()
|
||||||
local self = setmetatable({}, Button):__init()
|
local self = setmetatable({}, Button):__init()
|
||||||
self.set("width", 10)
|
self.set("width", 10)
|
||||||
@@ -21,11 +23,15 @@ function Button.new()
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Initializes the Button instance
|
||||||
|
--- @param props table The properties to initialize the element with
|
||||||
|
--- @param basalt table The basalt instance
|
||||||
function Button:init(props, basalt)
|
function Button:init(props, basalt)
|
||||||
VisualElement.init(self, props, basalt)
|
VisualElement.init(self, props, basalt)
|
||||||
self.set("type", "Button")
|
self.set("type", "Button")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Renders the Button
|
||||||
function Button:render()
|
function Button:render()
|
||||||
VisualElement.render(self)
|
VisualElement.render(self)
|
||||||
local text = self.get("text")
|
local text = self.get("text")
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ Checkbox.defineProperty(Checkbox, "symbol", {default = "x", type = "string"})
|
|||||||
|
|
||||||
Checkbox.listenTo(Checkbox, "mouse_click")
|
Checkbox.listenTo(Checkbox, "mouse_click")
|
||||||
|
|
||||||
|
--- Creates a new Checkbox instance
|
||||||
|
--- @return Checkbox self The created instance
|
||||||
function Checkbox.new()
|
function Checkbox.new()
|
||||||
local self = setmetatable({}, Checkbox):__init()
|
local self = setmetatable({}, Checkbox):__init()
|
||||||
self.set("width", 1)
|
self.set("width", 1)
|
||||||
@@ -20,19 +22,29 @@ function Checkbox.new()
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Initializes the Checkbox instance
|
||||||
|
--- @param props table The properties to initialize the element with
|
||||||
|
--- @param basalt table The basalt instance
|
||||||
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
|
||||||
|
|
||||||
|
--- Handles mouse click events
|
||||||
|
--- @param button number The button that was clicked
|
||||||
|
--- @param x number The x position of the click
|
||||||
|
--- @param y number The y position of the click
|
||||||
|
--- @return boolean Whether the event was handled
|
||||||
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"))
|
||||||
self:fireEvent("change", self.get("checked"))
|
self:fireEvent("change", self.get("checked"))
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Renders the Checkbox
|
||||||
function Checkbox:render()
|
function Checkbox:render()
|
||||||
VisualElement.render(self)
|
VisualElement.render(self)
|
||||||
|
|
||||||
|
|||||||
@@ -9,11 +9,17 @@ local max = math.max
|
|||||||
local Container = setmetatable({}, VisualElement)
|
local Container = setmetatable({}, VisualElement)
|
||||||
Container.__index = Container
|
Container.__index = Container
|
||||||
|
|
||||||
|
---@property children table {} The children of the container
|
||||||
Container.defineProperty(Container, "children", {default = {}, type = "table"})
|
Container.defineProperty(Container, "children", {default = {}, type = "table"})
|
||||||
|
---@property childrenSorted boolean true Whether the children are sorted
|
||||||
Container.defineProperty(Container, "childrenSorted", {default = true, type = "boolean"})
|
Container.defineProperty(Container, "childrenSorted", {default = true, type = "boolean"})
|
||||||
|
---@property childrenEventsSorted boolean true Whether the children events are sorted
|
||||||
Container.defineProperty(Container, "childrenEventsSorted", {default = true, type = "boolean"})
|
Container.defineProperty(Container, "childrenEventsSorted", {default = true, type = "boolean"})
|
||||||
|
---@property childrenEvents table {} The children events of the container
|
||||||
Container.defineProperty(Container, "childrenEvents", {default = {}, type = "table"})
|
Container.defineProperty(Container, "childrenEvents", {default = {}, type = "table"})
|
||||||
|
---@property eventListenerCount table {} The event listener count of the container
|
||||||
Container.defineProperty(Container, "eventListenerCount", {default = {}, type = "table"})
|
Container.defineProperty(Container, "eventListenerCount", {default = {}, type = "table"})
|
||||||
|
---@property focusedChild table nil The focused child of the container
|
||||||
Container.defineProperty(Container, "focusedChild", {default = nil, type = "table", setter = function(self, value, internal)
|
Container.defineProperty(Container, "focusedChild", {default = nil, type = "table", setter = function(self, value, internal)
|
||||||
local oldChild = self._values.focusedChild
|
local oldChild = self._values.focusedChild
|
||||||
|
|
||||||
@@ -36,20 +42,11 @@ Container.defineProperty(Container, "focusedChild", {default = nil, type = "tabl
|
|||||||
return value
|
return value
|
||||||
end})
|
end})
|
||||||
|
|
||||||
|
---@property visibleChildren table {} The visible children of the container
|
||||||
Container.defineProperty(Container, "visibleChildren", {default = {}, type = "table"})
|
Container.defineProperty(Container, "visibleChildren", {default = {}, type = "table"})
|
||||||
|
---@property visibleChildrenEvents table {} The visible children events of the container
|
||||||
Container.defineProperty(Container, "visibleChildrenEvents", {default = {}, type = "table"})
|
Container.defineProperty(Container, "visibleChildrenEvents", {default = {}, type = "table"})
|
||||||
|
|
||||||
function Container:isChildVisible(child)
|
|
||||||
local childX, childY = child.get("x"), child.get("y")
|
|
||||||
local childW, childH = child.get("width"), child.get("height")
|
|
||||||
local containerW, containerH = self.get("width"), self.get("height")
|
|
||||||
|
|
||||||
return childX <= containerW and
|
|
||||||
childY <= containerH and
|
|
||||||
childX + childW > 0 and
|
|
||||||
childY + childH > 0
|
|
||||||
end
|
|
||||||
|
|
||||||
for k, _ in pairs(elementManager:getElementList()) do
|
for k, _ in pairs(elementManager:getElementList()) do
|
||||||
local capitalizedName = k:sub(1,1):upper() .. k:sub(2)
|
local capitalizedName = k:sub(1,1):upper() .. k:sub(2)
|
||||||
if capitalizedName ~= "BaseFrame" then
|
if capitalizedName ~= "BaseFrame" then
|
||||||
@@ -68,16 +65,38 @@ for k, _ in pairs(elementManager:getElementList()) do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Creates a new Container instance
|
||||||
|
--- @return Container self The new container instance
|
||||||
function Container.new()
|
function Container.new()
|
||||||
local self = setmetatable({}, Container):__init()
|
local self = setmetatable({}, Container):__init()
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Initializes the Container instance
|
||||||
|
--- @param props table The properties to initialize the element with
|
||||||
|
--- @param basalt table The basalt instance
|
||||||
function Container:init(props, basalt)
|
function Container:init(props, basalt)
|
||||||
VisualElement.init(self, props, basalt)
|
VisualElement.init(self, props, basalt)
|
||||||
self.set("type", "Container")
|
self.set("type", "Container")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Returns whether a child is visible
|
||||||
|
--- @param child table The child to check
|
||||||
|
--- @return boolean boolean the child is visible
|
||||||
|
function Container:isChildVisible(child)
|
||||||
|
local childX, childY = child.get("x"), child.get("y")
|
||||||
|
local childW, childH = child.get("width"), child.get("height")
|
||||||
|
local containerW, containerH = self.get("width"), self.get("height")
|
||||||
|
|
||||||
|
return childX <= containerW and
|
||||||
|
childY <= containerH and
|
||||||
|
childX + childW > 0 and
|
||||||
|
childY + childH > 0
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Adds a child to the container
|
||||||
|
--- @param child table The child to add
|
||||||
|
--- @return Container self The container instance
|
||||||
function Container:addChild(child)
|
function Container:addChild(child)
|
||||||
if child == self then
|
if child == self then
|
||||||
error("Cannot add container to itself")
|
error("Cannot add container to itself")
|
||||||
@@ -118,6 +137,8 @@ local function sortAndFilterChildren(self, children)
|
|||||||
return visibleChildren
|
return visibleChildren
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Clears the container
|
||||||
|
--- @return Container self The container instance
|
||||||
function Container:clear()
|
function Container:clear()
|
||||||
self.set("children", {})
|
self.set("children", {})
|
||||||
self.set("childrenEvents", {})
|
self.set("childrenEvents", {})
|
||||||
@@ -125,27 +146,43 @@ function Container:clear()
|
|||||||
self.set("visibleChildrenEvents", {})
|
self.set("visibleChildrenEvents", {})
|
||||||
self.set("childrenSorted", true)
|
self.set("childrenSorted", true)
|
||||||
self.set("childrenEventsSorted", true)
|
self.set("childrenEventsSorted", true)
|
||||||
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Sorts the children of the container
|
||||||
|
--- @return Container self The container instance
|
||||||
function Container:sortChildren()
|
function Container:sortChildren()
|
||||||
self.set("visibleChildren", sortAndFilterChildren(self, self._values.children))
|
self.set("visibleChildren", sortAndFilterChildren(self, self._values.children))
|
||||||
self.set("childrenSorted", true)
|
self.set("childrenSorted", true)
|
||||||
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Sorts the children events of the container
|
||||||
|
--- @param eventName string The event name to sort
|
||||||
|
--- @return Container self The container instance
|
||||||
function Container:sortChildrenEvents(eventName)
|
function Container:sortChildrenEvents(eventName)
|
||||||
if self._values.childrenEvents[eventName] then
|
if self._values.childrenEvents[eventName] then
|
||||||
self._values.visibleChildrenEvents[eventName] = sortAndFilterChildren(self, self._values.childrenEvents[eventName])
|
self._values.visibleChildrenEvents[eventName] = sortAndFilterChildren(self, self._values.childrenEvents[eventName])
|
||||||
end
|
end
|
||||||
self.set("childrenEventsSorted", true)
|
self.set("childrenEventsSorted", true)
|
||||||
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Registers the children events of the container
|
||||||
|
--- @param child table The child to register events for
|
||||||
|
--- @return Container self The container instance
|
||||||
function Container:registerChildrenEvents(child)
|
function Container:registerChildrenEvents(child)
|
||||||
if(child._registeredEvents == nil)then return end
|
if(child._registeredEvents == nil)then return end
|
||||||
for event in pairs(child._registeredEvents) do
|
for event in pairs(child._registeredEvents) do
|
||||||
self:registerChildEvent(child, event)
|
self:registerChildEvent(child, event)
|
||||||
end
|
end
|
||||||
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Registers the children events of the container
|
||||||
|
--- @param child table The child to register events for
|
||||||
|
--- @param eventName string The event name to register
|
||||||
|
--- @return Container self The container instance
|
||||||
function Container:registerChildEvent(child, eventName)
|
function Container:registerChildEvent(child, eventName)
|
||||||
if not self._values.childrenEvents[eventName] then
|
if not self._values.childrenEvents[eventName] then
|
||||||
self._values.childrenEvents[eventName] = {}
|
self._values.childrenEvents[eventName] = {}
|
||||||
@@ -158,22 +195,31 @@ function Container:registerChildEvent(child, eventName)
|
|||||||
|
|
||||||
for _, registeredChild in ipairs(self._values.childrenEvents[eventName]) do
|
for _, registeredChild in ipairs(self._values.childrenEvents[eventName]) do
|
||||||
if registeredChild == child then
|
if registeredChild == child then
|
||||||
return
|
return self
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
self.set("childrenEventsSorted", false)
|
self.set("childrenEventsSorted", false)
|
||||||
table.insert(self._values.childrenEvents[eventName], child)
|
table.insert(self._values.childrenEvents[eventName], child)
|
||||||
self._values.eventListenerCount[eventName] = self._values.eventListenerCount[eventName] + 1
|
self._values.eventListenerCount[eventName] = self._values.eventListenerCount[eventName] + 1
|
||||||
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Unregisters the children events of the container
|
||||||
|
--- @param child table The child to unregister events for
|
||||||
|
--- @return Container self The container instance
|
||||||
function Container:removeChildrenEvents(child)
|
function Container:removeChildrenEvents(child)
|
||||||
if(child._registeredEvents == nil)then return end
|
if(child._registeredEvents == nil)then return self end
|
||||||
for event in pairs(child._registeredEvents) do
|
for event in pairs(child._registeredEvents) do
|
||||||
self:unregisterChildEvent(child, event)
|
self:unregisterChildEvent(child, event)
|
||||||
end
|
end
|
||||||
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Unregisters the children events of the container
|
||||||
|
--- @param child table The child to unregister events for
|
||||||
|
--- @param eventName string The event name to unregister
|
||||||
|
--- @return Container self The container instance
|
||||||
function Container:unregisterChildEvent(child, eventName)
|
function Container:unregisterChildEvent(child, eventName)
|
||||||
if self._values.childrenEvents[eventName] then
|
if self._values.childrenEvents[eventName] then
|
||||||
for i, listener in ipairs(self._values.childrenEvents[eventName]) do
|
for i, listener in ipairs(self._values.childrenEvents[eventName]) do
|
||||||
@@ -193,6 +239,7 @@ function Container:unregisterChildEvent(child, eventName)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
function Container:removeChild(child)
|
function Container:removeChild(child)
|
||||||
|
|||||||
Reference in New Issue
Block a user