Small Dropdown fix
This commit is contained in:
40
examples/graphs.lua
Normal file
40
examples/graphs.lua
Normal 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()
|
||||||
|
|
||||||
@@ -102,12 +102,10 @@ function Dropdown:render()
|
|||||||
VisualElement.render(self)
|
VisualElement.render(self)
|
||||||
|
|
||||||
local text = self.get("selectedText")
|
local text = self.get("selectedText")
|
||||||
if #text == 0 then
|
local selectedItems = self:getSelectedItems()
|
||||||
local selectedItems = self:getSelectedItems()
|
if #selectedItems > 0 then
|
||||||
if #selectedItems > 0 then
|
local selectedItem = selectedItems[1]
|
||||||
local selectedItem = selectedItems[1]
|
text = selectedItem.text or ""
|
||||||
text = selectedItem.text or ""
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
self:blit(1, 1, text .. string.rep(" ", self.get("width") - #text - 1) .. (self.get("isOpen") and "\31" or "\17"),
|
self:blit(1, 1, text .. string.rep(" ", self.get("width") - #text - 1) .. (self.get("isOpen") and "\31" or "\17"),
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ List.defineProperty(List, "selectedBackground", {default = colors.blue, type = "
|
|||||||
---@property selectedForeground color white Text color for selected items
|
---@property selectedForeground color white Text color for selected items
|
||||||
List.defineProperty(List, "selectedForeground", {default = colors.white, type = "color"})
|
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_click")
|
||||||
List.defineEvent(List, "mouse_scroll")
|
List.defineEvent(List, "mouse_scroll")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user