-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement wrapWord parameter (#268) #345
base: dev
Are you sure you want to change the base?
Changes from 5 commits
da89c2e
98b45c9
8a939ad
4f47680
c7f8c9c
856cc7c
3c98b21
dab52d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,7 @@ export function layoutText( | |
scrollable: TrProps['scrollable'], | ||
overflowSuffix: TrProps['overflowSuffix'], | ||
maxLines: TrProps['maxLines'], | ||
wrapWord: TrProps['wrapWord'], | ||
): { | ||
bufferNumFloats: number; | ||
bufferNumQuads: number; | ||
|
@@ -292,6 +293,24 @@ export function layoutText( | |
maxX = Math.max(maxX, quadX + glyph.width); | ||
curX += glyph.xAdvance; | ||
} | ||
if ( | ||
marcel-danilewicz-consult-red marked this conversation as resolved.
Show resolved
Hide resolved
|
||
wrapWord == 'break' && | ||
charEndX + glyph.width >= lineVertexW && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is that correct? Wrap-word I think is meant to only wrap a word when this word alone is larger than the wrapping width. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought it should be wrapped if the width is exceeded. So if a word doesn't fit it should be moved to the next line and then if still doesn't fit it should be wrapped? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be silly to break every word. The point is that sometimes (as reported in #268) you may have a single word larger than the target width, in which case you may prefer to break it. In L2, that's what I suggest again to make sure that the requirements are non-ambiguous - ask @wouterlucas for confirmation. Make a diagram/drawing to explain what you are going to do. In any case it is very wise to have proposed an early draft. |
||
contain != 'none' | ||
) { | ||
if (curLineBufferStart !== -1 && lineIsWithinWindow) { | ||
bufferLineInfos.push({ | ||
bufferStart: curLineBufferStart, | ||
bufferEnd: bufferOffset, | ||
}); | ||
curLineBufferStart = -1; | ||
} | ||
curX = 0; | ||
curY += vertexLineHeight; | ||
curLineIndex++; | ||
lastWord.codepointIndex = -1; | ||
xStartLastWordBoundary = 0; | ||
} | ||
} else { | ||
// Unmapped character | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is incorrect in some cases, and inefficient in general. You should instead break words as part of the
wrapText
function.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this is inside of
wrapText
function :)Could you give me an example of NG case for this code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but it is misplaced I think: it re-measures every word which we already measure in the above loop - could the break happen as part of the above wrapping logic? Also isn't that a different breaking logic as SDF? It seems SDF tries to cut the word to fit the line, isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It remeasures whole lines. I'd rather separate normal and break cases, but you are right that the code can be optimized. Algorithms are not the same due to different surrounding code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No
allLines
has all the individual words, andrealNewlines
tells the index of each new line's first word.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the algorithm in last commit. It should be better now, but words still need to be measured in order to find the breaking point. Probably it can be optimized further , but I don't see a way to entirely avoid measurement.