Skip to content

Commit 3a87b44

Browse files
committed
Changes
1 parent ccc86b0 commit 3a87b44

File tree

9 files changed

+226
-128
lines changed

9 files changed

+226
-128
lines changed

src/elements/BarChart.lua

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ local VisualElement = elementManager.getElement("VisualElement")
33
local BaseGraph = elementManager.getElement("Graph")
44
local tHex = require("libraries/colorHex")
55
--- @configDescription A bar chart element based on the graph element.
6-
---@configDefault false
6+
--- @configDefault false
77

8-
--- The Bar Chart element is designed for visualizing data series as vertical bars. It displays multiple values as side-by-side bars where each bar's height represents its value.
8+
--- A data visualization element that represents numeric data through vertical bars. Each bar's height corresponds to its value, making it ideal for comparing quantities across categories or showing data changes over time. Supports multiple data series with customizable colors and styles.
9+
--- @usage -- Create a bar chart
910
--- @usage local chart = main:addBarChart()
10-
--- @usage :addSeries("input", " ", colors.green, colors.green, 5)
11-
--- @usage :addSeries("output", " ", colors.red, colors.red, 5)
1211
--- @usage
12+
--- @usage -- Add two data series with different colors
13+
--- @usage chart:addSeries("input", " ", colors.green, colors.green, 5)
14+
--- @usage chart:addSeries("output", " ", colors.red, colors.red, 5)
15+
--- @usage
16+
--- @usage -- Continuously update the chart with random data
1317
--- @usage basalt.schedule(function()
1418
--- @usage while true do
1519
--- @usage chart:addPoint("input", math.random(1,100))
@@ -42,7 +46,8 @@ function BarChart:init(props, basalt)
4246
return self
4347
end
4448

45-
--- @shortDescription Renders the BarChart
49+
--- Renders the bar chart by calculating bar positions and heights based on data values
50+
--- @shortDescription Draws bars for each data point in visible series
4651
--- @protected
4752
function BarChart:render()
4853
VisualElement.render(self)

src/elements/BaseElement.lua

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ local uuid = require("libraries/utils").uuid
33
local errorManager = require("errorManager")
44
---@configDescription The base class for all UI elements in Basalt.
55

6-
--- The base class for all UI elements in Basalt. This class provides basic properties and event handling functionality.
6+
--- The fundamental base class for all UI elements in Basalt. It implements core functionality like event handling, property management, lifecycle hooks, and the observer pattern. Every UI component inherits from this class to ensure consistent behavior and interface.
77
--- @class BaseElement : PropertySystem
88
local BaseElement = setmetatable({}, PropertySystem)
99
BaseElement.__index = BaseElement
1010

11-
--- @property type string BaseElement The type identifier of the element
11+
--- @property type string BaseElement A hierarchical identifier of the element's type chain
1212
BaseElement.defineProperty(BaseElement, "type", {default = {"BaseElement"}, type = "string", setter=function(self, value)
1313
if type(value) == "string" then
1414
table.insert(self._values.type, 1, value)
@@ -22,19 +22,19 @@ end, getter = function(self, _, index)
2222
return self._values.type[index or 1]
2323
end})
2424

25-
--- @property id string BaseElement The unique identifier for the element
25+
--- @property id string BaseElement Auto-generated unique identifier for element lookup
2626
BaseElement.defineProperty(BaseElement, "id", {default = "", type = "string", readonly = true})
2727

28-
--- @property name string BaseElement The name of the element
28+
--- @property name string BaseElement User-defined name for the element
2929
BaseElement.defineProperty(BaseElement, "name", {default = "", type = "string"})
3030

31-
--- @property eventCallbacks table BaseElement The event callbacks for the element
31+
--- @property eventCallbacks table BaseElement Collection of registered event handler functions
3232
BaseElement.defineProperty(BaseElement, "eventCallbacks", {default = {}, type = "table"})
3333

34-
--- @property enabled boolean BaseElement Whether the element is enabled or not
34+
--- @property enabled boolean BaseElement Controls event processing for this element
3535
BaseElement.defineProperty(BaseElement, "enabled", {default = true, type = "boolean" })
3636

37-
--- Registers a new event listener for the element (on class level)
37+
--- Registers a class-level event listener with optional dependency
3838
--- @shortDescription Registers a new event listener for the element (on class level)
3939
--- @param class table The class to register
4040
--- @param eventName string The name of the event to register
@@ -49,8 +49,8 @@ function BaseElement.defineEvent(class, eventName, requiredEvent)
4949
}
5050
end
5151

52-
--- Registers a new event callback for the element (on class level)
53-
--- @shortDescription Registers a new event callback for the element (on class level)
52+
--- Defines a class-level event callback method with automatic event registration
53+
--- @shortDescription Registers a new event callback method with auto-registration
5454
--- @param class table The class to register
5555
--- @param callbackName string The name of the callback to register
5656
--- @param ... string The names of the events to register the callback for
@@ -143,8 +143,8 @@ function BaseElement:postInit()
143143
return self
144144
end
145145

146-
--- Checks if the element is a specific type
147-
--- @shortDescription Checks if the element is a specific type
146+
--- Checks if the element matches or inherits from the specified type
147+
--- @shortDescription Tests if element is of or inherits given type
148148
--- @param type string The type to check for
149149
--- @return boolean isType Whether the element is of the specified type
150150
function BaseElement:isType(type)
@@ -156,8 +156,8 @@ function BaseElement:isType(type)
156156
return false
157157
end
158158

159-
--- Enables or disables event listening for a specific event
160-
--- @shortDescription Enables or disables event listening for a specific event
159+
--- Configures event listening behavior with automatic parent notification
160+
--- @shortDescription Enables/disables event handling for this element
161161
--- @param eventName string The name of the event to listen for
162162
--- @param enable? boolean Whether to enable or disable the event (default: true)
163163
--- @return table self The BaseElement instance
@@ -179,8 +179,8 @@ function BaseElement:listenEvent(eventName, enable)
179179
return self
180180
end
181181

182-
--- Registers a callback function for an event
183-
--- @shortDescription Registers a callback function
182+
--- Adds an event handler function with automatic event registration
183+
--- @shortDescription Registers a function to handle specific events
184184
--- @param event string The event to register the callback for
185185
--- @param callback function The callback function to register
186186
--- @return table self The BaseElement instance
@@ -197,8 +197,8 @@ function BaseElement:registerCallback(event, callback)
197197
return self
198198
end
199199

200-
--- Triggers an event and calls all registered callbacks
201-
--- @shortDescription Triggers an event and calls all registered callbacks
200+
--- Executes all registered callbacks for the specified event
201+
--- @shortDescription Triggers event callbacks with provided arguments
202202
--- @param event string The event to fire
203203
--- @param ... any Additional arguments to pass to the callbacks
204204
--- @return table self The BaseElement instance
@@ -236,8 +236,8 @@ function BaseElement:handleEvent(event, ...)
236236
return false
237237
end
238238

239-
--- Observes a property and calls a callback when it changes
240-
--- @shortDescription Observes a property and calls a callback when it changes
239+
--- Sets up a property change observer with immediate callback registration
240+
--- @shortDescription Watches property changes with callback notification
241241
--- @param property string The property to observe
242242
--- @param callback function The callback to call when the property changes
243243
--- @return table self The BaseElement instance
@@ -246,8 +246,8 @@ function BaseElement:onChange(property, callback)
246246
return self
247247
end
248248

249-
--- Returns the base frame of the element
250-
--- @shortDescription Returns the base frame of the element
249+
--- Traverses parent chain to locate the root frame element
250+
--- @shortDescription Retrieves the root frame of this element's tree
251251
--- @return BaseFrame BaseFrame The base frame of the element
252252
function BaseElement:getBaseFrame()
253253
if self.parent then
@@ -256,8 +256,8 @@ function BaseElement:getBaseFrame()
256256
return self
257257
end
258258

259-
--- Destroys the element and cleans up all references
260-
--- @shortDescription Destroys the element and cleans up all references
259+
--- Removes the element from UI tree and cleans up resources
260+
--- @shortDescription Removes element and performs cleanup
261261
function BaseElement:destroy()
262262
if(self.parent) then
263263
self.parent:removeChild(self)
@@ -267,8 +267,8 @@ function BaseElement:destroy()
267267
self:setFocused(false)
268268
end
269269

270-
--- Requests a render update for this element
271-
--- @shortDescription Requests a render update for this element
270+
--- Propagates render request up the element tree
271+
--- @shortDescription Requests UI update for this element
272272
--- @return table self The BaseElement instance
273273
function BaseElement:updateRender()
274274
if(self.parent) then

src/elements/BaseFrame.lua

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local Render = require("render")
55
---@configDescription This is the base frame class. It is the root element of all elements and the only element without a parent.
66

77

8-
--- This is the base frame class. It is the root element of all elements and the only element without a parent.
8+
--- This is the root frame class that serves as the foundation for the UI hierarchy. It manages the rendering context and acts as the top-level container for all other elements. Unlike other elements, it renders directly to a terminal or monitor and does not require a parent element.
99
---@class BaseFrame : Container
1010
---@field _render Render The render object
1111
---@field _renderUpdate boolean Whether the render object needs to be updated
@@ -110,22 +110,31 @@ function BaseFrame:textBg(x, y, text, bg)
110110
self._render:textBg(x, y, text, bg)
111111
end
112112

113-
--- @shortDescription Renders a text with a background color to the render Object
113+
--- @shortDescription Draws plain text to the render Object
114114
--- @param x number The x position to render to
115115
--- @param y number The y position to render to
116116
--- @param text string The text to render
117-
--- @param bg colors The background color
118117
--- @protected
119118
function BaseFrame:drawText(x, y, text)
120119
if x < 1 then text = string.sub(text, 1 - x); x = 1 end
121120
self._render:text(x, y, text)
122121
end
123122

123+
--- @shortDescription Draws a foreground color to the render Object
124+
--- @param x number The x position to render to
125+
--- @param y number The y position to render to
126+
--- @param fg colors The foreground color
127+
--- @protected
124128
function BaseFrame:drawFg(x, y, fg)
125129
if x < 1 then fg = string.sub(fg, 1 - x); x = 1 end
126130
self._render:fg(x, y, fg)
127131
end
128132

133+
--- @shortDescription Draws a background color to the render Object
134+
--- @param x number The x position to render to
135+
--- @param y number The y position to render to
136+
--- @param bg colors The background color
137+
--- @protected
129138
function BaseFrame:drawBg(x, y, bg)
130139
if x < 1 then bg = string.sub(bg, 1 - x); x = 1 end
131140
self._render:bg(x, y, bg)

src/elements/BigFont.lua

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,22 +145,34 @@ local VisualElement = elementManager.getElement("VisualElement")
145145
---@cofnigDescription The BigFont is a text element that displays large text.
146146
---@configDefault false
147147

148-
--- The BigFont element is a text element that displays larger text. It uses Wojbie's BigFont API to render the text in a larger font size. Credits to Wojbie for the original API.
149-
--- @run local basalt = require("basalt")
150-
--- @run local main = basalt.getMainFrame()
151-
--- @run local font = main:addBigFont()
152-
--- @run font:setText("Hello World!")
153-
--- @run basalt.run()
148+
--- A specialized text element that renders characters in larger sizes using Wojbie's BigFont API. Supports multiple font sizes and custom colors while maintaining the pixel-art style of ComputerCraft. Ideal for headers, titles, and emphasis text.
149+
--- @usage -- Create a large welcome message
150+
--- @usage local main = basalt.getMainFrame()
151+
--- @usage local title = main:addBigFont()
152+
--- @usage :setPosition(3, 3)
153+
--- @usage :setFontSize(2) -- Makes text twice as large
154+
--- @usage :setText("Welcome!")
155+
--- @usage :setForeground(colors.yellow) -- Make text yellow
156+
--- @usage
157+
--- @usage -- For animated text
158+
--- @usage basalt.schedule(function()
159+
--- @usage while true do
160+
--- @usage title:setForeground(colors.yellow)
161+
--- @usage sleep(0.5)
162+
--- @usage title:setForeground(colors.orange)
163+
--- @usage sleep(0.5)
164+
--- @usage end
165+
--- @usage end)
154166
---@class BigFont : VisualElement
155167
local BigFont = setmetatable({}, VisualElement)
156168
BigFont.__index = BigFont
157169

158-
---@property text string BigFont BigFont text
170+
---@property text string BigFont The text string to display in enlarged format
159171
BigFont.defineProperty(BigFont, "text", {default = "BigFont", type = "string", canTriggerRender = true, setter=function(self, value)
160172
self.bigfontText = makeText(self.get("fontSize"), value, self.get("foreground"), self.get("background"))
161173
return value
162174
end})
163-
---@property fontSize number 1 The font size of the BigFont
175+
---@property fontSize number 1 Scale factor for text size (1-3, where 1 is 3x3 pixels per character)
164176
BigFont.defineProperty(BigFont, "fontSize", {default = 1, type = "number", canTriggerRender = true, setter=function(self, value)
165177
self.bigfontText = makeText(value, self.get("text"), self.get("foreground"), self.get("background"))
166178
return value

src/elements/Button.lua

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,34 @@
11
local elementManager = require("elementManager")
22
local VisualElement = elementManager.getElement("VisualElement")
33
local getCenteredPosition = require("libraries/utils").getCenteredPosition
4-
---@cofnigDescription The Button is a standard button element with click handling and state management.
4+
---@configDescription The Button is a standard button element with click handling and state management.
55

6-
--- The Button is a standard button element with click handling and state management.
6+
--- A clickable interface element that triggers actions when pressed. Supports text labels, custom styling, and automatic text centering. Commonly used for user interactions and form submissions.
7+
--- @usage -- Create a simple action button
8+
--- @usage local button = parent:addButton()
9+
--- @usage :setPosition(5, 5)
10+
--- @usage :setText("Click me!")
11+
--- @usage :setBackground(colors.blue)
12+
--- @usage :setForeground(colors.white)
13+
--- @usage
14+
--- @usage -- Add click handling
15+
--- @usage button:onClick(function(self, button, x, y)
16+
--- @usage -- Change appearance when clicked
17+
--- @usage self:setBackground(colors.green)
18+
--- @usage self:setText("Success!")
19+
--- @usage
20+
--- @usage -- Revert after delay
21+
--- @usage basalt.schedule(function()
22+
--- @usage sleep(1)
23+
--- @usage self:setBackground(colors.blue)
24+
--- @usage self:setText("Click me!")
25+
--- @usage end)
26+
--- @usage end)
727
---@class Button : VisualElement
828
local Button = setmetatable({}, VisualElement)
929
Button.__index = Button
1030

11-
---@property text string Button Button text
31+
---@property text string Button Label text displayed centered within the button
1232
Button.defineProperty(Button, "text", {default = "Button", type = "string", canTriggerRender = true})
1333

1434
Button.defineEvent(Button, "mouse_click")

src/elements/CheckBox.lua

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
local VisualElement = require("elements/VisualElement")
2-
---@cofnigDescription This is a checkbox. It is a visual element that can be checked.
2+
---@configDescription This is a checkbox. It is a visual element that can be checked.
33

4-
--- The CheckBox is a visual element that can be checked.
5-
---@class CheckBox : VisualElement
4+
--- A toggleable UI element that can be checked or unchecked. Displays different text based on its state and supports automatic sizing. Commonly used in forms and settings interfaces for boolean options.
5+
--- @usage -- Create a checkbox for a setting
6+
--- @usage local checkbox = parent:addCheckBox()
7+
--- @usage :setText("Enable Feature")
8+
--- @usage :setCheckedText("✓")
9+
--- @usage :onChange("checked", function(self, checked)
10+
--- @usage -- React to checkbox state changes
11+
--- @usage if checked then
12+
--- @usage -- Handle enabled state
13+
--- @usage else
14+
--- @usage -- Handle disabled state
15+
--- @usage end
16+
--- @usage end)
17+
--- @class CheckBox : VisualElement
618
local CheckBox = setmetatable({}, VisualElement)
719
CheckBox.__index = CheckBox
820

9-
---@property checked boolean Whether checkbox is checked
21+
---@property checked boolean false The current state of the checkbox (true=checked, false=unchecked)
1022
CheckBox.defineProperty(CheckBox, "checked", {default = false, type = "boolean", canTriggerRender = true})
11-
---@property text string empty Text to display
23+
---@property text string empty Text shown when the checkbox is unchecked
1224
CheckBox.defineProperty(CheckBox, "text", {default = " ", type = "string", canTriggerRender = true, setter=function(self, value)
1325
local checkedText = self.get("checkedText")
1426
local width = math.max(#value, #checkedText)
@@ -17,7 +29,7 @@ CheckBox.defineProperty(CheckBox, "text", {default = " ", type = "string", canTr
1729
end
1830
return value
1931
end})
20-
---@property checkedText string Text when checked
32+
---@property checkedText string x Text shown when the checkbox is checked
2133
CheckBox.defineProperty(CheckBox, "checkedText", {default = "x", type = "string", canTriggerRender = true, setter=function(self, value)
2234
local text = self.get("text")
2335
local width = math.max(#value, #text)
@@ -26,7 +38,7 @@ CheckBox.defineProperty(CheckBox, "checkedText", {default = "x", type = "string"
2638
end
2739
return value
2840
end})
29-
---@property autoSize boolean true Whether to automatically size the checkbox
41+
---@property autoSize boolean true Automatically adjusts width based on text length
3042
CheckBox.defineProperty(CheckBox, "autoSize", {default = true, type = "boolean"})
3143

3244
CheckBox.defineEvent(CheckBox, "mouse_click")
@@ -51,7 +63,8 @@ function CheckBox:init(props, basalt)
5163
self.set("type", "CheckBox")
5264
end
5365

54-
--- @shortDescription Handles mouse click events
66+
--- Handles mouse interactions to toggle the checkbox state
67+
--- @shortDescription Toggles checked state on mouse click
5568
--- @param button number The button that was clicked
5669
--- @param x number The x position of the click
5770
--- @param y number The y position of the click

0 commit comments

Comments
 (0)