Skip to content

Commit 8fd37ee

Browse files
committed
removed scrollbar from tables
added enabled property
1 parent 1b467c4 commit 8fd37ee

File tree

9 files changed

+286
-217
lines changed

9 files changed

+286
-217
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ testWorkflows
99
todo.txt
1010
Flexbox2.lua
1111
markdown2.lua
12+
BasaltDoc

src/elements/BaseElement.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ BaseElement.defineProperty(BaseElement, "name", {default = "", type = "string"})
3131
--- @property eventCallbacks table BaseElement The event callbacks for the element
3232
BaseElement.defineProperty(BaseElement, "eventCallbacks", {default = {}, type = "table"})
3333

34+
--- @property enabled boolean BaseElement Whether the element is enabled or not
35+
BaseElement.defineProperty(BaseElement, "enabled", {default = true, type = "boolean" })
36+
3437
--- Registers a new event listener for the element (on class level)
3538
--- @shortDescription Registers a new event listener for the element (on class level)
3639
--- @param class table The class to register
@@ -215,6 +218,9 @@ end
215218
--- @return boolean? handled Whether the event was handled
216219
--- @protected
217220
function BaseElement:dispatchEvent(event, ...)
221+
if self.get("enabled") == false then
222+
return false
223+
end
218224
if self[event] then
219225
return self[event](self, ...)
220226
end

src/elements/Table.lua

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ function Table:render()
216216
local finalText = string.sub(paddedText, 1, col.width)
217217
local finalForeground = string.rep(tHex[self.get("foreground")], #finalText)
218218
local finalBackground = string.rep(tHex[bg], #finalText)
219-
219+
220220
self:blit(currentX, y, finalText, finalForeground, finalBackground)
221221
currentX = currentX + col.width
222222
end
@@ -226,27 +226,6 @@ function Table:render()
226226
string.rep(tHex[self.get("background")], self.get("width")))
227227
end
228228
end
229-
230-
if #data > height - 2 then
231-
local scrollbarHeight = height - 2
232-
local thumbSize = math.max(1, math.floor(scrollbarHeight * (height - 2) / #data))
233-
234-
local maxScroll = #data - (height - 2) + 1
235-
local scrollPercent = scrollOffset / maxScroll
236-
local thumbPos = 2 + math.floor(scrollPercent * (scrollbarHeight - thumbSize))
237-
238-
if scrollOffset >= maxScroll then
239-
thumbPos = height - thumbSize
240-
end
241-
242-
for y = 2, height do
243-
self:blit(self.get("width"), y, "\127", tHex[colors.gray], tHex[colors.gray])
244-
end
245-
246-
for y = thumbPos, math.min(height, thumbPos + thumbSize - 1) do
247-
self:blit(self.get("width"), y, "\127", tHex[colors.white], tHex[colors.white])
248-
end
249-
end
250229
end
251230

252231
return Table

src/elements/VisualElement.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ VisualElement.registerEventCallback(VisualElement, "ClickUp", "mouse_up", "mouse
9999
VisualElement.registerEventCallback(VisualElement, "Drag", "mouse_drag", "mouse_click", "mouse_up")
100100
VisualElement.registerEventCallback(VisualElement, "Scroll", "mouse_scroll")
101101
VisualElement.registerEventCallback(VisualElement, "Enter", "mouse_enter", "mouse_move")
102-
VisualElement.registerEventCallback(VisualElement, "LeEave", "mouse_leave", "mouse_move")
102+
VisualElement.registerEventCallback(VisualElement, "Leave", "mouse_leave", "mouse_move")
103103
VisualElement.registerEventCallback(VisualElement, "Focus", "focus", "blur")
104104
VisualElement.registerEventCallback(VisualElement, "Blur", "blur", "focus")
105105
VisualElement.registerEventCallback(VisualElement, "Key", "key", "key_up")

tools/BasaltDoc/Button.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ function Button.new()
2626
return self
2727
end
2828

29+
--- Initializes the Button instance
2930
--- @shortDescription Initializes the Button instance
3031
--- @param props table The properties to initialize the element with
3132
--- @param basalt table The basalt instance
Lines changed: 51 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,81 @@
11
local CommentExtractor = {}
22

3-
--- Extracts comments with their associated code context
4-
-- @param lines table The lines of the Lua file as a table of strings.
5-
-- @return table A table containing comment blocks with context.
6-
function CommentExtractor.extractComments(lines)
3+
--- Extracts comment blocks that belong together
4+
function CommentExtractor.extractBlocks(lines)
75
local blocks = {}
8-
local currentCommentBlock = {}
9-
local i = 1
6+
local currentBlock = {
7+
comments = {},
8+
codeContext = nil
9+
}
1010

11+
local i = 1
1112
while i <= #lines do
12-
local line = lines[i]:match("^%s*(.*)") -- Trim leading whitespace
13+
local line = lines[i]
14+
local trimmed = line:match("^%s*(.-)%s*$")
1315

1416
-- Check if this is a comment line
15-
if line:find("^%-%-%-") or line:find("^%-%-") then
16-
table.insert(currentCommentBlock, line)
17-
elseif #currentCommentBlock > 0 then
18-
-- We have accumulated comments, check if next non-empty line is code
19-
local codeContext = nil
20-
local j = i
21-
22-
-- Skip empty lines to find the actual code
23-
while j <= #lines and lines[j]:match("^%s*$") do
24-
j = j + 1
17+
if trimmed:match("^%-%-%-") or trimmed:match("^%-%-") then
18+
table.insert(currentBlock.comments, trimmed)
19+
elseif #currentBlock.comments > 0 then
20+
-- We have comments, now look for the code that follows
21+
local codeLineIndex = CommentExtractor.findNextCodeLine(lines, i)
22+
if codeLineIndex then
23+
local codeLine = lines[codeLineIndex]:match("^%s*(.-)%s*$")
24+
currentBlock.codeContext = CommentExtractor.analyzeCode(codeLine, codeLineIndex)
2525
end
2626

27-
if j <= #lines then
28-
local codeLine = lines[j]:match("^%s*(.*)")
29-
-- Check if it's a function, class, property, etc.
30-
if codeLine:find("^function") or
31-
codeLine:find("^local function") or
32-
codeLine:find("^local%s+%w+%s*=") or
33-
codeLine:find("^%w+%.%w+") then
34-
codeContext = {
35-
type = CommentExtractor.getCodeType(codeLine),
36-
name = CommentExtractor.extractName(codeLine),
37-
line = codeLine,
38-
lineNumber = j
39-
}
40-
end
41-
end
42-
43-
-- Add the comment block with its context
44-
table.insert(blocks, {
45-
comments = currentCommentBlock,
46-
context = codeContext
47-
})
48-
49-
currentCommentBlock = {}
27+
-- Save this block and start a new one
28+
table.insert(blocks, currentBlock)
29+
currentBlock = {comments = {}, codeContext = nil}
5030
end
5131

5232
i = i + 1
5333
end
5434

55-
-- Handle any remaining comments
56-
if #currentCommentBlock > 0 then
57-
table.insert(blocks, {
58-
comments = currentCommentBlock,
59-
context = nil
60-
})
35+
-- Handle remaining comments
36+
if #currentBlock.comments > 0 then
37+
table.insert(blocks, currentBlock)
6138
end
6239

6340
return blocks
6441
end
6542

66-
--- Determines the type of code (function, class, property, etc.)
67-
function CommentExtractor.getCodeType(codeLine)
68-
if codeLine:find("^function") or codeLine:find("^local function") then
69-
return "function"
70-
elseif codeLine:find("^local%s+%w+%s*=%s*setmetatable") then
71-
return "class"
72-
elseif codeLine:find("^local%s+%w+%s*=") then
73-
return "variable"
74-
elseif codeLine:find("^%w+%.defineProperty") then
75-
return "property_definition"
76-
else
77-
return "unknown"
43+
--- Find the next non-empty code line
44+
function CommentExtractor.findNextCodeLine(lines, startIndex)
45+
for i = startIndex, #lines do
46+
local trimmed = lines[i]:match("^%s*(.-)%s*$")
47+
if trimmed ~= "" and not trimmed:match("^%-%-") then
48+
return i
49+
end
7850
end
51+
return nil
7952
end
8053

81-
--- Extracts the name from a code line
82-
function CommentExtractor.extractName(codeLine)
54+
--- Analyze what kind of code this is
55+
function CommentExtractor.analyzeCode(codeLine, lineNumber)
8356
-- Function patterns
84-
local funcName = codeLine:match("^function%s+([%w%.%:]+)")
85-
if funcName then return funcName end
57+
if codeLine:match("^function%s+([%w%.%:]+)") then
58+
local name = codeLine:match("^function%s+([%w%.%:]+)")
59+
return {type = "function", name = name, line = codeLine, lineNumber = lineNumber}
60+
end
8661

87-
local localFuncName = codeLine:match("^local%s+function%s+([%w%.%:]+)")
88-
if localFuncName then return localFuncName end
62+
if codeLine:match("^local%s+function%s+([%w%.%:]+)") then
63+
local name = codeLine:match("^local%s+function%s+([%w%.%:]+)")
64+
return {type = "function", name = name, line = codeLine, lineNumber = lineNumber}
65+
end
8966

90-
-- Variable/class patterns
91-
local varName = codeLine:match("^local%s+([%w_]+)%s*=")
92-
if varName then return varName end
67+
-- Class/variable patterns
68+
if codeLine:match("^local%s+([%w_]+)%s*=%s*setmetatable") then
69+
local name = codeLine:match("^local%s+([%w_]+)%s*=")
70+
return {type = "class", name = name, line = codeLine, lineNumber = lineNumber}
71+
end
9372

94-
-- Method patterns
95-
local methodName = codeLine:match("^([%w%.%:]+)%s*=")
96-
if methodName then return methodName end
73+
if codeLine:match("^local%s+([%w_]+)%s*=") then
74+
local name = codeLine:match("^local%s+([%w_]+)%s*=")
75+
return {type = "variable", name = name, line = codeLine, lineNumber = lineNumber}
76+
end
9777

98-
return "unknown"
78+
return {type = "unknown", name = "unknown", line = codeLine, lineNumber = lineNumber}
9979
end
10080

10181
return CommentExtractor
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local CommentExtractor = require("parser.comment_extractor")
2+
local TagParser = require("parser.tag_parser")
23
local MarkdownGenerator = require("parser.markdown_generator")
34

45
local Parser = {}
@@ -9,21 +10,23 @@ function Parser.extractComments(content)
910
for line in content:gmatch("[^\r\n]+") do
1011
table.insert(lines, line)
1112
end
12-
return CommentExtractor.extractComments(lines)
13+
return CommentExtractor.extractBlocks(lines)
1314
end
1415

1516
--- Generate markdown from comment blocks
1617
function Parser.generateMarkdown(commentBlocks)
17-
local parsedBlocks = {}
18+
local markdown = {}
1819

19-
-- Parse each block using the appropriate parser
20+
-- Parse each block and generate markdown
2021
for _, block in ipairs(commentBlocks) do
21-
local parsedBlock = MarkdownGenerator.parseBlock(block)
22-
table.insert(parsedBlocks, parsedBlock)
22+
local tags = TagParser.parseAllTags(block.comments)
23+
local blockMarkdown = MarkdownGenerator.generateBlock(block, tags)
24+
if blockMarkdown and blockMarkdown ~= "" then
25+
table.insert(markdown, blockMarkdown)
26+
end
2327
end
2428

25-
-- Generate markdown from parsed blocks
26-
return MarkdownGenerator.generateMarkdown(parsedBlocks)
29+
return table.concat(markdown, "\n\n")
2730
end
2831

2932
return Parser

0 commit comments

Comments
 (0)