Skip to content

Commit

Permalink
Added support for nobr tag that will allow words to overflow width limit
Browse files Browse the repository at this point in the history
  • Loading branch information
britzl committed Apr 11, 2018
1 parent 1d00199 commit b0bac29
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,20 @@ A workaround is to do like this instead:
## Supported tags
The following tags are supported:

| Tag | Description | Example |
|-------|------------------------------------------------|---------------------------------------|
| b | The text should be bold | `<b>Foobar</b>` |
| i | The text should be italic | `<i>Foobar</i>` |
| size | Change text size, relative to default size | `<size="2">Twice as large</size>` |
| color | Change text color | `<color=red>Foobar</color>` |
| | | `<color=1.0,0,0,1.0>Foobar</color>` |
| | | `<color=#ff0000>Foobar</color>` |
| | | `<color=#ff0000ff>Foobar</color>` |
| font | Change font | `<font=MyCoolFont>Foobar</font>` |
| img | Display image | `<img=texture:image/>` |
| spine | Display spine model | `<spine=scene:anim/>` |
| br | Insert a line break (see notes on linebreak) | `<br/>` |
| Tag | Description | Example |
|-------|------------------------------------------------|---------------------------------------------|
| b | The text should be bold | `<b>Foobar</b>` |
| i | The text should be italic | `<i>Foobar</i>` |
| size | Change text size, relative to default size | `<size="2">Twice as large</size>` |
| color | Change text color | `<color=red>Foobar</color>` |
| | | `<color=1.0,0,0,1.0>Foobar</color>` |
| | | `<color=#ff0000>Foobar</color>` |
| | | `<color=#ff0000ff>Foobar</color>` |
| font | Change font | `<font=MyCoolFont>Foobar</font>` |
| img | Display image | `<img=texture:image/>` |
| spine | Display spine model | `<spine=scene:anim/>` |
| br | Insert a line break (see notes on linebreak) | `<br/>` |
| nobr | Prevent the text from breaking | `Words <nobr>inside tag</nobr> won't break` |

### Line breaks
Note that there is no need for the HTML `<br/>` tag since line breaks (i.e. `\n`) are parsed and presented by the system. Note that a single `<br>` (ie without a closing or empty tag) isn't supported (even though most browsers accept it).
Expand Down
10 changes: 10 additions & 0 deletions example/example.gui_script
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,21 @@ local function create_spine_example()
end


local function create_nobreak_example()
local settings_nobr = { position = vmath.vector3(0, 600, 0), align = richtext.ALIGN_LEFT, width = 245 }
richtext.create("The image at the end should end up on a new line <nobr><img=smileys:cyclops/></nobr>", "Roboto-Regular", settings_nobr)

local settings_right = { position = vmath.vector3(320, 600, 0), align = richtext.ALIGN_LEFT, width = 245 }
richtext.create("The image at the end should end up on a new line <img=smileys:cyclops/>", "Roboto-Regular", settings_right)
end



function init(self)
create_complex_example()
create_align_example()
create_truncate_example()
create_characters_example()
create_spine_example()
create_nobreak_example()
end
2 changes: 2 additions & 0 deletions richtext/parse.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ local function parse_tag(tag, params)
scene = scene,
anim = anim
}
elseif tag == "nobr" then
settings.nobr = true
end

return settings
Expand Down
2 changes: 1 addition & 1 deletion richtext/richtext.lua
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ function M.create(text, font, settings)

-- does the word fit on the line or does it overflow?
local overflow = (settings.width and (line_width + word.metrics.width) > settings.width)
if overflow then
if overflow and not word.nobr then
-- overflow, position the words that fit on the line
position.x = settings.position.x
position.y = settings.position.y - text_metrics.height
Expand Down

0 comments on commit b0bac29

Please sign in to comment.