about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-08-24 13:35:21 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-08-24 13:35:21 -0700
commit0bdadfdafeb54c6b7f05f80f80c7d99d62f2e9c7 (patch)
tree1a23be86b3e30125900a98cde5c9dc959695c848
parent151e7dfe0f688929187fce8968156f512d699a5c (diff)
parent89081a8a78acd755f2c9b9899f341113c9f63c30 (diff)
downloadview.love-0bdadfdafeb54c6b7f05f80f80c7d99d62f2e9c7.tar.gz
Merge text.love
-rw-r--r--edit.lua1
-rw-r--r--main.lua11
2 files changed, 12 insertions, 0 deletions
diff --git a/edit.lua b/edit.lua
index 3d1fe2a..2b7cf31 100644
--- a/edit.lua
+++ b/edit.lua
@@ -248,6 +248,7 @@ function edit.update_font_settings(State, font_height)
   love.graphics.setFont(love.graphics.newFont(Editor_state.font_height))
   State.line_height = math.floor(font_height*1.3)
   State.em = App.newText(love.graphics.getFont(), 'm')
+  Text_cache = {}
 end
 
 --== some methods for tests
diff --git a/main.lua b/main.lua
index 984ab3e..9f04f22 100644
--- a/main.lua
+++ b/main.lua
@@ -17,6 +17,9 @@ Editor_state = {}
 function App.initialize_globals()
   -- tests currently mostly clear their own state
 
+  -- a few text objects we can avoid recomputing unless the font changes
+  Text_cache = {}
+
   -- blinking cursor
   Cursor_time = 0
 
@@ -200,3 +203,11 @@ function App.keyreleased(key, scancode)
   Cursor_time = 0  -- ensure cursor is visible immediately after it moves
   return edit.key_released(Editor_state, key, scancode)
 end
+
+-- use this sparingly
+function to_text(s)
+  if Text_cache[s] == nil then
+    Text_cache[s] = App.newText(love.graphics.getFont(), s)
+  end
+  return Text_cache[s]
+end