I added Text Style Sheet with bold style: <style=“bold”>text text
But when I’m using it in Label, its width is incorrectly calculated, looks like instead of result text width, original width of text with tags is used, although excluding closing tag.
You can see the issue in the screenshot, 1st Label has incorrect width (I marked space that shouldn’t be there), 2nd Label has the same text but with disabled Rich Text, 3rd is just bold text () without style.
index.uxml
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
<Style src="project://database/Assets/NewUSSFile.uss?fileID=7433441132597879392&guid=e80ab3813b9fd9240a67b2e1a7b3a693&type=3#NewUSSFile" />
<ui:VisualElement class="row">
<ui:Label text="<style="bold">bold style text</style>" />
<ui:Label text="Label" />
</ui:VisualElement>
<ui:VisualElement class="row">
<ui:Label text="<style="bold">bold style text</style>" enable-rich-text="false" />
<ui:Label text="Label" />
</ui:VisualElement>
<ui:VisualElement class="row">
<ui:Label text="<b>b text</b>" />
<ui:Label text="Label" />
</ui:VisualElement>
</ui:UXML>
style.uss
.row {
justify-content: space-between;
flex-direction: row;
}
Label {
background-color: white;
}