about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--edit.lua1
-rw-r--r--help.lua7
-rw-r--r--main.lua11
3 files changed, 13 insertions, 6 deletions
diff --git a/edit.lua b/edit.lua
index 7a59ff3..f5dc1f2 100644
--- a/edit.lua
+++ b/edit.lua
@@ -467,6 +467,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/help.lua b/help.lua
index 2abeb00..145692f 100644
--- a/help.lua
+++ b/help.lua
@@ -146,11 +146,6 @@ function current_shape(State, shape)
   end
 end
 
-_bullet_indent = nil
 function bullet_indent()
-  if _bullet_indent == nil then
-    local text = love.graphics.newText(love.graphics.getFont(), '* ')
-    _bullet_indent = text:getWidth()
-  end
-  return _bullet_indent
+  return App.width(to_text('* '))
 end
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
'>187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269