diff --git a/0019-B b/0019-B index 6e59917..beb6033 100644 --- a/0019-B +++ b/0019-B @@ -1,6 +1,7 @@ B = function() -- print('B') -- recompute various aspects based on the current viewport settings + local font = nil for _,obj in ipairs(Surface) do if obj.type == 'line' then obj.zdata = {} @@ -17,7 +18,8 @@ B = function() obj.zdata = love.math.newBezierCurve(zdata):render() elseif obj.type == 'text' then if obj.w then - update_editor_box(obj) + update_editor_box(obj, font) + if obj.editor and obj.editor.font then font = obj.editor.font end else obj.text = love.graphics.newText(love.graphics.getFont(), obj.data) end diff --git a/0021-compute_layout b/0021-compute_layout index debbba3..cb055f9 100644 --- a/0021-compute_layout +++ b/0021-compute_layout @@ -1,4 +1,4 @@ -compute_layout = function(node, x,y, nodes_to_render) +compute_layout = function(node, x,y, nodes_to_render, font) --[[ --debug prints when modifying the DOM if node.type == 'rows' or node.type == 'cols' then print(node.type, node.button, #node.data) @@ -38,7 +38,7 @@ compute_layout = function(node, x,y, nodes_to_render) if node.editor == nil then initialize_editor(node) else - update_editor_box(node) + update_editor_box(node, font) end node.h = box_height(node) table.insert(nodes_to_render, node) @@ -66,7 +66,7 @@ compute_layout = function(node, x,y, nodes_to_render) if not child.width then child.width = node.width -- HACK: should we set child.w or child.width? Neither is quite satisfactory. end - subx,suby = compute_layout(child, x,suby, nodes_to_render) + subx,suby = compute_layout(child, x,suby, nodes_to_render, font) if w < child.w then w = child.w end @@ -94,7 +94,7 @@ compute_layout = function(node, x,y, nodes_to_render) subx = subx+child.margin w = w+child.margin end - subx,suby = compute_layout(child, subx,y, nodes_to_render) + subx,suby = compute_layout(child, subx,y, nodes_to_render, font) w = w + child.w if h < child.h then h = child.h diff --git a/0028-A b/0028-A index c95c1d4..bcaae09 100644 --- a/0028-A +++ b/0028-A @@ -1,12 +1,13 @@ A = function() -- print('A') - love.graphics.setFont(love.graphics.newFont(scale(20))) -- editor objects implicitly depend on current font + local font = love.graphics.newFont(scale(20)) + love.graphics.setFont(font) -- editor objects implicitly depend on current font -- translate some page in Global_state to Surface Surface = {} if Global_state.thread == nil then lay_out_file_picker() else - compute_layout(Global_state.thread, 0,0, Surface, skip_updating_screen_top_for) + compute_layout(Global_state.thread, 0,0, Surface, skip_updating_screen_top_for, font) end compute_viewport_bounds() -- continue the pipeline diff --git a/0030-update_editor_box b/0030-update_editor_box index 9c82d62..a028242 100644 --- a/0030-update_editor_box +++ b/0030-update_editor_box @@ -1,7 +1,7 @@ -update_editor_box = function(node) +update_editor_box = function(node, font) if node.editor == nil then return end if node.editor.font_height ~= scale(20) then - edit.update_font_settings(node.editor, scale(20)) + edit.update_font_settings(node.editor, scale(20), font) end node.editor.left = math.floor(vx(node.x)) node.editor.right = math.ceil(vx(node.x+node.w)) diff --git a/edit.lua b/edit.lua index 098679d..3b4aed9 100644 --- a/edit.lua +++ b/edit.lua @@ -379,9 +379,9 @@ end function edit.key_release(State, key, scancode) end -function edit.update_font_settings(State, font_height) +function edit.update_font_settings(State, font_height, font) State.font_height = font_height - State.font = love.graphics.newFont(State.font_height) + State.font = font or love.graphics.newFont(State.font_height) State.line_height = math.floor(font_height*1.3) end