only add padding to the node being moved

This keeps the surface more stable as we move things around.
This commit is contained in:
Kartik K. Agaram 2023-12-13 08:23:20 -08:00
parent a7b9c3c808
commit 99035b22f9
2 changed files with 10 additions and 4 deletions

View File

@ -25,7 +25,7 @@ on.mouse_press = function(x,y, mouse_button)
local node = on_handle(x,y)
if node then
-- move node
prepare_to_move()
prepare_to_move(node)
Move = {xoff=App.mouse_x()-vx(node.x), yoff=App.mouse_y()-vy(node.y), node=node}
return
end

View File

@ -1,11 +1,17 @@
prepare_to_move = function()
-- pad out one node fully, and all other nodes just enough to keep them from overlapping.
-- We don't want cascading movements to get too chaotic.
prepare_to_move = function(target)
for _,def in pairs(Definitions) do
assert(def.w)
assert(def.h)
if def.pos == nil then def.pos = {} end
if def.hs == nil then def.hs = {} end
def.hs.x = def.w/2 + 50
def.hs.y = def.h/2 + math.max(60, math.min(def.h/3, 200))
def.hs.x = def.w/2
def.hs.y = def.h/2 + 30
if def == target then
def.hs.x = def.hs.x + 50
def.hs.y = def.hs.y + math.max(30, math.min(def.h/3, 200))
end
def.pos.x = def.x + def.hs.x
def.pos.y = def.y + def.hs.y
end