mock up affordances for moving and resizing
A node will take up as much vertical space as it needs given its text. But we can resize its width.
This commit is contained in:
parent
fc0f2f27aa
commit
bcb16bbd8d
|
@ -3,5 +3,15 @@ on.update = function(dt)
|
||||||
Viewport.x = Pan.x - App.mouse_x()/Viewport.zoom
|
Viewport.x = Pan.x - App.mouse_x()/Viewport.zoom
|
||||||
Viewport.y = Pan.y - App.mouse_y()/Viewport.zoom
|
Viewport.y = Pan.y - App.mouse_y()/Viewport.zoom
|
||||||
B()
|
B()
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local sx = sx(App.mouse_x())
|
||||||
|
local sy = sy(App.mouse_y())
|
||||||
|
if on_move_bar(sx, sy) then
|
||||||
|
set_mouse_cursor('crosshair')
|
||||||
|
elseif on_resize(sx, sy) then
|
||||||
|
set_mouse_cursor('sizewe')
|
||||||
|
else
|
||||||
|
set_mouse_cursor('arrow')
|
||||||
end
|
end
|
||||||
end
|
end
|
2
0019-B
2
0019-B
|
@ -1,9 +1,11 @@
|
||||||
B = function(preserve_screen_top_of_cursor_node)
|
B = function(preserve_screen_top_of_cursor_node)
|
||||||
|
print('B')
|
||||||
-- recompute various aspects based on the current viewport settings
|
-- recompute various aspects based on the current viewport settings
|
||||||
love.graphics.setFont(love.graphics.newFont(scale(20))) -- editor objects implicitly depend on current font so update it
|
love.graphics.setFont(love.graphics.newFont(scale(20))) -- editor objects implicitly depend on current font so update it
|
||||||
for _,obj in ipairs(Surface) do
|
for _,obj in ipairs(Surface) do
|
||||||
if obj.type == 'line' then
|
if obj.type == 'line' then
|
||||||
obj.zdata = {}
|
obj.zdata = {}
|
||||||
|
print('A', #obj.data)
|
||||||
for i=1,#obj.data,2 do
|
for i=1,#obj.data,2 do
|
||||||
table.insert(obj.zdata, vx(obj.data[i]))
|
table.insert(obj.zdata, vx(obj.data[i]))
|
||||||
table.insert(obj.zdata, vy(obj.data[i+1]))
|
table.insert(obj.zdata, vy(obj.data[i+1]))
|
||||||
|
|
|
@ -1,16 +1,17 @@
|
||||||
compute_layout = function(node, x,y, nodes_to_render, preserve_screen_top_of_cursor_node)
|
compute_layout = function(node, x,y, nodes_to_render, preserve_screen_top_of_cursor_node)
|
||||||
|
print('compute_layout')
|
||||||
-- append to nodes_to_render flattened instructions to render a hierarchy of nodes
|
-- append to nodes_to_render flattened instructions to render a hierarchy of nodes
|
||||||
-- return x,y rendered until (surface coordinates)
|
-- return x,y rendered until (surface coordinates)
|
||||||
if node.type == 'text' then
|
if node.type == 'text' then
|
||||||
-- leaf node containing raw text
|
-- leaf node containing raw text
|
||||||
node.x = x
|
node.x = x
|
||||||
node.y = y
|
node.y = y
|
||||||
-- render background if necessary
|
-- render a bar to grab for moving the node
|
||||||
local node_to_render
|
local move_bar = {type='rectangle', r=0.5,g=0.5,b=0.5, x=node.x-10, y=node.y-10-10-4, h=4}
|
||||||
if node.bg then
|
table.insert(nodes_to_render, move_bar)
|
||||||
node_to_render = {type='rectangle', drawmode='line', r=0.5, g=0.5, b=0.5, x=node.x-10, y=node.y-10, corner_radius=5}
|
-- render bounding box
|
||||||
table.insert(nodes_to_render, node_to_render)
|
local bounding_box = {type='rectangle', drawmode='line', r=0.5, g=0.5, b=0.5, x=node.x-10, y=node.y-10, corner_radius=5}
|
||||||
end
|
table.insert(nodes_to_render, bounding_box)
|
||||||
-- render contents
|
-- render contents
|
||||||
if node.width then
|
if node.width then
|
||||||
node.w = node.width
|
node.w = node.width
|
||||||
|
@ -29,10 +30,13 @@ compute_layout = function(node, x,y, nodes_to_render, preserve_screen_top_of_cur
|
||||||
end
|
end
|
||||||
node.h = box_height(node)
|
node.h = box_height(node)
|
||||||
table.insert(nodes_to_render, node)
|
table.insert(nodes_to_render, node)
|
||||||
if node_to_render then
|
move_bar.w = node.w/2
|
||||||
node_to_render.w = node.w+20
|
bounding_box.w = node.w+20
|
||||||
node_to_render.h = math.max(node.h, 3*node.editor.line_height)+20
|
local buffer_height = math.max(node.h, 3*node.editor.line_height)
|
||||||
end
|
bounding_box.h = buffer_height+20
|
||||||
|
-- resize affordance
|
||||||
|
table.insert(nodes_to_render, {type='line', r=0.7,g=0.7,b=0.7, data={node.x+node.w+20,node.y, node.x+node.w+20,node.y+buffer_height}})
|
||||||
|
table.insert(nodes_to_render, {type='line', r=0.7,g=0.7,b=0.7, data={node.x+node.w+20+4,node.y, node.x+node.w+20+4,node.y+buffer_height}})
|
||||||
elseif node.type == 'rows' then
|
elseif node.type == 'rows' then
|
||||||
node.x = x
|
node.x = x
|
||||||
node.y = y
|
node.y = y
|
||||||
|
|
1
0028-A
1
0028-A
|
@ -1,4 +1,5 @@
|
||||||
A = function(preserve_screen_top_of_cursor_node)
|
A = function(preserve_screen_top_of_cursor_node)
|
||||||
|
print('A')
|
||||||
-- translate Nodes to Surface
|
-- translate Nodes to Surface
|
||||||
while #Surface > 0 do table.remove(Surface) end
|
while #Surface > 0 do table.remove(Surface) end
|
||||||
for _, node in ipairs(Nodes) do
|
for _, node in ipairs(Nodes) do
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
Nodes = {
|
Nodes = {
|
||||||
{type='text', x=0,y=0, margin=0, width=400, bg={r=0,g=1,b=1}},
|
{type='text', x=0,y=0, margin=0, width=120},
|
||||||
}
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
set_mouse_cursor = function(name)
|
||||||
|
if Mouse_cursor ~= name then
|
||||||
|
Mouse_cursor = name
|
||||||
|
love.mouse.setCursor(love.mouse.getSystemCursor(name))
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,3 @@
|
||||||
|
sx = function(vx)
|
||||||
|
return vx/Viewport.zoom + Viewport.x
|
||||||
|
end
|
|
@ -0,0 +1,3 @@
|
||||||
|
sy = function(vy)
|
||||||
|
return vy/Viewport.zoom + Viewport.y
|
||||||
|
end
|
|
@ -0,0 +1,9 @@
|
||||||
|
on_move_bar = function(sx,sy)
|
||||||
|
for _,node in ipairs(Nodes) do
|
||||||
|
if sx >= node.x-10 and sx < node.x-10+node.w/2 then
|
||||||
|
if sy >= node.y - 40 and sy < node.y-20 then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,10 @@
|
||||||
|
on_resize = function(sx,sy)
|
||||||
|
for _,node in ipairs(Nodes) do
|
||||||
|
if sx >= node.x+node.w+20 and sx < node.x+node.w+24 then
|
||||||
|
local buffer_height = math.max(node.h, 3*node.editor.line_height)
|
||||||
|
if sy >= node.y and sy < node.y+buffer_height then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue