Skip to content

Commit dcc3dda

Browse files
committed
Added custom coloring for tree nodes
1 parent 57f8da9 commit dcc3dda

File tree

4 files changed

+25
-25
lines changed

4 files changed

+25
-25
lines changed

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,10 @@ testWorkflows
99
todo.txt
1010
Flexbox2.lua
1111
markdown.lua
12-
markdown2.lua
12+
markdown2.lua
13+
SplitPane.lua
14+
Accordion.lua
15+
Stepper.lua
16+
Drawer.lua
17+
Breadcrumb.lua
18+
Dialog.lua

src/elements/SideNav.lua

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ local elementManager = require("elementManager")
22
local VisualElement = require("elements/VisualElement")
33
local Container = elementManager.getElement("Container")
44
local tHex = require("libraries/colorHex")
5-
local log = require("log")
65
---@configDescription A SideNav element that provides sidebar navigation with multiple content areas.
76

87
--- The SideNav is a container that provides sidebar navigation functionality
@@ -27,7 +26,7 @@ SideNav.defineProperty(SideNav, "activeTabBackground", {default = colors.white,
2726
SideNav.defineProperty(SideNav, "activeTabTextColor", {default = colors.black, type = "color", canTriggerRender = true})
2827
---@property sidebarScrollOffset number 0 Current scroll offset for navigation items in scrollable mode
2928
SideNav.defineProperty(SideNav, "sidebarScrollOffset", {default = 0, type = "number", canTriggerRender = true})
30-
---@property sidebarPosition string "left" Position of the sidebar ("left" or "right")
29+
---@property sidebarPosition string left Position of the sidebar ("left" or "right")
3130
SideNav.defineProperty(SideNav, "sidebarPosition", {default = "left", type = "string", canTriggerRender = true})
3231

3332
SideNav.defineEvent(SideNav, "mouse_click")
@@ -198,7 +197,7 @@ function SideNav:_getSidebarMetrics()
198197

199198
for i, tab in ipairs(tabs) do
200199
local itemHeight = 1
201-
200+
202201
local visualY = actualY - scrollOffset
203202
local startClip = 0
204203
local endClip = 0
@@ -255,14 +254,14 @@ function SideNav:mouse_click(button, x, y)
255254
local baseRelX, baseRelY = VisualElement.getRelativePosition(self, x, y)
256255
local metrics = self:_getSidebarMetrics()
257256
local width = self.get("width") or 1
258-
257+
259258
local inSidebar = false
260259
if metrics.sidebarPosition == "right" then
261260
inSidebar = baseRelX > (width - metrics.sidebarWidth)
262261
else
263262
inSidebar = baseRelX <= metrics.sidebarWidth
264263
end
265-
264+
266265
if inSidebar then
267266
if #metrics.positions == 0 then return true end
268267
for _, pos in ipairs(metrics.positions) do
@@ -280,7 +279,7 @@ end
280279
function SideNav:getRelativePosition(x, y)
281280
local metrics = self:_getSidebarMetrics()
282281
local width = self.get("width") or 1
283-
282+
284283
if x == nil or y == nil then
285284
return VisualElement.getRelativePosition(self)
286285
else
@@ -363,14 +362,14 @@ function SideNav:mouse_up(button, x, y)
363362
local baseRelX, baseRelY = VisualElement.getRelativePosition(self, x, y)
364363
local metrics = self:_getSidebarMetrics()
365364
local width = self.get("width") or 1
366-
365+
367366
local inSidebar = false
368367
if metrics.sidebarPosition == "right" then
369368
inSidebar = baseRelX > (width - metrics.sidebarWidth)
370369
else
371370
inSidebar = baseRelX <= metrics.sidebarWidth
372371
end
373-
372+
374373
if inSidebar then
375374
return true
376375
end
@@ -382,14 +381,14 @@ function SideNav:mouse_release(button, x, y)
382381
local baseRelX, baseRelY = VisualElement.getRelativePosition(self, x, y)
383382
local metrics = self:_getSidebarMetrics()
384383
local width = self.get("width") or 1
385-
384+
386385
local inSidebar = false
387386
if metrics.sidebarPosition == "right" then
388387
inSidebar = baseRelX > (width - metrics.sidebarWidth)
389388
else
390389
inSidebar = baseRelX <= metrics.sidebarWidth
391390
end
392-
391+
393392
if inSidebar then
394393
return
395394
end
@@ -401,14 +400,14 @@ function SideNav:mouse_move(_, x, y)
401400
local baseRelX, baseRelY = VisualElement.getRelativePosition(self, x, y)
402401
local metrics = self:_getSidebarMetrics()
403402
local width = self.get("width") or 1
404-
403+
405404
local inSidebar = false
406405
if metrics.sidebarPosition == "right" then
407406
inSidebar = baseRelX > (width - metrics.sidebarWidth)
408407
else
409408
inSidebar = baseRelX <= metrics.sidebarWidth
410409
end
411-
410+
412411
if inSidebar then
413412
return true
414413
end
@@ -426,14 +425,14 @@ function SideNav:mouse_drag(button, x, y)
426425
local baseRelX, baseRelY = VisualElement.getRelativePosition(self, x, y)
427426
local metrics = self:_getSidebarMetrics()
428427
local width = self.get("width") or 1
429-
428+
430429
local inSidebar = false
431430
if metrics.sidebarPosition == "right" then
432431
inSidebar = baseRelX > (width - metrics.sidebarWidth)
433432
else
434433
inSidebar = baseRelX <= metrics.sidebarWidth
435434
end
436-
435+
437436
if inSidebar then
438437
return true
439438
end
@@ -487,7 +486,7 @@ function SideNav:setCursor(x, y, blink, color)
487486
if self.parent then
488487
local xPos, yPos = self:calculatePosition()
489488
local targetX, targetY
490-
489+
491490
if metrics.sidebarPosition == "right" then
492491
targetX = x + xPos - 1
493492
targetY = y + yPos - 1
@@ -513,14 +512,12 @@ function SideNav:render()
513512
local metrics = self:_getSidebarMetrics()
514513
local sidebarW = metrics.sidebarWidth or 12
515514

516-
-- Render sidebar background
517515
for y = 1, height do
518516
VisualElement.multiBlit(self, 1, y, sidebarW, 1, " ", tHex[self.get("foreground")], tHex[self.get("sidebarBackground")])
519517
end
520518

521519
local activeTab = self.get("activeTab")
522520

523-
-- Render navigation items
524521
for _, pos in ipairs(metrics.positions) do
525522
local bgColor = (pos.id == activeTab) and self.get("activeTabBackground") or self.get("sidebarBackground")
526523
local fgColor = (pos.id == activeTab) and self.get("activeTabTextColor") or self.get("foreground")
@@ -530,12 +527,11 @@ function SideNav:render()
530527
VisualElement.multiBlit(self, 1, pos.y1 + dy, sidebarW, 1, " ", tHex[self.get("foreground")], tHex[bgColor])
531528
end
532529

533-
-- Render title text (truncate if necessary)
534530
local displayTitle = pos.title
535531
if #displayTitle > sidebarW - 2 then
536532
displayTitle = displayTitle:sub(1, sidebarW - 2)
537533
end
538-
534+
539535
VisualElement.textFg(self, 2, pos.y1, displayTitle, fgColor)
540536
end
541537

src/elements/Tree.lua

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ function Tree:render()
199199
end
200200

201201
local isSelected = node == selectedNode
202-
local _bg = isSelected and self.get("selectedBackgroundColor") or self.get("background")
203-
local _fg = isSelected and self.get("selectedForegroundColor") or self.get("foreground")
202+
local _bg = isSelected and self.get("selectedBackgroundColor") or (node.background or node.bg or self.get("background"))
203+
local _fg = isSelected and self.get("selectedForegroundColor") or (node.foreground or node.fg or self.get("foreground"))
204204

205205
local fullText = indent .. symbol .. " " .. (node.text or "Node")
206206
local text = sub(fullText, horizontalOffset + 1, horizontalOffset + self.get("width"))
@@ -216,5 +216,4 @@ function Tree:render()
216216
end
217217
end
218218

219-
220-
return Tree
219+
return Tree

src/elements/VisualElement.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,6 @@ function VisualElement:render()
536536
local fgHex = tHex[self.get("foreground")]
537537
local bgHex = tHex[self.get("background")]
538538
self:multiBlit(1, 1, width, height, " ", fgHex, bgHex)
539-
-- Draw integrated border after background fill
540539
if (self.get("borderTop") or self.get("borderBottom") or self.get("borderLeft") or self.get("borderRight")) then
541540
local bColor = self.get("borderColor") or self.get("foreground")
542541
local bHex = tHex[bColor] or fgHex

0 commit comments

Comments
 (0)