about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-09-17 23:01:40 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-09-17 23:01:40 -0700
commitcea2730080b80e1c8d3c4ad1196429ff282b7c1c (patch)
treedcc7a319af64c1fb7f2534f971c2e0ca2789f705
parent620176263a2a2a6f2dac2940a50392e7c8bc71d1 (diff)
downloadlines.love-cea2730080b80e1c8d3c4ad1196429ff282b7c1c.tar.gz
use a helper
-rw-r--r--commands.lua18
1 files changed, 7 insertions, 11 deletions
diff --git a/commands.lua b/commands.lua
index 29e4a3e..b30013c 100644
--- a/commands.lua
+++ b/commands.lua
@@ -42,15 +42,13 @@ function source.draw_menu_bar()
 end
 
 function add_hotkey_to_menu(s)
-  if Text_cache[s] == nil then
-    Text_cache[s] = App.newText(love.graphics.getFont(), s)
-  end
-  local width = App.width(Text_cache[s])
+  local s_text = to_text(s)
+  local width = App.width(s_text)
   if Menu_cursor + width > App.screen.width - 5 then
     return
   end
   App.color(Menu_command_color)
-  App.screen.draw(Text_cache[s], Menu_cursor,5)
+  App.screen.draw(s_text, Menu_cursor,5)
   Menu_cursor = Menu_cursor + width + 30
 end
 
@@ -68,20 +66,18 @@ function source.draw_file_navigator()
 end
 
 function add_file_to_menu(s, cursor_highlight)
-  if Text_cache[s] == nil then
-    Text_cache[s] = App.newText(love.graphics.getFont(), s)
-  end
-  local width = App.width(Text_cache[s])
+  local s_text = to_text(s)
+  local width = App.width(s_text)
   if Menu_cursor + width > App.screen.width - 5 then
     log(2, 'skipped')
     return
   end
   if cursor_highlight then
     App.color(Menu_highlight_color)
-    love.graphics.rectangle('fill', Menu_cursor-5,5-2, App.width(Text_cache[s])+5*2,Editor_state.line_height+2*2)
+    love.graphics.rectangle('fill', Menu_cursor-5,5-2, App.width(s_text)+5*2,Editor_state.line_height+2*2)
   end
   App.color(Menu_command_color)
-  App.screen.draw(Text_cache[s], Menu_cursor,5)
+  App.screen.draw(s_text, Menu_cursor,5)
   Menu_cursor = Menu_cursor + width + 30
 end