diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2023-04-01 16:29:17 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2023-04-01 18:12:29 -0700 |
commit | 876d6298b40fc8b00bf559d4ec2d909ab1e6bc80 (patch) | |
tree | 8a949ceac0f9c6010a6de42518683ba9b75a3450 /drawing.lua | |
parent | 4ab901c92e11f47828bc7f5f16d8d2250812d53f (diff) | |
download | text.love-876d6298b40fc8b00bf559d4ec2d909ab1e6bc80.tar.gz |
App.width can no longer take a Text
In the process I discovered the horrible fact that Text.x allocates a new Text. And it gets called (just once, thank goodness) on every single frame.
Diffstat (limited to 'drawing.lua')
-rw-r--r-- | drawing.lua | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/drawing.lua b/drawing.lua index 99193c6..5af25fb 100644 --- a/drawing.lua +++ b/drawing.lua @@ -60,14 +60,13 @@ function Drawing.draw(State, line_index, y) if State.current_drawing_mode == 'name' and i == line.pending.target_point then -- create a faint red box for the name App.color(Current_name_background_color) - local name_text - -- TODO: avoid computing name width on every repaint + local name_width if p.name == '' then - name_text = State.em + name_width = App.width('m') else - name_text = App.newText(love.graphics.getFont(), p.name) + name_width = App.width(p.name) end - love.graphics.rectangle('fill', x,y, App.width(name_text), State.line_height) + love.graphics.rectangle('fill', x,y, name_width, State.line_height) end end end |