private void LoadTemplate(VisualTreeAsset tpl) { tpl.CloneTree(this); InitBadgeComponent("tip", tipUssClassName, ref m_TipElement); InitBadgeComponent("icon", iconUssClassName, ref m_IconElement); InitBadgeComponent("text", textUssClassName, ref m_TextElement); if (m_TipElement != null) { ////we make sure the tip is in the back m_TipElement.SendToBack(); } name = "IconBadge"; AddToClassList(ussClassName); this.AddStylesheet(defaultStylePath); if (m_TextElement != null) { m_TextElement.RemoveFromHierarchy(); //we need to add the style sheet to the Text element as well since it will be parented elsewhere m_TextElement.AddStylesheet(defaultStylePath); m_TextElement.style.whiteSpace = WhiteSpace.Normal; m_TextElement.RegisterCallback <GeometryChangedEvent>((evt) => ComputeTextSize()); m_TextElement.pickingMode = PickingMode.Ignore; } }
void LoadTemplate() { name = "error-badge"; m_TipElement = new Image { name = "tip" }; Add(m_TipElement); m_TipElement.AddToClassList(tipUssClassName); m_IconElement = new Image { name = "icon" }; Add(m_IconElement); m_IconElement.AddToClassList(iconUssClassName); m_TextElement = new Label { name = "text" }; m_TextElement.AddToClassList(textUssClassName); //we need to add the style sheet to the Text element as well since it will be parented elsewhere m_TextElement.AddStylesheet(defaultStylePath); m_TextElement.RegisterCallback <GeometryChangedEvent>(evt => ComputeTextSize()); }