mirror of
https://github.com/Insality/druid.git
synced 2025-09-27 18:12:19 +02:00
Better scroll and slider API
This commit is contained in:
@@ -380,6 +380,29 @@ function M.scroll_to(self, point, is_instant)
|
||||
self.on_scroll_to:trigger(self:get_context(), point, is_instant)
|
||||
end
|
||||
|
||||
--- Start scroll to target scroll percent
|
||||
-- @function scroll:scroll_to_percent
|
||||
-- @tparam point vector3 target percent
|
||||
-- @tparam[opt] bool is_instant instant scroll flag
|
||||
-- @usage scroll:scroll_to_percent(vmath.vector3(0.5, 0, 0))
|
||||
function M.scroll_to_percent(self, percent, is_instant)
|
||||
local border = self.border
|
||||
|
||||
local size_x = math.abs(border.z - border.x)
|
||||
if size_x == 0 then
|
||||
size_x = 1
|
||||
end
|
||||
local size_y = math.abs(border.w - border.y)
|
||||
if size_y == 0 then
|
||||
size_y = 1
|
||||
end
|
||||
|
||||
local pos = vmath.vector3(
|
||||
-size_x * percent.x + border.x,
|
||||
-size_y * percent.y + border.y,
|
||||
0)
|
||||
M.scroll_to(self, pos, is_instant)
|
||||
end
|
||||
|
||||
--- Scroll to item in scroll by point index
|
||||
-- @function scroll:init
|
||||
@@ -450,4 +473,29 @@ function M.set_border(self, content_size)
|
||||
end
|
||||
|
||||
|
||||
--- Return current scroll progress
|
||||
-- @function scroll:get_scroll_percent
|
||||
-- @tparam table self Component instance
|
||||
-- @return vmath.vector3 Scroll progress
|
||||
function M.get_scroll_percent(self)
|
||||
local border = self.border
|
||||
local size_x = math.abs(border.z - border.x)
|
||||
if size_x == 0 then
|
||||
size_x = 1
|
||||
end
|
||||
|
||||
local size_y = math.abs(border.w - border.y)
|
||||
if size_y == 0 then
|
||||
size_y = 1
|
||||
end
|
||||
local pos = self.pos
|
||||
|
||||
return vmath.vector3(
|
||||
(border.x - pos.x) / size_x,
|
||||
(border.y - pos.y) / size_y,
|
||||
0
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
return M
|
||||
|
@@ -79,12 +79,14 @@ function M.on_input(self, action_id, action)
|
||||
end
|
||||
|
||||
|
||||
function M.set(self, value)
|
||||
function M.set(self, value, is_silent)
|
||||
value = helper.clamp(value, 0, 1)
|
||||
|
||||
gui.set_position(self.node, self.start_pos + self.dist * value)
|
||||
self.value = value
|
||||
on_change_value(self)
|
||||
if not is_silent then
|
||||
on_change_value(self)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user