about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2023-12-29 11:52:28 -0800
committerKartik K. Agaram <vc@akkartik.com>2023-12-29 11:52:28 -0800
commitbd2179d8aa37e6088f20faae08fd6564a33e18c1 (patch)
tree9775eb972fa69ca272f681a4186ce508d9c4c494
parent6601c9fad87fb8b06df442c964486c8050fec3ac (diff)
downloadtext.love-bd2179d8aa37e6088f20faae08fd6564a33e18c1.tar.gz
bugfix
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().
-rw-r--r--edit.lua5
-rw-r--r--log_browser.lua2
-rw-r--r--reference.md4
-rw-r--r--run.lua4
-rw-r--r--source.lua4
-rw-r--r--source_edit.lua3
6 files changed, 12 insertions, 10 deletions
diff --git a/edit.lua b/edit.lua
index 7f8a379..ba6acda 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, 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
 
diff --git a/log_browser.lua b/log_browser.lua
index 3a42394..dabec2b 100644
--- a/log_browser.lua
+++ b/log_browser.lua
@@ -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)
diff --git a/reference.md b/reference.md
index 84f6f0e..df08f28 100644
--- a/reference.md
+++ b/reference.md
@@ -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.
diff --git a/run.lua b/run.lua
index fd01f46..2cdd892 100644
--- a/run.lua
+++ b/run.lua
@@ -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
 
diff --git a/source.lua b/source.lua
index d6ea40f..14d7afc 100644
--- a/source.lua
+++ b/source.lua
@@ -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
 
diff --git a/source_edit.lua b/source_edit.lua
index 9414ee4..8032278 100644
--- a/source_edit.lua
+++ b/source_edit.lua
@@ -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