Also update node height as we add or delete lines.
EHVOKKDTAH4ED432LZCX2Y4BK63BP6YAIL2U7WXWBNWJRIACY7WQC
on.keychord_press = function(chord, key)
if chord == 'C-=' then
-- zoom in
Viewport.zoom = Viewport.zoom+0.1
B()
elseif chord == 'C--' then
-- zoom out
Viewport.zoom = Viewport.zoom-0.1
B()
elseif chord == 'C-0' then
-- reset zoom
Viewport.zoom = 1.0
B()
elseif Cursor_node then
local old_top = {line=Cursor_node.editor.screen_top1.line, pos=Cursor_node.editor.screen_top1.pos}
edit.keychord_press(Cursor_node.editor, chord, key)
if not eq(Cursor_node.editor.screen_top1, old_top) then
Viewport.y = Cursor_node.y + y_of_schema1(Cursor_node.editor, Cursor_node.editor.screen_top1)
end
A(--[[preserve screen_top of cursor node]] true)
end
end
{"Cursor_node":172,"scale":7,"on.update":368,"to_text":180,"font":353,"on.text_input":388,"on":1,"schema1_of_y":366,"A":387,"initialize_editor":338,"on.initialize":350,"y_of_schema1":364,"Page":381,"B":379,"on.draw":346,"box_height":345,"vx":5,"on.keychord_press":389,"Viewport":303,"compute_layout":385,"on.mouse_release":367,"vy":8,"on.code_change":306,"update_editor_box":377,"Surface":196,"parent":388,"on.mouse_press":179,"line_height":365}
on.text_input = function(t)
if Cursor_node then
local old_top = {line=Cursor_node.editor.screen_top1.line, pos=Cursor_node.editor.screen_top1.pos}
edit.text_input(Cursor_node.editor, t)
if not eq(Cursor_node.editor.screen_top1, old_top) then
Viewport.y = Cursor_node.y + y_of_schema1(Cursor_node.editor, Cursor_node.editor.screen_top1)
end
A(--[[preserve screen_top of cursor node]] true)
end
end
{"Cursor_node":172,"scale":7,"on.update":368,"to_text":180,"font":353,"on.text_input":388,"on":1,"schema1_of_y":366,"A":387,"initialize_editor":338,"on.initialize":350,"y_of_schema1":364,"Page":381,"B":379,"on.draw":346,"box_height":345,"vx":5,"on.keychord_press":383,"Viewport":303,"compute_layout":385,"on.mouse_release":367,"vy":8,"on.code_change":306,"update_editor_box":377,"Surface":196,"parent":387,"on.mouse_press":179,"line_height":365}
{"Cursor_node":172,"scale":7,"on.update":368,"to_text":180,"font":353,"on.text_input":382,"on":1,"schema1_of_y":366,"A":387,"initialize_editor":338,"on.initialize":350,"y_of_schema1":364,"Page":381,"B":379,"on.draw":346,"box_height":345,"vx":5,"on.keychord_press":383,"Viewport":303,"compute_layout":385,"on.mouse_release":367,"vy":8,"on.code_change":306,"update_editor_box":377,"Surface":196,"parent":386,"on.mouse_press":179,"line_height":365}
A = function(preserve_screen_top_of_cursor_node)
-- translate Page to Surface
while #Surface > 3 do table.remove(Surface) end -- HACK
compute_layout(Page, Page.x,Page.y, Surface, preserve_screen_top_of_cursor_node)
-- continue the pipeline
B(preserve_screen_top_of_cursor_node)
-- TODO: ugly that we're manipulating editor objects twice
end
{"Cursor_node":172,"scale":7,"on.update":368,"to_text":180,"font":353,"on.text_input":382,"on":1,"schema1_of_y":366,"A":386,"initialize_editor":338,"on.initialize":350,"y_of_schema1":364,"Page":381,"B":379,"on.draw":346,"box_height":345,"vx":5,"on.keychord_press":383,"Viewport":303,"compute_layout":385,"on.mouse_release":367,"vy":8,"on.code_change":306,"update_editor_box":377,"Surface":196,"parent":385,"on.mouse_press":179,"line_height":365}
A = function(preserve_screen_top_of_cursor_node)
-- translate Page to Surface
while #Surface > 3 do table.remove(Surface) end -- HACK
compute_layout(Page, Page.x,Page.y, Surface, preserve_screen_top_of_cursor_node)
-- continue the pipeline
B()
end
{"on.code_change":306,"parent":384,"Surface":196,"schema1_of_y":366,"on.draw":346,"font":353,"Cursor_node":172,"Viewport":303,"y_of_schema1":364,"update_editor_box":377,"vx":5,"vy":8,"on.text_input":382,"to_text":180,"line_height":365,"scale":7,"on.mouse_press":179,"A":309,"on":1,"on.mouse_release":367,"on.update":368,"B":379,"on.keychord_press":383,"box_height":345,"initialize_editor":338,"compute_layout":385,"Page":381,"on.initialize":350}
compute_layout = function(node, x,y, nodes_to_render, preserve_screen_top_of_cursor_node)
-- 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', r=node.bg.r, g=node.bg.g, b=node.bg.b, x=node.x, y=node.y}
table.insert(nodes_to_render, node_to_render)
end
-- render contents
if node.width then
node.w = node.width
else
node.w = 0
for i,s in ipairs(node.data) do
local text = love.graphics.newText(font(20), node.data)
local width = text:getWidth()
if node.w < width then node.w = width end
end
end
if node.editor == nil then
initialize_editor(node)
else
update_editor_box(node, preserve_screen_top_of_cursor_node)
end
node.h = box_height(node)
table.insert(nodes_to_render, node)
if node_to_render then
node_to_render.w = node.w
node_to_render.h = node.h
end
elseif node.type == 'rows' then
node.x = x
node.y = y
local node_to_render
if node.bg then
node_to_render = {type='rectangle', r=node.bg.r, g=node.bg.g, b=node.bg.b, x=node.x, y=node.y}
table.insert(nodes_to_render, node_to_render)
end
-- lay out children top to bottom
local subx,suby = x,y
local w,h = 0,0
local subnodes
for _,child in ipairs(node.data) do
if child.margin then
suby = suby+child.margin
h = h+child.margin
end
if not child.width then
child.width = node.width -- HACK: should we set child.w or child.width? Neither is quite satisfactory.
end
subx,suby = compute_layout(child, x,suby, nodes_to_render)
if w < child.w then
w = child.w
end
h = h+child.h
end
node.w = w
node.h = h
if node_to_render then
node_to_render.w = w
node_to_render.h = h
end
elseif node.type == 'cols' then
node.x = x
node.y = y
-- lay out children left to right
local node_to_render
if node.bg then
node_to_render = {type='rectangle', r=node.bg.r, g=node.bg.g, b=node.bg.b, x=node.x, y=node.y}
table.insert(nodes_to_render, node_to_render)
end
local subx,suby = x,y
local w,h = 0,0
for _,child in ipairs(node.data) do
if child.margin then
subx = subx+child.margin
w = w+child.margin
end
subx,suby = compute_layout(child, subx,y, nodes_to_render)
w = w + child.w
if h < child.h then
h = child.h
end
end
node.w = w
node.h = h
if node_to_render then
node_to_render.w = w
node_to_render.h = h
end
end
return x+node.w,y+node.h
end
{"on.code_change":306,"parent":383,"Surface":196,"schema1_of_y":366,"on.draw":346,"font":353,"Cursor_node":172,"Viewport":303,"y_of_schema1":364,"update_editor_box":377,"vx":5,"vy":8,"on.text_input":382,"to_text":180,"line_height":365,"scale":7,"on.mouse_press":179,"A":309,"on":1,"on.mouse_release":367,"on.update":368,"B":379,"on.keychord_press":383,"box_height":345,"initialize_editor":338,"compute_layout":384,"Page":381,"on.initialize":350}
compute_layout = function(node, x,y, nodes_to_render, preserve_screen_top_of_cursor_node)
-- 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', r=node.bg.r, g=node.bg.g, b=node.bg.b, x=node.x, y=node.y}
table.insert(nodes_to_render, node_to_render)
end
-- render contents
if node.width then
node.w = node.width
else
node.w = 0
for i,s in ipairs(node.data) do
local text = love.graphics.newText(font(20), node.data)
local width = text:getWidth()
if node.w < width then node.w = width end
end
end
if node.editor == nil then
initialize_editor(node)
else
update_editor_box(obj, preserve_screen_top_of_cursor_node)
end
node.h = box_height(node)
table.insert(nodes_to_render, node)
if node_to_render then
node_to_render.w = node.w
node_to_render.h = node.h
end
elseif node.type == 'rows' then
node.x = x
node.y = y
local node_to_render
if node.bg then
node_to_render = {type='rectangle', r=node.bg.r, g=node.bg.g, b=node.bg.b, x=node.x, y=node.y}
table.insert(nodes_to_render, node_to_render)
end
-- lay out children top to bottom
local subx,suby = x,y
local w,h = 0,0
local subnodes
for _,child in ipairs(node.data) do
if child.margin then
suby = suby+child.margin
h = h+child.margin
end
if not child.width then
child.width = node.width -- HACK: should we set child.w or child.width? Neither is quite satisfactory.
end
subx,suby = compute_layout(child, x,suby, nodes_to_render)
if w < child.w then
w = child.w
end
h = h+child.h
end
node.w = w
node.h = h
if node_to_render then
node_to_render.w = w
node_to_render.h = h
end
elseif node.type == 'cols' then
node.x = x
node.y = y
-- lay out children left to right
local node_to_render
if node.bg then
node_to_render = {type='rectangle', r=node.bg.r, g=node.bg.g, b=node.bg.b, x=node.x, y=node.y}
table.insert(nodes_to_render, node_to_render)
end
local subx,suby = x,y
local w,h = 0,0
for _,child in ipairs(node.data) do
if child.margin then
subx = subx+child.margin
w = w+child.margin
end
subx,suby = compute_layout(child, subx,y, nodes_to_render)
w = w + child.w
if h < child.h then
h = child.h
end
end
node.w = w
node.h = h
if node_to_render then
node_to_render.w = w
node_to_render.h = h
end
end
return x+node.w,y+node.h
end
on.keychord_press = function(chord, key)
if chord == 'C-=' then
-- zoom in
Viewport.zoom = Viewport.zoom+0.1
B()
elseif chord == 'C--' then
-- zoom out
Viewport.zoom = Viewport.zoom-0.1
B()
elseif chord == 'C-0' then
-- reset zoom
Viewport.zoom = 1.0
B()
elseif Cursor_node then
local old_top = {line=Cursor_node.editor.screen_top1.line, pos=Cursor_node.editor.screen_top1.pos}
edit.keychord_press(Cursor_node.editor, chord, key)
if not eq(Cursor_node.editor.screen_top1, old_top) then
Viewport.y = Cursor_node.y + y_of_schema1(Cursor_node.editor, Cursor_node.editor.screen_top1)
end
B(--[[preserve screen_top of cursor node]] true)
end
end
{"on.code_change":306,"parent":382,"Surface":196,"schema1_of_y":366,"on.draw":346,"font":353,"Cursor_node":172,"Viewport":303,"y_of_schema1":364,"update_editor_box":377,"vx":5,"vy":8,"on.text_input":382,"to_text":180,"line_height":365,"scale":7,"on.mouse_press":179,"A":309,"on":1,"on.mouse_release":367,"on.update":368,"B":379,"on.keychord_press":383,"box_height":345,"initialize_editor":338,"compute_layout":354,"Page":381,"on.initialize":350}
on.text_input = function(t)
if Cursor_node then
local old_top = {line=Cursor_node.editor.screen_top1.line, pos=Cursor_node.editor.screen_top1.pos}
edit.text_input(Cursor_node.editor, t)
if not eq(Cursor_node.editor.screen_top1, old_top) then
Viewport.y = Cursor_node.y + y_of_schema1(Cursor_node.editor, Cursor_node.editor.screen_top1)
end
B(--[[preserve screen_top of cursor node]] true)
end
end
{"on.code_change":306,"parent":381,"Surface":196,"schema1_of_y":366,"on.draw":346,"font":353,"Cursor_node":172,"Viewport":303,"y_of_schema1":364,"update_editor_box":377,"vx":5,"vy":8,"on.text_input":382,"to_text":180,"line_height":365,"scale":7,"on.mouse_press":179,"A":309,"on":1,"on.mouse_release":367,"on.update":368,"B":379,"on.keychord_press":376,"box_height":345,"initialize_editor":338,"compute_layout":354,"Page":381,"on.initialize":350}