Skip to content

Conversation

hatal175
Copy link
Contributor

@hatal175 hatal175 commented Aug 2, 2021

This should fix the sonny hover text issue. Since relayout sets the bounds width if wordwrap is false, it needs to reset it to the default width if it's true.

There are still some font and layout issues (text is not bold or bounding borders are not the same, so this is not a complete fix.

@adrian17
Copy link
Collaborator

adrian17 commented Aug 2, 2021

I think this isn't a correct fix - as in, it removes one symptom that happens to occur in Sonny, but not the root issue. I'll try to reproduce it in Flash and come back to you.

@hatal175
Copy link
Contributor Author

hatal175 commented Aug 2, 2021

I relied on the table https://flylib.com/books/en/4.13.1.618/1/ when trying to figure out the correct behavior, if it helps.
the code from sonny because it's a headache to find:

this.createTextField("my_txt3",2,scaffold,21,150,120);
my_txt3.color = 16777215;
my_txt3.autoSize = "left";
my_txt3.border = true;
my_txt3.multiline = true;
my_txt3.text = t3;
my_txt3.wordWrap = true;
var my_fmt3 = new TextFormat();
my_fmt3.font = "_sans";
my_fmt3.color = 51;
my_fmt3.size = 12;
my_fmt3.indent = 2;
my_txt3.setTextFormat(my_fmt3);
fontBacker3._height = my_txt3._height;
fontBacker3._width = my_txt3._width;
fontBacker3._x = my_txt3._x;
fontBacker3._y = my_txt3._y;

@adrian17
Copy link
Collaborator

adrian17 commented Aug 2, 2021

OK, so while I mentioned this a couple times in comments in some issues like #3163 and on Discord, I never properly wrote up an issue about this, so that's my bad.

As far as I understand it, the true issue actually has nothing to do with autosize+wordwrap, it has to do with our core design of relayout.

Here's a fun demo in AS2:

Code A:

// original tf._width is 240.95
tf.text = "aaaaaa";
tf.autoSize = "left";
//var unused = tf._width;
tf.wordWrap = true;
trace(tf._width);

Code B:

// original tf._width is 240.95
tf.text = "aaaaaa";
tf.autoSize = "left";
var unused = tf._width;
tf.wordWrap = true;
trace(tf._width);

Note that the only difference is uncommented comment.

And here's the result comparison between Flash, Ruffle and your PR (feel free to only look at order of magnitude differences due to other small-scale inconsistencies :) ):

- Flash Ruffle This PR
Code A (comment) 240.95 46.8 238.95
Code B (uncommented) 40 46.8 238.95

Why does the commented code matter? Because just like in JS, the relayout is lazy - only invoking getters of layout-relying properties (like tf.width) or actually drawing the text will cause the relayout to fire. In Ruffle, instead, relayout() is eager and gets called after every setter.

So in Flash in code A there is one relayout:

  • autoSize=left, wordWrap=true (width is not changed)

In Ruffle there are two:

  • autoSize=left, wordWrap=false (width gets reduced)
  • autosize=left, wordWrap=true (width is not changed, but it was already reduced before <- here your PR changes it "back to original")

So in a way, your PR changes it from one kind of wrong to another :( It can also regress movies in other "less obscure" cases, like: you change autoSize in one frame and wordWrap in another frame - you can observe it doesn't actually "return to original width".

The correct fix is to refactor edit_text.rs to do relayout lazily (or do it eagerly without "committing" the results until they should be); this means the entire rendering call stack needs to have MutationContext passed around so that the object can be mutated during render phase (which we generally avoided before). I actually tried this a couple months ago but got weird results and put it aside :(

(btw, I really hope this only concerns the text fields and not the entire graphics stack)

@hatal175
Copy link
Contributor Author

hatal175 commented Aug 2, 2021

closing this then.

@hatal175 hatal175 closed this Aug 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants