greatly simplify layout

I don't know why this was so hard, but I don't need this variable
preserve_screen_top_of_cursor_node at all. We only set it when the
cursor is in some node, but we also only check for when the current node
is the cursor. Comparing with a nil cursor node works just as well.

I've also checked that driver.love doesn't need
preserve_screen_top_of_cursor_node. I think it came from pensieve.love,
where I've since taken it out. Did I ever need it even there?
This commit is contained in:
Kartik K. Agaram 2023-10-21 09:54:12 -07:00
parent c103bda5a6
commit 4c8960b5c7
6 changed files with 15 additions and 15 deletions

6
0019-B
View File

@ -1,4 +1,4 @@
B = function(preserve_screen_top_of_cursor_node)
B = function()
-- 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
@ -17,10 +17,10 @@ B = function(preserve_screen_top_of_cursor_node)
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)
update_editor_box(obj)
else
obj.text = love.graphics.newText(love.graphics.getFont(), obj.data)
end
end
end
end
end

View File

@ -1,4 +1,4 @@
compute_layout = function(node, x,y, nodes_to_render, preserve_screen_top_of_cursor_node)
compute_layout = function(node, x,y, nodes_to_render)
-- 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
@ -31,7 +31,7 @@ compute_layout = function(node, x,y, nodes_to_render, preserve_screen_top_of_cur
if node.editor == nil then
initialize_editor(node)
else
update_editor_box(node, preserve_screen_top_of_cursor_node)
update_editor_box(node)
end
node.h = box_height(node)
table.insert(nodes_to_render, node)

View File

@ -5,6 +5,6 @@ on.text_input = function(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)
A()
end
end
end

View File

@ -17,7 +17,7 @@ on.keychord_press = function(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)
A()
else
if chord == 'up' then
Viewport.y = Viewport.y - scale(20)
@ -51,4 +51,4 @@ on.keychord_press = function(chord, key)
B()
end
end
end
end

8
0028-A
View File

@ -1,4 +1,4 @@
A = function(preserve_screen_top_of_cursor_node)
A = function()
love.graphics.setFont(love.graphics.newFont(scale(20))) -- editor objects implicitly depend on current font
-- translate Page to Surface
while #Surface > 3 do table.remove(Surface) end -- HACK
@ -9,9 +9,9 @@ A = function(preserve_screen_top_of_cursor_node)
red = not red
end
end
compute_layout(Page, Page.x,Page.y, Surface, preserve_screen_top_of_cursor_node)
compute_layout(Page2, Page2.x,Page2.y, Surface, preserve_screen_top_of_cursor_node)
compute_layout(Page, Page.x,Page.y, Surface)
compute_layout(Page2, Page2.x,Page2.y, Surface)
-- continue the pipeline
B(preserve_screen_top_of_cursor_node)
B()
-- TODO: ugly that we're manipulating editor objects twice
end

View File

@ -1,8 +1,8 @@
update_editor_box = function(node, preserve_screen_top_of_cursor_node)
update_editor_box = function(node)
if node.editor == nil then return end
-- Compute screen_top1 in viewport coordinates because the editor's font takes scaling into account.
if vy(node.y) > 0 then
if not preserve_screen_top_of_cursor_node or node ~= Cursor_node then
if node ~= Cursor_node then
node.editor.screen_top1.line = 1
node.editor.screen_top1.pos = 1
end