ensure cursor is initially on viewport

Important with larger threads like the input2 example.
This commit is contained in:
Kartik K. Agaram 2023-02-19 00:05:11 -08:00
parent 799afaf881
commit 9d173290b7
4 changed files with 53 additions and 1 deletions

1
0652-fwmanifest Normal file
View File

@ -0,0 +1 @@
{"render_thread_to_surface":652,"dehtml":456,"Cursor_node":172,"on.code_change":578,"copy_shape":396,"on.text_input":587,"header":651,"Surface":588,"update_editor_box":430,"load_from_iterator":463,"on.draw":632,"compute_ntracks":598,"on":1,"Viewport":303,"font":353,"split_lines":469,"schema1_of_y":366,"on.mouse_press":618,"y_of_schema1":364,"on.initialize":446,"on.update":368,"scale":7,"add_node":650,"render_node_and_descendants":646,"vx":5,"add_edge":575,"initialize_editor":338,"vy":8,"Nodes":593,"add_thick_line":400,"ntracks":600,"Input_filename":436,"compute_layout":619,"to_text":180,"A":582,"on.keychord_press":644,"box_height":345,"line_height":365,"B":379,"fw_parent":651,"to_node":611,"fw_app":"mastodon-unfurl","ensure_cursor_node_within_viewport":643,"on.mouse_release":586}

View File

@ -0,0 +1,50 @@
render_thread_to_surface = function(thread_data)
-- design constraints:
-- trees only, no graphs or DAGs
-- parents above children
-- a child shares its parent's column exactly only if it's an only child
-- parents can overlap columns with children and more distant descendants
-- siblings never share a column
-- siblings never overlap columns
-- siblings always occupy the same row
-- cousins/aunts/nephews never overlap columns
Surface = {}
-- we're going to be computing box heights
love.graphics.setFont(love.graphics.newFont(scale(20)))
-- compute mapping from ids to nodes
Nodes = {} -- id to object
Nodes[thread_data.id] = thread_data
for _,x in ipairs(thread_data.descendants) do
Nodes[x.id] = x
end
local root = thread_data
Cursor_node = root
-- compute children
for _,x in pairs(Nodes) do
parent_id = x.in_reply_to_id
if x.id ~= root.id then
assert(parent_id)
local parent = Nodes[parent_id]
if parent.children == nil then
parent.children = {}
end
table.insert(parent.children, x.id)
end
end
-- sort children by time
for _,x in pairs(Nodes) do
if x.children then
table.sort(x.children)
end
end
-- compute number of tracks needed
for _,x in pairs(Nodes) do
if x.ntracks == nil then
x.ntracks = compute_ntracks(x)
end
end
-- prepare the tracks
-- each track is 600px + 20px of gutter between nodes
render_node_and_descendants(root.id, --[[y]] 0, --[[xlo]] 0, --[[xhi]] 620 * root.ntracks)
ensure_cursor_node_within_viewport()
end

2
head
View File

@ -1 +1 @@
651
652

1
input2 Normal file

File diff suppressed because one or more lines are too long