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.y = Pan.y - App.mouse_y()/Viewport.zoom
|
||||
B()
|
||||
return
|
||||
end
|
||||
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
|
2
0019-B
2
0019-B
|
@ -1,9 +1,11 @@
|
|||
B = function(preserve_screen_top_of_cursor_node)
|
||||
print('B')
|
||||
-- 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
|
||||
for _,obj in ipairs(Surface) do
|
||||
if obj.type == 'line' then
|
||||
obj.zdata = {}
|
||||
print('A', #obj.data)
|
||||
for i=1,#obj.data,2 do
|
||||
table.insert(obj.zdata, vx(obj.data[i]))
|
||||
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)
|
||||
print('compute_layout')
|
||||
-- append to nodes_to_render flattened instructions to render a hierarchy of nodes
|
||||
-- return x,y rendered until (surface coordinates)
|
||||
if node.type == 'text' then
|
||||
-- leaf node containing raw text
|
||||
node.x = x
|
||||
node.y = y
|
||||
-- render background if necessary
|
||||
local node_to_render
|
||||
if node.bg then
|
||||
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}
|
||||
table.insert(nodes_to_render, node_to_render)
|
||||
end
|
||||
-- render a bar to grab for moving the node
|
||||
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}
|
||||
table.insert(nodes_to_render, move_bar)
|
||||
-- render bounding box
|
||||
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}
|
||||
table.insert(nodes_to_render, bounding_box)
|
||||
-- render contents
|
||||
if node.width then
|
||||
node.w = node.width
|
||||
|
@ -29,10 +30,13 @@ compute_layout = function(node, x,y, nodes_to_render, preserve_screen_top_of_cur
|
|||
end
|
||||
node.h = box_height(node)
|
||||
table.insert(nodes_to_render, node)
|
||||
if node_to_render then
|
||||
node_to_render.w = node.w+20
|
||||
node_to_render.h = math.max(node.h, 3*node.editor.line_height)+20
|
||||
end
|
||||
move_bar.w = node.w/2
|
||||
bounding_box.w = node.w+20
|
||||
local buffer_height = math.max(node.h, 3*node.editor.line_height)
|
||||
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
|
||||
node.x = x
|
||||
node.y = y
|
||||
|
|
1
0028-A
1
0028-A
|
@ -1,4 +1,5 @@
|
|||
A = function(preserve_screen_top_of_cursor_node)
|
||||
print('A')
|
||||
-- translate Nodes to Surface
|
||||
while #Surface > 0 do table.remove(Surface) end
|
||||
for _, node in ipairs(Nodes) do
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
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