Added custom coloring for tree nodes
This commit is contained in:
8
.gitignore
vendored
8
.gitignore
vendored
@@ -9,4 +9,10 @@ testWorkflows
|
|||||||
todo.txt
|
todo.txt
|
||||||
Flexbox2.lua
|
Flexbox2.lua
|
||||||
markdown.lua
|
markdown.lua
|
||||||
markdown2.lua
|
markdown2.lua
|
||||||
|
SplitPane.lua
|
||||||
|
Accordion.lua
|
||||||
|
Stepper.lua
|
||||||
|
Drawer.lua
|
||||||
|
Breadcrumb.lua
|
||||||
|
Dialog.lua
|
||||||
@@ -2,7 +2,6 @@ local elementManager = require("elementManager")
|
|||||||
local VisualElement = require("elements/VisualElement")
|
local VisualElement = require("elements/VisualElement")
|
||||||
local Container = elementManager.getElement("Container")
|
local Container = elementManager.getElement("Container")
|
||||||
local tHex = require("libraries/colorHex")
|
local tHex = require("libraries/colorHex")
|
||||||
local log = require("log")
|
|
||||||
---@configDescription A SideNav element that provides sidebar navigation with multiple content areas.
|
---@configDescription A SideNav element that provides sidebar navigation with multiple content areas.
|
||||||
|
|
||||||
--- The SideNav is a container that provides sidebar navigation functionality
|
--- The SideNav is a container that provides sidebar navigation functionality
|
||||||
@@ -27,7 +26,7 @@ SideNav.defineProperty(SideNav, "activeTabBackground", {default = colors.white,
|
|||||||
SideNav.defineProperty(SideNav, "activeTabTextColor", {default = colors.black, type = "color", canTriggerRender = true})
|
SideNav.defineProperty(SideNav, "activeTabTextColor", {default = colors.black, type = "color", canTriggerRender = true})
|
||||||
---@property sidebarScrollOffset number 0 Current scroll offset for navigation items in scrollable mode
|
---@property sidebarScrollOffset number 0 Current scroll offset for navigation items in scrollable mode
|
||||||
SideNav.defineProperty(SideNav, "sidebarScrollOffset", {default = 0, type = "number", canTriggerRender = true})
|
SideNav.defineProperty(SideNav, "sidebarScrollOffset", {default = 0, type = "number", canTriggerRender = true})
|
||||||
---@property sidebarPosition string "left" Position of the sidebar ("left" or "right")
|
---@property sidebarPosition string left Position of the sidebar ("left" or "right")
|
||||||
SideNav.defineProperty(SideNav, "sidebarPosition", {default = "left", type = "string", canTriggerRender = true})
|
SideNav.defineProperty(SideNav, "sidebarPosition", {default = "left", type = "string", canTriggerRender = true})
|
||||||
|
|
||||||
SideNav.defineEvent(SideNav, "mouse_click")
|
SideNav.defineEvent(SideNav, "mouse_click")
|
||||||
@@ -198,7 +197,7 @@ function SideNav:_getSidebarMetrics()
|
|||||||
|
|
||||||
for i, tab in ipairs(tabs) do
|
for i, tab in ipairs(tabs) do
|
||||||
local itemHeight = 1
|
local itemHeight = 1
|
||||||
|
|
||||||
local visualY = actualY - scrollOffset
|
local visualY = actualY - scrollOffset
|
||||||
local startClip = 0
|
local startClip = 0
|
||||||
local endClip = 0
|
local endClip = 0
|
||||||
@@ -255,14 +254,14 @@ function SideNav:mouse_click(button, x, y)
|
|||||||
local baseRelX, baseRelY = VisualElement.getRelativePosition(self, x, y)
|
local baseRelX, baseRelY = VisualElement.getRelativePosition(self, x, y)
|
||||||
local metrics = self:_getSidebarMetrics()
|
local metrics = self:_getSidebarMetrics()
|
||||||
local width = self.get("width") or 1
|
local width = self.get("width") or 1
|
||||||
|
|
||||||
local inSidebar = false
|
local inSidebar = false
|
||||||
if metrics.sidebarPosition == "right" then
|
if metrics.sidebarPosition == "right" then
|
||||||
inSidebar = baseRelX > (width - metrics.sidebarWidth)
|
inSidebar = baseRelX > (width - metrics.sidebarWidth)
|
||||||
else
|
else
|
||||||
inSidebar = baseRelX <= metrics.sidebarWidth
|
inSidebar = baseRelX <= metrics.sidebarWidth
|
||||||
end
|
end
|
||||||
|
|
||||||
if inSidebar then
|
if inSidebar then
|
||||||
if #metrics.positions == 0 then return true end
|
if #metrics.positions == 0 then return true end
|
||||||
for _, pos in ipairs(metrics.positions) do
|
for _, pos in ipairs(metrics.positions) do
|
||||||
@@ -280,7 +279,7 @@ end
|
|||||||
function SideNav:getRelativePosition(x, y)
|
function SideNav:getRelativePosition(x, y)
|
||||||
local metrics = self:_getSidebarMetrics()
|
local metrics = self:_getSidebarMetrics()
|
||||||
local width = self.get("width") or 1
|
local width = self.get("width") or 1
|
||||||
|
|
||||||
if x == nil or y == nil then
|
if x == nil or y == nil then
|
||||||
return VisualElement.getRelativePosition(self)
|
return VisualElement.getRelativePosition(self)
|
||||||
else
|
else
|
||||||
@@ -363,14 +362,14 @@ function SideNav:mouse_up(button, x, y)
|
|||||||
local baseRelX, baseRelY = VisualElement.getRelativePosition(self, x, y)
|
local baseRelX, baseRelY = VisualElement.getRelativePosition(self, x, y)
|
||||||
local metrics = self:_getSidebarMetrics()
|
local metrics = self:_getSidebarMetrics()
|
||||||
local width = self.get("width") or 1
|
local width = self.get("width") or 1
|
||||||
|
|
||||||
local inSidebar = false
|
local inSidebar = false
|
||||||
if metrics.sidebarPosition == "right" then
|
if metrics.sidebarPosition == "right" then
|
||||||
inSidebar = baseRelX > (width - metrics.sidebarWidth)
|
inSidebar = baseRelX > (width - metrics.sidebarWidth)
|
||||||
else
|
else
|
||||||
inSidebar = baseRelX <= metrics.sidebarWidth
|
inSidebar = baseRelX <= metrics.sidebarWidth
|
||||||
end
|
end
|
||||||
|
|
||||||
if inSidebar then
|
if inSidebar then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@@ -382,14 +381,14 @@ function SideNav:mouse_release(button, x, y)
|
|||||||
local baseRelX, baseRelY = VisualElement.getRelativePosition(self, x, y)
|
local baseRelX, baseRelY = VisualElement.getRelativePosition(self, x, y)
|
||||||
local metrics = self:_getSidebarMetrics()
|
local metrics = self:_getSidebarMetrics()
|
||||||
local width = self.get("width") or 1
|
local width = self.get("width") or 1
|
||||||
|
|
||||||
local inSidebar = false
|
local inSidebar = false
|
||||||
if metrics.sidebarPosition == "right" then
|
if metrics.sidebarPosition == "right" then
|
||||||
inSidebar = baseRelX > (width - metrics.sidebarWidth)
|
inSidebar = baseRelX > (width - metrics.sidebarWidth)
|
||||||
else
|
else
|
||||||
inSidebar = baseRelX <= metrics.sidebarWidth
|
inSidebar = baseRelX <= metrics.sidebarWidth
|
||||||
end
|
end
|
||||||
|
|
||||||
if inSidebar then
|
if inSidebar then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -401,14 +400,14 @@ function SideNav:mouse_move(_, x, y)
|
|||||||
local baseRelX, baseRelY = VisualElement.getRelativePosition(self, x, y)
|
local baseRelX, baseRelY = VisualElement.getRelativePosition(self, x, y)
|
||||||
local metrics = self:_getSidebarMetrics()
|
local metrics = self:_getSidebarMetrics()
|
||||||
local width = self.get("width") or 1
|
local width = self.get("width") or 1
|
||||||
|
|
||||||
local inSidebar = false
|
local inSidebar = false
|
||||||
if metrics.sidebarPosition == "right" then
|
if metrics.sidebarPosition == "right" then
|
||||||
inSidebar = baseRelX > (width - metrics.sidebarWidth)
|
inSidebar = baseRelX > (width - metrics.sidebarWidth)
|
||||||
else
|
else
|
||||||
inSidebar = baseRelX <= metrics.sidebarWidth
|
inSidebar = baseRelX <= metrics.sidebarWidth
|
||||||
end
|
end
|
||||||
|
|
||||||
if inSidebar then
|
if inSidebar then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@@ -426,14 +425,14 @@ function SideNav:mouse_drag(button, x, y)
|
|||||||
local baseRelX, baseRelY = VisualElement.getRelativePosition(self, x, y)
|
local baseRelX, baseRelY = VisualElement.getRelativePosition(self, x, y)
|
||||||
local metrics = self:_getSidebarMetrics()
|
local metrics = self:_getSidebarMetrics()
|
||||||
local width = self.get("width") or 1
|
local width = self.get("width") or 1
|
||||||
|
|
||||||
local inSidebar = false
|
local inSidebar = false
|
||||||
if metrics.sidebarPosition == "right" then
|
if metrics.sidebarPosition == "right" then
|
||||||
inSidebar = baseRelX > (width - metrics.sidebarWidth)
|
inSidebar = baseRelX > (width - metrics.sidebarWidth)
|
||||||
else
|
else
|
||||||
inSidebar = baseRelX <= metrics.sidebarWidth
|
inSidebar = baseRelX <= metrics.sidebarWidth
|
||||||
end
|
end
|
||||||
|
|
||||||
if inSidebar then
|
if inSidebar then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@@ -487,7 +486,7 @@ function SideNav:setCursor(x, y, blink, color)
|
|||||||
if self.parent then
|
if self.parent then
|
||||||
local xPos, yPos = self:calculatePosition()
|
local xPos, yPos = self:calculatePosition()
|
||||||
local targetX, targetY
|
local targetX, targetY
|
||||||
|
|
||||||
if metrics.sidebarPosition == "right" then
|
if metrics.sidebarPosition == "right" then
|
||||||
targetX = x + xPos - 1
|
targetX = x + xPos - 1
|
||||||
targetY = y + yPos - 1
|
targetY = y + yPos - 1
|
||||||
@@ -513,14 +512,12 @@ function SideNav:render()
|
|||||||
local metrics = self:_getSidebarMetrics()
|
local metrics = self:_getSidebarMetrics()
|
||||||
local sidebarW = metrics.sidebarWidth or 12
|
local sidebarW = metrics.sidebarWidth or 12
|
||||||
|
|
||||||
-- Render sidebar background
|
|
||||||
for y = 1, height do
|
for y = 1, height do
|
||||||
VisualElement.multiBlit(self, 1, y, sidebarW, 1, " ", tHex[self.get("foreground")], tHex[self.get("sidebarBackground")])
|
VisualElement.multiBlit(self, 1, y, sidebarW, 1, " ", tHex[self.get("foreground")], tHex[self.get("sidebarBackground")])
|
||||||
end
|
end
|
||||||
|
|
||||||
local activeTab = self.get("activeTab")
|
local activeTab = self.get("activeTab")
|
||||||
|
|
||||||
-- Render navigation items
|
|
||||||
for _, pos in ipairs(metrics.positions) do
|
for _, pos in ipairs(metrics.positions) do
|
||||||
local bgColor = (pos.id == activeTab) and self.get("activeTabBackground") or self.get("sidebarBackground")
|
local bgColor = (pos.id == activeTab) and self.get("activeTabBackground") or self.get("sidebarBackground")
|
||||||
local fgColor = (pos.id == activeTab) and self.get("activeTabTextColor") or self.get("foreground")
|
local fgColor = (pos.id == activeTab) and self.get("activeTabTextColor") or self.get("foreground")
|
||||||
@@ -530,12 +527,11 @@ function SideNav:render()
|
|||||||
VisualElement.multiBlit(self, 1, pos.y1 + dy, sidebarW, 1, " ", tHex[self.get("foreground")], tHex[bgColor])
|
VisualElement.multiBlit(self, 1, pos.y1 + dy, sidebarW, 1, " ", tHex[self.get("foreground")], tHex[bgColor])
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Render title text (truncate if necessary)
|
|
||||||
local displayTitle = pos.title
|
local displayTitle = pos.title
|
||||||
if #displayTitle > sidebarW - 2 then
|
if #displayTitle > sidebarW - 2 then
|
||||||
displayTitle = displayTitle:sub(1, sidebarW - 2)
|
displayTitle = displayTitle:sub(1, sidebarW - 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
VisualElement.textFg(self, 2, pos.y1, displayTitle, fgColor)
|
VisualElement.textFg(self, 2, pos.y1, displayTitle, fgColor)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -199,8 +199,8 @@ function Tree:render()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local isSelected = node == selectedNode
|
local isSelected = node == selectedNode
|
||||||
local _bg = isSelected and self.get("selectedBackgroundColor") or self.get("background")
|
local _bg = isSelected and self.get("selectedBackgroundColor") or (node.background or node.bg or self.get("background"))
|
||||||
local _fg = isSelected and self.get("selectedForegroundColor") or self.get("foreground")
|
local _fg = isSelected and self.get("selectedForegroundColor") or (node.foreground or node.fg or self.get("foreground"))
|
||||||
|
|
||||||
local fullText = indent .. symbol .. " " .. (node.text or "Node")
|
local fullText = indent .. symbol .. " " .. (node.text or "Node")
|
||||||
local text = sub(fullText, horizontalOffset + 1, horizontalOffset + self.get("width"))
|
local text = sub(fullText, horizontalOffset + 1, horizontalOffset + self.get("width"))
|
||||||
@@ -216,5 +216,4 @@ function Tree:render()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return Tree
|
||||||
return Tree
|
|
||||||
@@ -536,7 +536,6 @@ function VisualElement:render()
|
|||||||
local fgHex = tHex[self.get("foreground")]
|
local fgHex = tHex[self.get("foreground")]
|
||||||
local bgHex = tHex[self.get("background")]
|
local bgHex = tHex[self.get("background")]
|
||||||
self:multiBlit(1, 1, width, height, " ", fgHex, bgHex)
|
self:multiBlit(1, 1, width, height, " ", fgHex, bgHex)
|
||||||
-- Draw integrated border after background fill
|
|
||||||
if (self.get("borderTop") or self.get("borderBottom") or self.get("borderLeft") or self.get("borderRight")) then
|
if (self.get("borderTop") or self.get("borderBottom") or self.get("borderLeft") or self.get("borderRight")) then
|
||||||
local bColor = self.get("borderColor") or self.get("foreground")
|
local bColor = self.get("borderColor") or self.get("foreground")
|
||||||
local bHex = tHex[bColor] or fgHex
|
local bHex = tHex[bColor] or fgHex
|
||||||
|
|||||||
Reference in New Issue
Block a user