I'm starting to understand this mechanism. I keep polishing pensieve.love in parallel with these changes.
U3YIPNIJ6JBWKXZOKDFZFUDL3USFDIMDDVGP2JZMXGPZQ7ELKF6QC
{"vy":8,"schema1_of_y":366,"on.keychord_press":376,"to_text":180,"initialize_editor":338,"on.update":368,"on.initialize":350,"y_of_schema1":364,"A":309,"box_height":345,"compute_layout":354,"Page":381,"B":379,"on.mouse_release":367,"on":1,"scale":7,"on.mouse_press":179,"on.text_input":177,"Surface":196,"on.code_change":306,"parent":380,"line_height":365,"Cursor_node":172,"vx":5,"update_editor_box":377,"Viewport":303,"on.draw":346,"font":353}
Page = {
-- page
type='cols', x=0, y=0,
width=800, data={
-- editor covering left side
{
type='text',
name='editor',
doc='prose goes here, on the left half of the window',
margin=Margin_left,
data={
"Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
'1',
'2',
'3',
'mno',
'Acb',
'g',
'hij',
'klm',
'nop',
},
width=400, bg={r=1,g=1,b=0}
},
-- a table on the right
{ type='rows', name='searches', margin=50, data={
{ type='text', data={''},},
{ type='cols', data={
{ type='text', data={'search:'},},
{ type='text', name='search', bg={r=0.8,g=0.8,b=0.8}, data={''}, width=90,},
}},
{ type='text', data={'table:'},},
{ type='cols', bg={r=0.8,g=0.8,b=0.8}, data={
{ type='rows', width=90, data={
{type='text', data={'abc'},},
{type='text', data={'abc'},},
}},
{ type='rows', width=90, data={
{type='text', data={'def'},},
{type='text', data={'def'},},
}},
}},
}},
},
}
{"compute_layout":354,"Page":380,"schema1_of_y":366,"parent":379,"Cursor_node":172,"on":1,"on.initialize":350,"y_of_schema1":364,"A":309,"on.draw":346,"font":353,"vx":5,"B":379,"Viewport":303,"initialize_editor":338,"line_height":365,"vy":8,"on.code_change":306,"Surface":196,"on.text_input":177,"to_text":180,"on.mouse_press":179,"scale":7,"on.mouse_release":367,"update_editor_box":377,"on.update":368,"box_height":345,"on.keychord_press":376}
Page = {
-- page
type='rows', x=0, y=0,
width=800, data={
-- editor covering left side
{
type='text',
name='editor',
doc='prose goes here, on the left half of the window',
margin=Margin_left,
data={
"Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
'1',
'2',
'3',
'mno',
'Acb',
'g',
'hij',
'klm',
'nop',
},
width=400, bg={r=1,g=1,b=0}
},
-- a table on the right
{ type='rows', name='searches', margin=50, data={
{ type='text', data={''},},
{ type='cols', data={
{ type='text', data={'search:'},},
{ type='text', name='search', bg={r=0.8,g=0.8,b=0.8}, data={''}, width=90,},
}},
{ type='text', data={'table:'},},
{ type='cols', bg={r=0.8,g=0.8,b=0.8}, data={
{ type='rows', width=90, data={
{type='text', data={'abc'},},
{type='text', data={'abc'},},
}},
{ type='rows', width=90, data={
{type='text', data={'def'},},
{type='text', data={'def'},},
}},
}},
}},
},
}
{"compute_layout":354,"Page":344,"schema1_of_y":366,"parent":378,"Cursor_node":172,"on":1,"on.initialize":350,"y_of_schema1":364,"A":309,"on.draw":346,"font":353,"vx":5,"B":379,"Viewport":303,"initialize_editor":338,"line_height":365,"vy":8,"on.code_change":306,"Surface":196,"on.text_input":177,"to_text":180,"on.mouse_press":179,"scale":7,"on.mouse_release":367,"update_editor_box":377,"on.update":368,"box_height":345,"on.keychord_press":376}
B = function(preserve_screen_top_of_cursor_node)
-- 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 = {}
for i=1,#obj.data,2 do
table.insert(obj.zdata, vx(obj.data[i]))
table.insert(obj.zdata, vy(obj.data[i+1]))
end
elseif obj.type == 'bezier' then
zdata = {}
for i=1,#obj.data,2 do
table.insert(zdata, vx(obj.data[i]))
table.insert(zdata, vy(obj.data[i+1]))
end
obj.zdata = love.math.newBezierCurve(zdata):render()
elseif obj.type == 'text' then
if obj.w then
update_editor_box(obj, preserve_screen_top_of_cursor_node)
else
obj.text = love.graphics.newText(love.graphics.getFont(), obj.data)
end
end
end
end
{"compute_layout":354,"Page":344,"schema1_of_y":366,"parent":377,"Cursor_node":172,"on":1,"on.initialize":350,"y_of_schema1":364,"A":309,"on.draw":346,"font":353,"vx":5,"B":378,"Viewport":303,"initialize_editor":338,"line_height":365,"vy":8,"on.code_change":306,"Surface":196,"on.text_input":177,"to_text":180,"on.mouse_press":179,"scale":7,"on.mouse_release":367,"update_editor_box":377,"on.update":368,"box_height":345,"on.keychord_press":376}
B = function(preserve_screen_top_of_cursor_node)
-- 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 = {}
for i=1,#obj.data,2 do
table.insert(obj.zdata, vx(obj.data[i]))
table.insert(obj.zdata, vy(obj.data[i+1]))
end
elseif obj.type == 'bezier' then
zdata = {}
for i=1,#obj.data,2 do
table.insert(zdata, vx(obj.data[i]))
table.insert(zdata, vy(obj.data[i+1]))
end
obj.zdata = love.math.newBezierCurve(zdata):render()
elseif obj.type == 'text' then
if obj.w then
update_editor_box(obj, preserve_screen_top_of_cursor_node)
else
obj.text = love.graphics.newText(love.graphics.getFont(), obj.data)
end
end
end
end
update_editor_box = function(node, preserve_screen_top_of_cursor_node)
if node.editor == nil then return end
if node.y > Viewport.y then
if not preserve_screen_top_of_cursor_node or node ~= Cursor_node then
node.editor.screen_top1.line = 1
node.editor.screen_top1.pos = 1
end
node.editor.top = vy(node.y)
else
node.editor.screen_top1, node.editor.top = schema1_of_y(node.editor, Viewport.y - node.y)
end
print('top', node.editor.top)
print('screen_top1', node.editor.screen_top1.line, node.editor.screen_top1.pos)
node.editor.left = math.floor(vx(node.x))
node.editor.right = math.ceil(vx(node.x+node.w))
edit.update_font_settings(node.editor, scale(20))
Text.redraw_all(node.editor)
end
{"compute_layout":354,"Page":344,"schema1_of_y":366,"parent":376,"Cursor_node":172,"on":1,"on.initialize":350,"y_of_schema1":364,"A":309,"on.draw":346,"font":353,"vx":5,"B":369,"Viewport":303,"initialize_editor":338,"line_height":365,"vy":8,"on.code_change":306,"Surface":196,"on.text_input":177,"to_text":180,"on.mouse_press":179,"scale":7,"on.mouse_release":367,"update_editor_box":377,"on.update":368,"box_height":345,"on.keychord_press":376}
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(--[[skip_cursor_node]] true)
end
end
{"compute_layout":354,"Page":344,"schema1_of_y":366,"parent":375,"Cursor_node":172,"on":1,"on.initialize":350,"y_of_schema1":364,"A":309,"on.draw":346,"font":353,"vx":5,"B":369,"Viewport":303,"initialize_editor":338,"line_height":365,"vy":8,"on.code_change":306,"Surface":196,"on.text_input":177,"to_text":180,"on.mouse_press":179,"scale":7,"on.mouse_release":367,"update_editor_box":372,"on.update":368,"box_height":345,"on.keychord_press":376}
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
print('before', Viewport.y)
Viewport.y = Cursor_node.y + y_of_schema1(Cursor_node.editor, Cursor_node.editor.screen_top1)
print('after', Viewport.y)
end
B(--[[skip_cursor_node]] true)
end
end
{"compute_layout":354,"Page":344,"schema1_of_y":366,"parent":374,"Cursor_node":172,"on":1,"on.initialize":350,"y_of_schema1":364,"A":309,"on.draw":346,"font":353,"vx":5,"B":369,"Viewport":303,"initialize_editor":338,"line_height":365,"vy":8,"on.code_change":306,"Surface":196,"on.text_input":177,"to_text":180,"on.mouse_press":179,"scale":7,"on.mouse_release":367,"update_editor_box":372,"on.update":368,"box_height":345,"on.keychord_press":375}
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(--[[skip_cursor_node]] true)
end
end
{"compute_layout":354,"Page":344,"schema1_of_y":366,"parent":373,"Cursor_node":172,"on":1,"on.initialize":350,"y_of_schema1":364,"A":309,"on.draw":346,"font":353,"vx":5,"B":369,"Viewport":303,"initialize_editor":338,"line_height":365,"vy":8,"on.code_change":306,"Surface":196,"on.text_input":177,"to_text":180,"on.mouse_press":179,"scale":7,"on.mouse_release":367,"update_editor_box":372,"on.update":368,"box_height":345,"on.keychord_press":374}
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.screen_top1)
end
B(--[[skip_cursor_node]] true)
end
end
{"compute_layout":354,"Page":344,"schema1_of_y":366,"parent":372,"Cursor_node":172,"on":1,"on.initialize":350,"y_of_schema1":364,"A":309,"on.draw":346,"font":353,"vx":5,"B":369,"Viewport":303,"initialize_editor":338,"line_height":365,"vy":8,"on.code_change":306,"Surface":196,"on.text_input":177,"to_text":180,"on.mouse_press":179,"scale":7,"on.mouse_release":367,"update_editor_box":372,"on.update":368,"box_height":345,"on.keychord_press":373}
update_editor_box = function(node, skip_cursor_node)
if node.editor == nil then return end
if skip_cursor_node and node == Cursor_node then return end
if node.y > Viewport.y then
node.editor.screen_top1.line = 1
node.editor.screen_top1.pos = 1
node.editor.top = vy(node.y)
else
node.editor.screen_top1, node.editor.top = schema1_of_y(node.editor, Viewport.y - node.y)
end
print('top', node.editor.top)
print('screen_top1', node.editor.screen_top1.line, node.editor.screen_top1.pos)
node.editor.left = math.floor(vx(node.x))
node.editor.right = math.ceil(vx(node.x+node.w))
edit.update_font_settings(node.editor, scale(20))
Text.redraw_all(node.editor)
end
{"compute_layout":354,"Page":344,"schema1_of_y":366,"parent":371,"Cursor_node":172,"on":1,"on.initialize":350,"y_of_schema1":364,"A":309,"on.draw":346,"font":353,"vx":5,"B":369,"Viewport":303,"initialize_editor":338,"line_height":365,"vy":8,"on.code_change":306,"Surface":196,"on.text_input":177,"to_text":180,"on.mouse_press":179,"scale":7,"on.mouse_release":367,"update_editor_box":372,"on.update":368,"box_height":345,"on.keychord_press":311}
update_editor_box = function(node, skip_cursor_node)
if node.editor == nil then return end
if skip_cursor_node and node == Cursor_node then return end
if node.y > Viewport.y then
node.editor.screen_top1.line = 1
node.editor.screen_top1.pos = 1
node.editor.top = vy(node.y)
else
node.editor.screen_top1, node.editor.top = schema1_of_y(node.editor, Viewport.y - node.y)
end
print('top', node.editor.top)
print('screen_top1', node.editor.screen_top1.line, node.editor.screen_top1.pos)
node.editor.left = math.floor(vx(node.x))
node.editor.right = math.ceil(vx(node.x+obj.w))
edit.update_font_settings(node.editor, scale(20))
Text.redraw_all(node.editor)
end
{"compute_layout":354,"Page":344,"schema1_of_y":366,"parent":370,"Cursor_node":172,"on":1,"on.initialize":350,"y_of_schema1":364,"A":309,"on.draw":346,"font":353,"vx":5,"B":369,"Viewport":303,"initialize_editor":338,"line_height":365,"vy":8,"on.code_change":306,"Surface":196,"on.text_input":177,"to_text":180,"on.mouse_press":179,"scale":7,"on.mouse_release":367,"update_editor_box":371,"on.update":368,"box_height":345,"on.keychord_press":311}
update_editor_box = function(obj, skip_cursor_node)
if obj.editor == nil then return end
if skip_cursor_node and obj == Cursor_node then return end
if obj.y > Viewport.y then
obj.editor.screen_top1.line = 1
obj.editor.screen_top1.pos = 1
obj.editor.top = vy(obj.y)
else
obj.editor.screen_top1, obj.editor.top = schema1_of_y(obj.editor, Viewport.y - obj.y)
end
print('top', obj.editor.top)
print('screen_top1', obj.editor.screen_top1.line, obj.editor.screen_top1.pos)
obj.editor.left = math.floor(vx(obj.x))
obj.editor.right = math.ceil(vx(obj.x+obj.w))
edit.update_font_settings(obj.editor, scale(20))
Text.redraw_all(obj.editor)
end
{"compute_layout":354,"Page":344,"schema1_of_y":366,"parent":369,"Cursor_node":172,"on":1,"on.initialize":350,"y_of_schema1":364,"A":309,"on.draw":346,"font":353,"vx":5,"B":369,"Viewport":303,"initialize_editor":338,"line_height":365,"vy":8,"on.code_change":306,"Surface":196,"on.text_input":177,"to_text":180,"on.mouse_press":179,"scale":7,"on.mouse_release":367,"update_editor_box":370,"on.update":368,"box_height":345,"on.keychord_press":311}
{"compute_layout":354,"Page":344,"schema1_of_y":366,"parent":368,"Cursor_node":172,"on":1,"on.initialize":350,"y_of_schema1":364,"A":309,"on.draw":346,"font":353,"vx":5,"B":369,"Viewport":303,"initialize_editor":338,"line_height":365,"vy":8,"on.code_change":306,"Surface":196,"on.text_input":177,"to_text":180,"on.mouse_press":179,"scale":7,"on.mouse_release":367,"update_editor_box":358,"on.update":368,"box_height":345,"on.keychord_press":311}
B = function(skip_cursor_node)
-- 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 = {}
for i=1,#obj.data,2 do
table.insert(obj.zdata, vx(obj.data[i]))
table.insert(obj.zdata, vy(obj.data[i+1]))
end
elseif obj.type == 'bezier' then
zdata = {}
for i=1,#obj.data,2 do
table.insert(zdata, vx(obj.data[i]))
table.insert(zdata, vy(obj.data[i+1]))
end
obj.zdata = love.math.newBezierCurve(zdata):render()
elseif obj.type == 'text' then
if obj.w then
update_editor_box(obj, skip_cursor_node)
else
obj.text = love.graphics.newText(love.graphics.getFont(), obj.data)
end
end
end
end
on.update = function(dt)
if Pan then
Viewport.x = Pan.x - love.mouse.getX()
Viewport.y = Pan.y - love.mouse.getY()
B()
end
end
{"compute_layout":354,"Page":344,"schema1_of_y":366,"parent":367,"Cursor_node":172,"on":1,"on.initialize":350,"y_of_schema1":364,"A":309,"on.draw":346,"font":353,"vx":5,"B":352,"Viewport":303,"initialize_editor":338,"line_height":365,"vy":8,"on.code_change":306,"Surface":196,"on.text_input":177,"to_text":180,"on.mouse_press":179,"scale":7,"on.mouse_release":367,"update_editor_box":358,"on.update":368,"box_height":345,"on.keychord_press":311}
on.mouse_release = function(x,y, mouse_button)
if Pan then
Pan = nil
elseif Cursor_node then
Cursor_node.show_cursor = true
edit.mouse_release(Cursor_node.editor, x,y, mouse_button)
end
end
{"compute_layout":354,"Page":344,"schema1_of_y":366,"parent":366,"Cursor_node":172,"on":1,"on.initialize":350,"y_of_schema1":364,"A":309,"on.draw":346,"font":353,"vx":5,"B":352,"Viewport":303,"initialize_editor":338,"line_height":365,"vy":8,"on.code_change":306,"Surface":196,"on.text_input":177,"to_text":180,"on.mouse_press":179,"scale":7,"on.mouse_release":367,"update_editor_box":358,"on.update":355,"box_height":345,"on.keychord_press":311}