From 45c1e42de25390dbdb646ee2d28949daa21abc15 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Wed, 25 Oct 2023 16:46:03 -0700 Subject: [PATCH] snapshot: a cleaner organization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit scenarios: * Zoom = 1 * pan with mouse: ✓ * pan with up arrow: ✓ * pan with down arrow: ✓ * Zoom < 1 * pan with mouse: ✓ * pan with up arrow: ✓ * pan with down arrow: ✗ * Zoom > 1 * pan with mouse: ✓ * pan with up arrow: ✗ * pan with down arrow: ✓ What ✓ means: * pan with mouse: lines don't slide relative to the surface * will still slide relative to the surface when zooming in/out; that's unavoidable because we want integer pixels for crisp text * pan with keyboard: at least some part of cursor is always peeking within the viewport * might still look ugly, with the line containing the cursor almost invisible, but hitting the down arrow will never pan upwards, or vice versa Still not working though. I'm pretty much guaranteeing by construction that if Viewport.y was set from screen_top1, then screen_top1 will not be perturbed. And yet using scale() inside update_editor_box is incorrect. Hmm.. --- 0019-B | 6 +++--- 0021-compute_layout | 4 ++-- 0022-on.text_input | 6 ++++-- 0023-on.keychord_press | 6 ++++-- 0028-A | 6 +++--- 0030-update_editor_box | 12 ++++++------ 6 files changed, 22 insertions(+), 18 deletions(-) diff --git a/0019-B b/0019-B index 7e366c3..43c72b6 100644 --- a/0019-B +++ b/0019-B @@ -1,4 +1,4 @@ -B = function(preserve_screen_top_of_cursor_node) +B = function(skip_updating_screen_top_for) -- recompute various aspects based on the current viewport settings for _,obj in ipairs(Surface) do if obj.type == 'line' then @@ -16,10 +16,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, skip_updating_screen_top_for) else obj.text = love.graphics.newText(love.graphics.getFont(), obj.data) end end end -end \ No newline at end of file +end diff --git a/0021-compute_layout b/0021-compute_layout index 6ae7ca8..86d1d3c 100644 --- a/0021-compute_layout +++ b/0021-compute_layout @@ -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, skip_updating_screen_top_for) -- 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, skip_updating_screen_top_for) end node.h = box_height(node) table.insert(nodes_to_render, node) diff --git a/0022-on.text_input b/0022-on.text_input index 9ce6eff..a3c22d3 100644 --- a/0022-on.text_input +++ b/0022-on.text_input @@ -4,7 +4,9 @@ on.text_input = function(t) 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) + A(--[[skip updating screen_top for]] Cursor_node) + return end - A(--[[preserve screen_top of cursor node]] true) + A() end -end \ No newline at end of file +end diff --git a/0023-on.keychord_press b/0023-on.keychord_press index 3dd8a2d..c73389f 100644 --- a/0023-on.keychord_press +++ b/0023-on.keychord_press @@ -21,8 +21,10 @@ on.keychord_press = function(chord, key) 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) + A(--[[skip updating screen_top for]] Cursor_node) + return end - A(--[[preserve screen_top of cursor node]] true) + A() else if chord == 'up' then Viewport.y = Viewport.y - scale(20) @@ -56,4 +58,4 @@ on.keychord_press = function(chord, key) B() end end -end \ No newline at end of file +end diff --git a/0028-A b/0028-A index 95f0636..2d44c6b 100644 --- a/0028-A +++ b/0028-A @@ -1,8 +1,8 @@ -A = function(preserve_screen_top_of_cursor_node) +A = function(skip_updating_screen_top_for) love.graphics.setFont(love.graphics.newFont(scale(20))) -- editor objects implicitly depend on current font Surface = {} - compute_layout(Page, Page.x,Page.y, Surface) + compute_layout(Page, Page.x,Page.y, Surface, skip_updating_screen_top_for) -- continue the pipeline - B(preserve_screen_top_of_cursor_node) + B(skip_updating_screen_top_for) -- TODO: ugly that we're manipulating editor objects twice end diff --git a/0030-update_editor_box b/0030-update_editor_box index fd103d6..0f807dc 100644 --- a/0030-update_editor_box +++ b/0030-update_editor_box @@ -1,14 +1,14 @@ -update_editor_box = function(node, preserve_screen_top_of_cursor_node) +update_editor_box = function(node, skip_updating_screen_top_for) if node.editor == nil then return end edit.update_font_settings(node.editor, scale(20)) - if node.y > Viewport.y then - if node ~= Cursor_node then + if node ~= skip_updating_screen_top_for then + 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, scale(Viewport.y-node.y)) 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 node.editor.left = math.floor(vx(node.x)) node.editor.right = math.ceil(vx(node.x+node.w))