From cea2730080b80e1c8d3c4ad1196429ff282b7c1c Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 17 Sep 2022 23:01:40 -0700 Subject: [PATCH] use a helper --- commands.lua | 18 +++++++----------- 1 file 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