snapshot: a cleaner organization
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..
This commit is contained in:
parent
0a37b1b80c
commit
45c1e42de2
6
0019-B
6
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
|
||||
end
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
end
|
||||
|
|
|
@ -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
|
||||
end
|
||||
|
|
6
0028-A
6
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
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in New Issue