mirror of
https://github.com/Insality/druid
synced 2025-09-27 18:12:21 +02:00
Update example with new brand one
This commit is contained in:
29
example/examples/basic/drag/drag.lua
Normal file
29
example/examples/basic/drag/drag.lua
Normal file
@@ -0,0 +1,29 @@
|
||||
local component = require("druid.component")
|
||||
|
||||
---@class drag: druid.base_component
|
||||
---@field druid druid_instance
|
||||
local M = component.create("drag")
|
||||
|
||||
|
||||
---@param template string
|
||||
---@param nodes table<hash, node>
|
||||
function M:init(template, nodes)
|
||||
self.druid = self:get_druid(template, nodes)
|
||||
|
||||
-- Init drag and move the drag node on drag callback
|
||||
self.drag = self.druid:new_drag("drag/root", function(_, dx, dy)
|
||||
local position_x = gui.get(self.drag.node, "position.x")
|
||||
local position_y = gui.get(self.drag.node, "position.y")
|
||||
gui.set(self.drag.node, "position.x", position_x + dx)
|
||||
gui.set(self.drag.node, "position.y", position_y + dy)
|
||||
end)
|
||||
|
||||
-- Save start position for animation
|
||||
self.start_position = gui.get_position(self.drag.node)
|
||||
self.drag.on_drag_end:subscribe(function()
|
||||
gui.animate(self.drag.node, "position", self.start_position, gui.EASING_OUTBACK, 0.3)
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
return M
|
Reference in New Issue
Block a user