You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(layouts): text truncation & proper text alignment (#120)
feat(layouts): text truncation & proper text alignment
You can now set `truncate` to true in a text element, like this:
```toml
wrap_width = 130.0
truncate = true
```
The text is truncated at the given wrap width instead of wrapped.
While I was truncating text and just generally figuring out what these
imgui functions do, I returned to the problem of correctly-aligning
wrapped text. For right- and center-aligned text, this requires
looping through the full text rendering it one line at a time,
adjusting the position of each line to match its bounds. Further,
because imgui does not export any of its word-wrapping implementation,
we have to do additional work to find word boundaries. To do this, we
look for the nearest space preceding the imgui-selected wrap position.
If it's near enough, we break the line at that position, recalculate
bounds, and draw.
I broke out the text rendering cases so that simple cases do the least
work possible, and the space-seeking and bounds-adjusting work is only
done when required. The implementation of drawing text is somewhat
verbose as a result but each case is simple by itself.
Fixes [#104](#104)
Fixes [[#98](#98)]
Copy file name to clipboardExpand all lines: docs/article-layouts-v2.md
+5-1Lines changed: 5 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -112,11 +112,13 @@ Each slot layout has a list of *text* elements. These describe text that should
112
112
113
113
Here are the fields a text element has:
114
114
115
-
-`offset`: Where to draw this text, relative to the center of the slot
115
+
-`offset`: Where to draw this text, relative to the center of the slot. This location is the *left edge* of the text box.
116
116
-`alignment`: How to justify the text. Possible values are `left`, `center`, and `right`.
117
117
-`font_size`: A floating-point number for the size of the type used.
118
118
-`color`: The color to use to draw the text.
119
119
-`contents`: A format string describing the text to draw.
120
+
-`wrap_width`: The maximum allowed width of the text. If set, text is wrapped if it would be longer.
121
+
` truncate`: A boolean value (`true` or `false`) indicating if the text should be cut short at the wrap width instead of wrapped. Set this to keep text at one line max.
120
122
121
123
The data that can be filled into a format string is:
122
124
@@ -147,6 +149,8 @@ color = { r = 255, g = 255, b = 255, a = 255 }
147
149
alignment = "left"
148
150
contents = "{name}"
149
151
font_size = 20.0
152
+
wrap_width = 130.0
153
+
truncate = false
150
154
```
151
155
152
156
Any additional text elements for the power slot would also be named `[[power.text]]`. The double square brackets tells TOML that this is an [list of items](https://toml.io/en/v1.0.0#array-of-tables). Each new element named that is added to the end of the list.
0 commit comments