From 37d5358290b6f36e828f6de9c2fc0be1f3ba6fe8 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Tue, 20 Jun 2023 19:35:32 -0700 Subject: [PATCH] start rendering the initialized thread This required a little more restructuring of Global_state. It's not flat now, it's hierarchical again, but in a different way. after commit 3d89b8eb9d: post \- reply A \- reply B \- reply C after commit f9f7dab9b7: post reply A reply B reply C after this commit: row \- col \- indent 0 \- post \- col \- indent 1 \- reply A \- col \- indent 2 \- reply B \- col \- indent 1 \- reply C The indents are just invisible rectangles of different widths with 0 height. One change I had to make was to initialize_editor. Neither luaML and driver load lines from disk, but that's arguably the common scenario to support. --- 0006-on.mouse_press | 2 +- 0009-on.code_change | 4 +++- 0010-initialize_editor | 2 +- 0012-on.initialize | 6 +++--- 0026-on.draw | 6 ++---- 0028-A | 6 ++---- 0032-Definitions | 3 --- 0077-new_definition | 16 ---------------- 0115-update_font_size | 13 ------------- 0117-open_thread | 5 +++-- 0118-load_subtree | 10 ++++++++-- 0120-initialize_item | 2 ++ 0124-Indent | 1 + 0125-Width | 1 + 14 files changed, 27 insertions(+), 50 deletions(-) delete mode 100644 0032-Definitions delete mode 100644 0077-new_definition delete mode 100644 0115-update_font_size create mode 100644 0124-Indent create mode 100644 0125-Width diff --git a/0006-on.mouse_press b/0006-on.mouse_press index e12fa94..2a241f8 100644 --- a/0006-on.mouse_press +++ b/0006-on.mouse_press @@ -2,7 +2,7 @@ on.mouse_press = function(x,y, mouse_button) if mouse_press_consumed_by_any_button_handler(Global_state, x,y, mouse_button) then return end - if Global_state.items then + if Global_state.root then mouse_press_on_surface(x,y, mouse_button) end end \ No newline at end of file diff --git a/0009-on.code_change b/0009-on.code_change index 10b0ba1..03deb23 100644 --- a/0009-on.code_change +++ b/0009-on.code_change @@ -1,4 +1,6 @@ on.code_change = function() print('code changed') - A() + if Global_state.root then + A() + end end \ No newline at end of file diff --git a/0010-initialize_editor b/0010-initialize_editor index 13cdeb6..a3d9169 100644 --- a/0010-initialize_editor +++ b/0010-initialize_editor @@ -4,7 +4,7 @@ initialize_editor = function(obj) local scaled_fontsize = scale(20) local scaled_lineheight = math.floor(scaled_fontsize*1.3) obj.editor = edit.initialize_state(Menu_bar_height + vy(obj.y), math.floor(vx(obj.x)), math.ceil(vx(obj.x+obj.w)), scaled_fontsize, scaled_lineheight) - obj.editor.lines = load_array(obj.data) + obj.editor.lines = obj.data Text.redraw_all(obj.editor) end end \ No newline at end of file diff --git a/0012-on.initialize b/0012-on.initialize index c40a24a..40c2abb 100644 --- a/0012-on.initialize +++ b/0012-on.initialize @@ -1,4 +1,6 @@ on.initialize = function() + local font = love.graphics.getFont() + font:setLineHeight(1.3) Files = love.filesystem.getDirectoryItems('data') for i=#Files,1,-1 do if (not Files[i]:match('%.md$')) or Files[i]:match('%-%d+.md$') then @@ -6,6 +8,4 @@ on.initialize = function() end end table.sort(Files) - new_definition() - A() -end \ No newline at end of file +end diff --git a/0026-on.draw b/0026-on.draw index b773f16..a8543a3 100644 --- a/0026-on.draw +++ b/0026-on.draw @@ -1,11 +1,9 @@ on.draw = function() Global_state.button_handlers = {} - local font = love.graphics.getFont() - font:setLineHeight(1.3) - if Global_state.items == nil then + if Global_state.root == nil then -- TODO: use surface for file picker as well draw_file_picker() else draw_surface() end -end \ No newline at end of file +end diff --git a/0028-A b/0028-A index 9ee8ca0..92a2471 100644 --- a/0028-A +++ b/0028-A @@ -1,11 +1,9 @@ A = function(preserve_screen_top_of_cursor_node) -- print('A') love.graphics.setFont(love.graphics.newFont(scale(20))) -- editor objects implicitly depend on current font - -- translate Definitions to Surface + -- translate Global_state.root to Surface Surface = {} - for key,node in pairs(Definitions) do - compute_layout(node, node.x,node.y, Surface, preserve_screen_top_of_cursor_node) - end + compute_layout(Global_state.root, 0,0, Surface, preserve_screen_top_of_cursor_node) -- continue the pipeline B(preserve_screen_top_of_cursor_node) -- TODO: ugly that we're manipulating editor objects twice diff --git a/0032-Definitions b/0032-Definitions deleted file mode 100644 index fe72372..0000000 --- a/0032-Definitions +++ /dev/null @@ -1,3 +0,0 @@ -Definitions = { - -- table mapping names to boxes where we edit their definitions -} \ No newline at end of file diff --git a/0077-new_definition b/0077-new_definition deleted file mode 100644 index bb712c7..0000000 --- a/0077-new_definition +++ /dev/null @@ -1,16 +0,0 @@ -new_definition = function() - if Cursor_node then - Cursor_node.show_cursor = false - end - table.insert(Definitions, { - type='text', - data={''}, - x=Spawn_point.x, y=Spawn_point.y, - width=600, - bg=Border_color, -- TODO: bg isn't accurate if obj.drawmode = 'line' - }) - Viewport.x = Spawn_point.x-30 - Viewport.y = Spawn_point.y-30 - Cursor_node = Definitions[#Definitions] - Cursor_node.show_cursor = true -end diff --git a/0115-update_font_size b/0115-update_font_size deleted file mode 100644 index 54540bf..0000000 --- a/0115-update_font_size +++ /dev/null @@ -1,13 +0,0 @@ -update_font_size = function(n) - Font_height = n - love.graphics.setFont(love.graphics.newFont(Font_height)) - local font = love.graphics.getFont() - font:setLineHeight(1.3) - Line_height = math.floor(Font_height*1.3) - Menu_bar_height = 5 + Line_height + 5 - if Global_state.items then - for _,item in ipairs(Global_state.items) do - edit.update_font_settings(item, n) - end - end -end \ No newline at end of file diff --git a/0117-open_thread b/0117-open_thread index b2df6e2..d8ff191 100644 --- a/0117-open_thread +++ b/0117-open_thread @@ -1,5 +1,6 @@ open_thread = function(filename) - Global_state.items = {} - load_subtree(filename, Global_state.items) + Global_state.root = rows() + load_subtree(filename, Global_state.root.data, 0) love.window.setTitle('pothi.love - '..filename) + A() end \ No newline at end of file diff --git a/0118-load_subtree b/0118-load_subtree index 4e868b3..8167969 100644 --- a/0118-load_subtree +++ b/0118-load_subtree @@ -1,8 +1,14 @@ load_subtree = function(filename, out, depth) -- load a file and recursively all replies to it -- print('load_subtree', filename) - local item = initialize_item(filename) - table.insert(out, item) + local item = initialize_item(filename, depth) + -- every item is a row consisting of two columns: + -- one column of padding and another of text + local row = cols() + table.insert(row.data, + {type='rectangle', w=depth*Indent, h=0}) + table.insert(row.data, item) + table.insert(out, row) for i,reply_id in ipairs(item.metadata.replies) do local reply = load_subtree(reply_id, out, depth+1) end diff --git a/0120-initialize_item b/0120-initialize_item index 7592b65..7b95171 100644 --- a/0120-initialize_item +++ b/0120-initialize_item @@ -5,6 +5,8 @@ initialize_item = function(filename, depth) result.data = result.lines result.lines = nil -- more fields + result.type = 'text' + result.width = Width result.depth = depth result.metadata = load_metadata(filename) return result diff --git a/0124-Indent b/0124-Indent new file mode 100644 index 0000000..6e3c197 --- /dev/null +++ b/0124-Indent @@ -0,0 +1 @@ +Indent = 20 -- number of pixels to indent replies by \ No newline at end of file diff --git a/0125-Width b/0125-Width new file mode 100644 index 0000000..834641c --- /dev/null +++ b/0125-Width @@ -0,0 +1 @@ +Width = 600 \ No newline at end of file