summaryrefslogtreecommitdiff
path: root/src/ui/text.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-05-14 08:45:51 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-05-14 08:45:51 +0300
commit8d2880f97638e131cbca4f0b355bca350dc3b97d (patch)
treeea57ffed59996812031b7374fc0001fe9bbc9c3d /src/ui/text.c
parent9883a206295fbdac3d4282836dca52d78c5e88dc (diff)
Text: Fixed handling of newlines
In the `tryAdvance*` methods, don't advance past newlines since this is intended to be a line-based operation.
Diffstat (limited to 'src/ui/text.c')
-rw-r--r--src/ui/text.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/ui/text.c b/src/ui/text.c
index eca0952d..b0c4f557 100644
--- a/src/ui/text.c
+++ b/src/ui/text.c
@@ -781,6 +781,7 @@ enum iRunMode {
781 permanentColorFlag_RunMode = iBit(11), 781 permanentColorFlag_RunMode = iBit(11),
782 alwaysVariableWidthFlag_RunMode = iBit(12), 782 alwaysVariableWidthFlag_RunMode = iBit(12),
783 fillBackground_RunMode = iBit(13), 783 fillBackground_RunMode = iBit(13),
784 stopAtNewline_RunMode = iBit(14), /* don't advance past \n, consider it a wrap pos */
784}; 785};
785 786
786static enum iFontId fontId_Text_(const iFont *font) { 787static enum iFontId fontId_Text_(const iFont *font) {
@@ -923,7 +924,7 @@ static iRect run_Font_(iFont *d, const iRunArgs *args) {
923 } 924 }
924 /* TODO: Check out if `uc_wordbreak_property()` from libunistring can be used here. */ 925 /* TODO: Check out if `uc_wordbreak_property()` from libunistring can be used here. */
925 if (ch == '\n') { 926 if (ch == '\n') {
926 if (args->xposLimit > 0 && ~mode & noWrapFlag_RunMode) { 927 if (args->xposLimit > 0 && mode & stopAtNewline_RunMode) {
927 /* Stop the line here, this is a hard warp. */ 928 /* Stop the line here, this is a hard warp. */
928 if (args->continueFrom_out) { 929 if (args->continueFrom_out) {
929 *args->continueFrom_out = chPos; 930 *args->continueFrom_out = chPos;
@@ -1148,7 +1149,8 @@ iInt2 advanceRange_Text(int fontId, iRangecc text) {
1148iInt2 tryAdvance_Text(int fontId, iRangecc text, int width, const char **endPos) { 1149iInt2 tryAdvance_Text(int fontId, iRangecc text, int width, const char **endPos) {
1149 int advance; 1150 int advance;
1150 const int height = run_Font_(font_Text_(fontId), 1151 const int height = run_Font_(font_Text_(fontId),
1151 &(iRunArgs){ .mode = measure_RunMode | runFlagsFromId_(fontId), 1152 &(iRunArgs){ .mode = measure_RunMode | stopAtNewline_RunMode |
1153 runFlagsFromId_(fontId),
1152 .text = text, 1154 .text = text,
1153 .xposLimit = width, 1155 .xposLimit = width,
1154 .continueFrom_out = endPos, 1156 .continueFrom_out = endPos,
@@ -1161,6 +1163,7 @@ iInt2 tryAdvanceNoWrap_Text(int fontId, iRangecc text, int width, const char **e
1161 int advance; 1163 int advance;
1162 const int height = run_Font_(font_Text_(fontId), 1164 const int height = run_Font_(font_Text_(fontId),
1163 &(iRunArgs){ .mode = measure_RunMode | noWrapFlag_RunMode | 1165 &(iRunArgs){ .mode = measure_RunMode | noWrapFlag_RunMode |
1166 stopAtNewline_RunMode |
1164 runFlagsFromId_(fontId), 1167 runFlagsFromId_(fontId),
1165 .text = text, 1168 .text = text,
1166 .xposLimit = width, 1169 .xposLimit = width,