Added in drag and drop capability. (#170)

This commit is contained in:
Adam 2021-05-02 03:13:21 -04:00 committed by GitHub
parent b42d9de0be
commit 67ec7e8065
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 2 deletions

View File

@ -597,6 +597,7 @@ function RootView:on_mouse_pressed(button, x, y, clicks)
if button == "middle" or node.hovered_close == idx then if button == "middle" or node.hovered_close == idx then
node:close_view(self.root_node, node.views[idx]) node:close_view(self.root_node, node.views[idx])
else else
self.dragged_node = idx
node:set_active_view(node.views[idx]) node:set_active_view(node.views[idx])
end end
else else
@ -610,6 +611,9 @@ function RootView:on_mouse_released(...)
if self.dragged_divider then if self.dragged_divider then
self.dragged_divider = nil self.dragged_divider = nil
end end
if self.dragged_node then
self.dragged_node = nil
end
self.root_node:on_mouse_released(...) self.root_node:on_mouse_released(...)
end end
@ -641,19 +645,26 @@ function RootView:on_mouse_moved(x, y, dx, dy)
node.divider = common.clamp(node.divider, 0.01, 0.99) node.divider = common.clamp(node.divider, 0.01, 0.99)
return return
end end
self.mouse.x, self.mouse.y = x, y self.mouse.x, self.mouse.y = x, y
self.root_node:on_mouse_moved(x, y, dx, dy) self.root_node:on_mouse_moved(x, y, dx, dy)
local node = self.root_node:get_child_overlapping_point(x, y) local node = self.root_node:get_child_overlapping_point(x, y)
local div = self.root_node:get_divider_overlapping_point(x, y) local div = self.root_node:get_divider_overlapping_point(x, y)
local tab_index = node and node:get_tab_overlapping_point(x, y)
if div then if div then
local axis = (div.type == "hsplit" and "x" or "y") local axis = (div.type == "hsplit" and "x" or "y")
if div.a:is_resizable(axis) and div.b:is_resizable(axis) then if div.a:is_resizable(axis) and div.b:is_resizable(axis) then
system.set_cursor(div.type == "hsplit" and "sizeh" or "sizev") system.set_cursor(div.type == "hsplit" and "sizeh" or "sizev")
end end
elseif node:get_tab_overlapping_point(x, y) then elseif tab_index then
system.set_cursor("arrow") system.set_cursor("arrow")
if self.dragged_node and self.dragged_node ~= tab_index then
local tab = node.views[self.dragged_node]
table.remove(node.views, self.dragged_node)
table.insert(node.views, tab_index, tab)
self.dragged_node = tab_index
end
else else
system.set_cursor(node.active_view.cursor) system.set_cursor(node.active_view.cursor)
end end