scenario: run without config file, quit, run again
expected: font size remains the same on second run

Before this commit it was increasing on each run.
It turns out the font height that you pass into love.graphics.newFont()
is not the result of font:getHeight().
This commit is contained in:
Kartik K. Agaram 2023-12-29 11:52:28 -08:00
parent 6601c9fad8
commit bd2179d8aa
6 changed files with 12 additions and 10 deletions

View File

@ -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, line_height) -- currently always draws to bottom of screen
function edit.initialize_state(top, left, right, font, font_height, 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:
@ -84,7 +84,7 @@ function edit.initialize_state(top, left, right, font, line_height) -- currentl
previous_drawing_mode = nil, -- extra state for some ephemeral modes like moving/deleting/naming points
font = font,
font_height = font:getHeight(),
font_height = font_height,
line_height = line_height,
top = top,
@ -568,6 +568,7 @@ function edit.initialize_test_state()
Test_margin_left,
App.screen.width - Test_margin_right,
love.graphics.getFont(),
14,
15) -- line height
end

View File

@ -6,7 +6,7 @@
-- functions to render them into the log_render namespace.
function source.initialize_log_browser_side()
Log_browser_state = edit.initialize_state(Margin_top, Editor_state.right + Margin_right + Margin_left, (Editor_state.right+Margin_right)*2, Editor_state.font, Editor_state.line_height)
Log_browser_state = edit.initialize_state(Margin_top, Editor_state.right + Margin_right + Margin_left, (Editor_state.right+Margin_right)*2, Editor_state.font, Editor_state.font_height, Editor_state.line_height)
Log_browser_state.filename = 'log'
load_from_disk(Log_browser_state) -- TODO: pay no attention to Fold
log_browser.parse(Log_browser_state)

View File

@ -190,8 +190,8 @@ There's much more I could include here; check out [the LÖVE manual](https://lov
The text-editor widget includes extremely thorough automated tests to give you
early warning if you break something.
* `state = edit.initialize_state(top, left, right, font, line_height)` --
returns an object that can be used to render an interactive editor widget
* `state = edit.initialize_state(top, left, right, font, font_height, line_height)`
-- returns an object that can be used to render an interactive editor widget
for text and line drawings starting at `y=top` on the app window, between
`x=left` and `x=right`. Wraps long lines at word boundaries where possible,
or in the middle of words (no hyphenation yet) when it must.

View File

@ -61,7 +61,7 @@ function run.load_settings()
App.screen.width, App.screen.height = Settings.width, Settings.height
App.screen.resize(App.screen.width, App.screen.height, App.screen.flags)
run.set_window_position_from_settings(Settings)
Editor_state = edit.initialize_state(Margin_top, Margin_left, App.screen.width-Margin_right, font, math.floor(Settings.font_height*1.3))
Editor_state = edit.initialize_state(Margin_top, Margin_left, App.screen.width-Margin_right, font, Settings.font_height, math.floor(Settings.font_height*1.3))
Editor_state.filename = Settings.filename
Editor_state.screen_top1 = Settings.screen_top
Editor_state.cursor1 = Settings.cursor
@ -81,7 +81,7 @@ function run.initialize_default_settings()
local font_height = 20
local font = love.graphics.newFont(font_height)
run.initialize_window_geometry()
Editor_state = edit.initialize_state(Margin_top, Margin_left, App.screen.width-Margin_right, font, math.floor(font_height*1.3))
Editor_state = edit.initialize_state(Margin_top, Margin_left, App.screen.width-Margin_right, font, font_height, math.floor(font_height*1.3))
Settings = run.settings()
end

View File

@ -126,7 +126,7 @@ function source.load_settings()
if Show_log_browser_side then
right = App.screen.width/2 - Margin_right
end
Editor_state = edit.initialize_state(Margin_top, Margin_left + Line_number_width*App.width('m'), right, font, math.floor(settings.font_height*1.3))
Editor_state = edit.initialize_state(Margin_top, Margin_left + Line_number_width*App.width('m'), right, font, font_height, math.floor(settings.font_height*1.3))
Editor_state.filename = settings.filename
Editor_state.filename = basename(Editor_state.filename) -- migrate settings that used full paths; we now support only relative paths within the app
if settings.cursors then
@ -154,7 +154,7 @@ function source.initialize_default_settings()
local font_height = 20
local font = love.graphics.newFont(font_height)
source.initialize_window_geometry()
Editor_state = edit.initialize_state(Margin_top, Margin_left + Line_number_width*App.width('m'), App.screen.width-Margin_right, font, math.floor(font_height*1.3))
Editor_state = edit.initialize_state(Margin_top, Margin_left + Line_number_width*App.width('m'), App.screen.width-Margin_right, font, font_height, math.floor(font_height*1.3))
Editor_state.filename = 'run.lua'
end

View File

@ -25,7 +25,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, line_height) -- currently always draws to bottom of screen
function edit.initialize_state(top, left, right, font, font_height, 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:
@ -572,6 +572,7 @@ function edit.initialize_test_state()
Test_margin_left,
App.screen.width - Test_margin_right,
love.graphics.getFont(),
14,
15) -- line height
end