Bugfix
Fixed program only using relative path Fixed list not sending scroll events Added observer to scrollbar's :attach method Fixed vertical sliders
This commit is contained in:
@@ -167,6 +167,7 @@ function List:mouse_scroll(direction, x, y)
|
||||
|
||||
offset = math.min(maxOffset, math.max(0, offset + direction))
|
||||
self.set("offset", offset)
|
||||
self:fireEvent("mouse_scroll", direction, x, y)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
|
||||
@@ -43,7 +43,7 @@ end
|
||||
---@private
|
||||
function BasaltProgram:run(path, width, height)
|
||||
self.window = window.create(self.program:getBaseFrame():getTerm(), 1, 1, width, height, false)
|
||||
local pPath = shell.resolveProgram(path)
|
||||
local pPath = shell.resolveProgram(path) or fs.exists(path) and path or nil
|
||||
if(pPath~=nil)then
|
||||
if(fs.exists(pPath)) then
|
||||
local file = fs.open(pPath, "r")
|
||||
@@ -68,7 +68,7 @@ function BasaltProgram:run(path, width, height)
|
||||
self.coroutine = coroutine.create(function()
|
||||
local program = load(content, "@/" .. path, nil, env)
|
||||
if program then
|
||||
local result = program(path, table.unpack(self.args))
|
||||
local result = program(table.unpack(self.args))
|
||||
return result
|
||||
end
|
||||
end)
|
||||
|
||||
@@ -76,6 +76,17 @@ function ScrollBar:attach(element, config)
|
||||
self.set("attachedProperty", config.property)
|
||||
self.set("minValue", config.min or 0)
|
||||
self.set("maxValue", config.max or 100)
|
||||
element:observe(config.property, function(_, value)
|
||||
if value then
|
||||
local min = self.get("minValue")
|
||||
local max = self.get("maxValue")
|
||||
if min == max then return end
|
||||
|
||||
self.set("value", math.floor(
|
||||
(value - min) / (max - min) * 100 + 0.5
|
||||
))
|
||||
end
|
||||
end)
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
local VisualElement = require("elements/VisualElement")
|
||||
local tHex = require("libraries/colorHex")
|
||||
|
||||
--- This is the slider class. It provides a draggable slider control that can be either horizontal or vertical,
|
||||
--- with customizable colors and value ranges.
|
||||
@@ -11,7 +12,13 @@ Slider.defineProperty(Slider, "step", {default = 1, type = "number", canTriggerR
|
||||
---@property max number 100 Maximum value for value conversion (maps slider position to this range)
|
||||
Slider.defineProperty(Slider, "max", {default = 100, type = "number"})
|
||||
---@property horizontal boolean true Whether the slider is horizontal (false for vertical)
|
||||
Slider.defineProperty(Slider, "horizontal", {default = true, type = "boolean", canTriggerRender = true})
|
||||
Slider.defineProperty(Slider, "horizontal", {default = true, type = "boolean", canTriggerRender = true, setter=function(self, value)
|
||||
if value then
|
||||
self.set("backgroundEnabled", false)
|
||||
else
|
||||
self.set("backgroundEnabled", true)
|
||||
end
|
||||
end})
|
||||
---@property barColor color gray Color of the slider track
|
||||
Slider.defineProperty(Slider, "barColor", {default = colors.gray, type = "color", canTriggerRender = true})
|
||||
---@property sliderColor color blue Color of the slider handle
|
||||
@@ -21,6 +28,7 @@ Slider.defineProperty(Slider, "sliderColor", {default = colors.blue, type = "col
|
||||
Slider.defineEvent(Slider, "mouse_click")
|
||||
Slider.defineEvent(Slider, "mouse_drag")
|
||||
Slider.defineEvent(Slider, "mouse_up")
|
||||
Slider.defineEvent(Slider, "mouse_scroll")
|
||||
|
||||
--- Creates a new Slider instance
|
||||
--- @shortDescription Creates a new Slider instance
|
||||
@@ -90,6 +98,7 @@ function Slider:mouse_scroll(direction, x, y)
|
||||
self:updateRender()
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
--- @shortDescription Renders the slider with track and handle
|
||||
@@ -101,17 +110,18 @@ function Slider:render()
|
||||
local horizontal = self.get("horizontal")
|
||||
local step = self.get("step")
|
||||
|
||||
local barChar = horizontal and "\140" or "│"
|
||||
local barChar = horizontal and "\140" or " "
|
||||
local text = string.rep(barChar, horizontal and width or height)
|
||||
|
||||
if horizontal then
|
||||
self:textFg(1, 1, text, self.get("barColor"))
|
||||
self:textBg(step, 1, " ", self.get("sliderColor"))
|
||||
else
|
||||
local bg = self.get("background")
|
||||
for y = 1, height do
|
||||
self:textFg(1, y, barChar, self.get("barColor"))
|
||||
self:textBg(1, y, " ", bg)
|
||||
end
|
||||
self:textFg(1, step, "\140", self.get("sliderColor"))
|
||||
self:textBg(1, step, " ", self.get("sliderColor"))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user