about summary refs log tree commit diff stats
path: root/main.lua
diff options
context:
space:
mode:
Diffstat (limited to 'main.lua')
-rw-r--r--main.lua11
1 files changed, 11 insertions, 0 deletions
diff --git a/main.lua b/main.lua
index f328139..a41d93b 100644
--- a/main.lua
+++ b/main.lua
@@ -16,6 +16,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
 
@@ -204,3 +207,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