Small Dropdown fix

This commit is contained in:
Robert Jelic
2025-03-04 10:37:42 +01:00
parent c0b404d0cd
commit 007ccfbdb5
3 changed files with 45 additions and 7 deletions

40
examples/graphs.lua Normal file
View File

@@ -0,0 +1,40 @@
local basalt = require("basalt")
-- This is a simple example of a line chart. It shows how to create a line chart and add points to it.
local main = basalt.getMainFrame()
local graph = main:addLineChart()--or addBarChart()
-- Add two series to the graph
graph:addSeries("red", " ", colors.red, colors.red, 5)
graph:addSeries("blue", " ", colors.blue, colors.blue, 5)
-- Add some points to the red series
graph:addPoint("red", 1)
graph:addPoint("red", 12)
graph:addPoint("red", 50)
graph:addPoint("red", 20)
graph:addPoint("red", 60)
basalt.schedule(function()
while true do
sleep(2)
graph:addPoint("red", math.random(1, 100))
graph:addPoint("blue", math.random(1, 100))
end
end)
-- :focusSeries("red") makes the red series more important in the rendering order
-- :changeSeriesVisibility("red", false) changes the visibility of the red series without removing the ability to add new points
local vis = true
main:addButton()
:setPosition(40, 1)
:setText("Focus red")
:onClick(function()
--vis = not vis
--graph:changeSeriesVisibility("red", vis)
graph:focusSeries("red")
end)
basalt.run()

View File

@@ -102,12 +102,10 @@ function Dropdown:render()
VisualElement.render(self)
local text = self.get("selectedText")
if #text == 0 then
local selectedItems = self:getSelectedItems()
if #selectedItems > 0 then
local selectedItem = selectedItems[1]
text = selectedItem.text or ""
end
local selectedItems = self:getSelectedItems()
if #selectedItems > 0 then
local selectedItem = selectedItems[1]
text = selectedItem.text or ""
end
self:blit(1, 1, text .. string.rep(" ", self.get("width") - #text - 1) .. (self.get("isOpen") and "\31" or "\17"),

View File

@@ -20,7 +20,7 @@ List.defineProperty(List, "selectedBackground", {default = colors.blue, type = "
---@property selectedForeground color white Text color for selected items
List.defineProperty(List, "selectedForeground", {default = colors.white, type = "color"})
---@event onSelect {index number, item any} Fired when an item is selected
---@event onSelect {index number, item table} Fired when an item is selected
List.defineEvent(List, "mouse_click")
List.defineEvent(List, "mouse_scroll")