Skip to content

Commit

Permalink
Fixed issue with text width measurement
Browse files Browse the repository at this point in the history
  • Loading branch information
britzl committed Feb 28, 2018
1 parent 29aebbd commit 382bacd
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions richtext/richtext.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,18 @@ function M.create(text, font, settings)
word.metrics.width = word.metrics.width * word.size
word.metrics.height = word.metrics.height * word.size

-- update text metrics width
local current_width = position.x - settings.position.x
text_metrics.width = math.max(text_metrics.width, current_width)

-- move word to next row if it overflows the width
local current_width = position.x - settings.position.x
local width = current_width + word.metrics.width
if settings.width and width > settings.width then
position.y = position.y - highest_word
position.x = settings.position.x
highest_word = word.metrics.height
text_metrics.width = math.max(text_metrics.width, current_width)
else
highest_word = math.max(highest_word, word.metrics.height)
text_metrics.width = math.max(text_metrics.width, width)
end

-- position word
Expand Down

0 comments on commit 382bacd

Please sign in to comment.