Fix minimum word width calculation#9004
Conversation
|
Build Stats
|
…s into fix-minimum-word-width
ShaMan123
left a comment
There was a problem hiding this comment.
This looks good
I would like to rename the use of words to parts or something else because in case of splitByGrapheme it is not words and very confusing.
I also think we should change the signature of _wrapLine to be more orderly
_wrapLine(lie, lineIndex, context)
Pull in the test from #8994
Regardless I think we should hold the entire measurement data in wordsData and reuse it in case of resizing, it optimizes perf significantly.
If we do that overriding, measureWords allows easy customization of wrapping (this is what I am doing) because it will contain of the data needed.
Let me verify if this fix what i think it fixes ( i think is just a case in initialization ), let's see then what is missing for your overrides need, then we can also rename and change signature of private methods in another PR. |
| * measure each word width and extract the largest word from all. | ||
| * @param {string[]} lines the lines we need to measure | ||
| */ | ||
| measureWords(lines: string[]): WordsWidthData { |
There was a problem hiding this comment.
@ShaMan123 this code now works as your for what regards min word width.
You said that this would be enough to also let you override the code, but in that case we need to be specific of the requirements of this functions.
Seems to me that this on top of measuring is also deciding the words that are going to be rendered?
(ex: swapping last word for ellipsis)
like are you returning different words from this function from the one that are in input?
in that case we need to rename it accordingly and also specify this in the returned type and description.
There was a problem hiding this comment.
this function so far would be something like:
getGraphemeDataForRender
measureAndSplitWords
getSplittedWords
getSplitWordsInfo
There was a problem hiding this comment.
So I have a few things.
(ex: swapping last word for ellipsis)
Yes. I am doing that exactly. And I can PR it if you wish.
I am also breaking words, this is why it is crucial to manage the infix here as well because then I can add and measure the infix, or not if I am simply breaking a word. It makes sense to have all measuring in one place, another reason to move infix measuring to here.
We should move this method to Text, it belongs there IMO.
Then the measureChars function should use it instead of remeasuring.
Positioning data (left, top => getGraphemeDataForRender) should be applied separately because these props are invalidated more frequently (always actually) where as the words data (width, height) could be cached to improve perf.
I have something POCing this and the perf diff is extremely significant when I apply caching.
There was a problem hiding this comment.
And actually it means that _wrapLine becomes a very standard method
There was a problem hiding this comment.
Don't poc anything i m not accepting new features, i m trying to let you get the method you need without flipping textbox now.
How can we get to what you need without revolutionin the code now?
| offset = 0; | ||
| let i; | ||
| for (i = 0; i < words.length; i++) { | ||
| for (i = 0; i < data.length; i++) { |
There was a problem hiding this comment.
there is probably something else that can be done down here to bring infix width calculation in measure words.
but i m intentionally skipping it for now.
Seems like line 419 could be pused in the else condition after 415.
i m also not convinced at all from the offset++ at line 426, but eventually it works
There was a problem hiding this comment.
Yes, all this is correct.
I did that in the other PR.
There was a problem hiding this comment.
Now it will make sense to you.
| } | ||
|
|
||
| // measure words | ||
| data[i] = words.map((word) => { |
There was a problem hiding this comment.
welll the previus for loop didn't exist, so i can use lines.map yes
| * measure each word width and extract the largest word from all. | ||
| * @param {string[]} lines the lines we need to measure | ||
| */ | ||
| measureWords(lines: string[]): WordsWidthData { |
There was a problem hiding this comment.
So I have a few things.
(ex: swapping last word for ellipsis)
Yes. I am doing that exactly. And I can PR it if you wish.
I am also breaking words, this is why it is crucial to manage the infix here as well because then I can add and measure the infix, or not if I am simply breaking a word. It makes sense to have all measuring in one place, another reason to move infix measuring to here.
We should move this method to Text, it belongs there IMO.
Then the measureChars function should use it instead of remeasuring.
Positioning data (left, top => getGraphemeDataForRender) should be applied separately because these props are invalidated more frequently (always actually) where as the words data (width, height) could be cached to improve perf.
I have something POCing this and the perf diff is extremely significant when I apply caching.
|
@ShaMan123 let me know if this is helpful and if you want to merge it. |
ShaMan123
left a comment
There was a problem hiding this comment.
This is almost there.
I want the infix as part of this change
Also please rename:
- All the use of words to something else because when splitting by grapheme words are not words and it is awfully confusing.
- getGraphemeDataForRender => this is not for rendering, it is for layout. The rendering measurements are in renderChar
|
without handling the infix I can't control word breaking because |
|
this part doesn't make sense in |
|
@asturur please merge this before you publish. |
It Doesn't make sense anymore because we moved the calculation up, and this code is now sort of unnecessary. |
| }); | ||
|
|
||
| return { | ||
| wordsData: data, |
There was a problem hiding this comment.
I am not happy about naming
#8994!! That is why I changed so much, because of all this ugliness |
|
I am not 100% happy of naming and overall state of this PR |
Motivation
While working on text measurement reorganization, @ShaMan123 found some possible improvemente in the handlin of the minimum text width/ largest word width.
This PR is the extraction of that improvement from his PR that has too many changes.
reference:
#8994
Changes
Gist
In Action