Merge luaML.love

A() determines the font and passes it in explicitly to all editors.
This commit is contained in:
Kartik K. Agaram 2024-07-10 01:27:25 -07:00
commit 6be4ab6c9e
5 changed files with 15 additions and 12 deletions

4
0019-B
View File

@ -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

View File

@ -1,4 +1,4 @@
compute_layout = function(node, x,y, nodes_to_render)
compute_layout = function(node, x,y, nodes_to_render, font)
-- 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)
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)
@ -59,7 +59,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
@ -87,7 +87,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

5
0028-A
View File

@ -1,11 +1,12 @@
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 Definitions to Surface
Surface = {}
for key,node in pairs(Definitions) do
node.key = key
compute_layout(node, node.x,node.y, Surface, skip_updating_screen_top_for)
compute_layout(node, node.x,node.y, Surface, skip_updating_screen_top_for, font)
end
-- continue the pipeline
B()

View File

@ -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)) + Line_number_width*node.editor.font:getWidth('m')
node.editor.right = math.ceil(vx(node.x+node.w))
@ -15,4 +15,4 @@ update_editor_box = function(node)
node.editor.screen_top1, node.editor.top = schema1_of_y(node.editor, scale(Viewport.y-node.y))
node.editor.top = node.editor.top + Menu_bar_height
end
end
end

View File

@ -359,9 +359,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