From 0f4aea6db747498467ab5b43a762ef3d5f39f56b Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Fri, 29 Dec 2023 11:18:41 -0800 Subject: pull font into editor Now it adjusts the current font for itself. And it's up to the caller to adjust the current font after. --- edit.lua | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'edit.lua') diff --git a/edit.lua b/edit.lua index 7b913fc..7f8a379 100644 --- a/edit.lua +++ b/edit.lua @@ -23,7 +23,7 @@ Same_point_distance = 4 -- pixel distance at which two points are considered th edit = {} -- run in both tests and a real run -function edit.initialize_state(top, left, right, font_height, line_height) -- currently always draws to bottom of screen +function edit.initialize_state(top, left, right, font, line_height) -- currently always draws to bottom of screen local result = { -- a line is either text or a drawing -- a text is a table with: @@ -83,7 +83,8 @@ function edit.initialize_state(top, left, right, font_height, line_height) -- c current_drawing_mode = 'line', -- one of the available shape modes previous_drawing_mode = nil, -- extra state for some ephemeral modes like moving/deleting/naming points - font_height = font_height, + font = font, + font_height = font:getHeight(), line_height = line_height, top = top, @@ -103,7 +104,7 @@ function edit.initialize_state(top, left, right, font_height, line_height) -- c search_backup = nil, -- stuff to restore when cancelling search } return result -end -- App.initialize_state +end -- edit.initialize_state function edit.check_locs(State) -- if State is inconsistent (i.e. file changed by some other program), @@ -156,6 +157,7 @@ end -- return y drawn until function edit.draw(State) State.button_handlers = {} + love.graphics.setFont(State.font) App.color(Text_color) assert(#State.lines == #State.line_cache, ('line_cache is out of date; %d elements when it should be %d'):format(#State.line_cache, #State.lines)) assert(Text.le1(State.screen_top1, State.cursor1), ('screen_top (line=%d,pos=%d) is below cursor (line=%d,pos=%d)'):format(State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos)) @@ -548,7 +550,7 @@ end function edit.update_font_settings(State, font_height) State.font_height = font_height - love.graphics.setFont(love.graphics.newFont(State.font_height)) + State.font = love.graphics.newFont(State.font_height) State.line_height = math.floor(font_height*1.3) end @@ -565,7 +567,7 @@ function edit.initialize_test_state() 15, -- top margin Test_margin_left, App.screen.width - Test_margin_right, - 14, -- font height assuming default LÖVE font + love.graphics.getFont(), 15) -- line height end -- cgit 1.4.1-2-gfad0