From 007ccfbdb5ef386167e4143e6dc0f921dc68e829 Mon Sep 17 00:00:00 2001 From: Robert Jelic <36573031+NoryiE@users.noreply.github.com> Date: Tue, 4 Mar 2025 10:37:42 +0100 Subject: [PATCH] Small Dropdown fix --- examples/graphs.lua | 40 +++++++++++++++++++++++++++++++++++++++ src/elements/Dropdown.lua | 10 ++++------ src/elements/List.lua | 2 +- 3 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 examples/graphs.lua diff --git a/examples/graphs.lua b/examples/graphs.lua new file mode 100644 index 0000000..0917357 --- /dev/null +++ b/examples/graphs.lua @@ -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() + diff --git a/src/elements/Dropdown.lua b/src/elements/Dropdown.lua index 75e9712..72941b9 100644 --- a/src/elements/Dropdown.lua +++ b/src/elements/Dropdown.lua @@ -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"), diff --git a/src/elements/List.lua b/src/elements/List.lua index 3cf7363..c64dfb4 100644 --- a/src/elements/List.lua +++ b/src/elements/List.lua @@ -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")