Map the accessibility of VisualElement's IncrementVersion be set to public?

Map the accessibility of VisualElement’s IncrementVersion be set to protected?
When I customize VisualElement, I hope to increase the version as needed.
e.g. I changed the properties of the custom Visualelement, hoping to re-Layout.
Thanks for your attention!

Can you clarify what you mean by that? Custom layout is not possible at the moment, the only properties that can affect layout should already call “IncrementVersion(Layout)”.

Hello, thank you for your reply.:slight_smile:

I currently use unity 2021.2.0a17.2411.

I am customizing a Label. I expect that when the text changes, it will be re-layout and the yoga node can call DoMeasure to determine its own size.

In detail. I am customizing Label and TextField to handle combined emoji, such as ‍‍, and text selection, deletion and editing in TextField. Because I learned from the unity team that the combination emoji will not be supported until 2022, so my current combination emoji is implemented using the tag. However, there is a problem with the deletion of richtext tags in the TextField on the destop platform. On the mobile terminal, the operations of selecting, editing, and deleting are inconsistent with those on the mobile terminal.

I hope to have such an effect on the mobile platform

I am currently implementing it like this.

I did this by separating independent text elements into separate TextElement. So I need to handle the layout of the TextElement in the Label by myself.

I carefully read the source code in UI Toolkit preview-14 and found that requireMeasureFunction is only valid for visual elements without children. That is to say, my custom Label, because it has a shadow child node, cannot determine its own size by overloading the DoMeasure method.

Can you give me some better suggestions, I am currently stuck here and cannot move on anymore, thank you!

7390724--902312--截屏2021-08-05 下午2.17.31.png
7390724--902321--截屏2021-08-05 下午2.34.30.png

It looks like you are trying to overlay a TextField with a Label.
I would say the best course of action to achieve this would be to listen to GeometryChangedEvent for the Label and try to keep the TextField in sync with it.

If you wish to go with the DoMeasure() route, maybe you could have a parent that has the #content and the Label as children, instead of parenting #content in the Label. This way the DoMeasure code would be called?

Thank you very much, your suggestions gave me inspiration.:stuck_out_tongue:

My original plan was to implement two controls, Label and Textfield. They share a set of text display and layout logic.

So the newest method I use now is to add a leaf node under Label, position is relative, this leaf node is set to requireMeasureFunction, and the position of other child nodes of Label is set to absolute.

As shown in the figure below, the #measure-view is set to requireMeasureFunction, so that the DoMeasure of the #measure-view will be called, and the Label will be supported by the #measure-view.

For TextField, your suggestions are also very useful. I can use TextField to handle the logic of KeyboardTextEditorEventHandler and TouchScreenTextEditorEventHandler, and then use the above logic to process the display and layout of the text.

I currently use the following method to mark the re-layout. I found that setting the scale will call IncrementVersion(VersionChangeType.Transform | VersionChangeType.Layout);.

public bool requireMeasureFunction { set => GetType().GetProperty("requireMeasureFunction", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).SetValue(this, value);  }

//mark re-layout
protected internal void MarkDirtyLayout()
{
       this.transform.scale = Vector3.one * 0f;
       this.transform.scale = Vector3.one * 1f;
}

Thanks.:stuck_out_tongue:

7393901--902981--截屏2021-08-06 下午2.33.44.png