public static void AlternateClass(this VisualElement element, string validClass, string invalidClass, bool isValid) { if (isValid) { if (!element.ClassListContains(validClass)) { element.AddToClassList(validClass); } if (element.ClassListContains(invalidClass)) { element.RemoveFromClassList(invalidClass); } } else { if (!element.ClassListContains(invalidClass)) { element.AddToClassList(invalidClass); } if (element.ClassListContains(validClass)) { element.RemoveFromClassList(validClass); } } }
public void WhenFalse_ShouldAddClass() { VisualElement listElement = new VisualElement(); ElementInteractions.SetAddSectionVisibility(listElement, false); Assert.IsTrue(listElement.ClassListContains(UxmlClassNames.HideAddSection)); }
public void WhenOptionFalse_ShouldAddClass() { VisualElement itemSection = new VisualElement(); Handler.SetReorderButtonVisibility(itemSection, false); Assert.IsTrue(itemSection.ClassListContains(UxmlClassNames.HideReorderButtons)); }
public void WhenOptionFalse_ShouldAddClass() { VisualElement listElement = new VisualElement(); Handler.SetRemoveButtonVisibility(listElement, false); Assert.IsTrue(listElement.ClassListContains(UxmlClassNames.HideRemoveButtons)); }
public void ShouldAddClassToList() { VisualElement ve = new VisualElement(); ElementInteractions.SetDefaultStyle(ve); Assert.IsTrue(ve.ClassListContains(UxmlClassNames.DefaultStyle)); }
void GetPickedElementFromHoverElement(out VisualElement pickedElement, out int index) { index = -1; if (IsElementTheScrollView(m_LastRowHoverElement)) { pickedElement = m_Canvas; } else if (m_LastHoverElement.ClassListContains(BuilderConstants.ExplorerItemReorderZoneClassName)) { var reorderZone = m_LastHoverElement; var sibling = GetLinkedElementFromReorderZone(reorderZone); pickedElement = sibling.parent; var siblingIndex = pickedElement.IndexOf(sibling); index = pickedElement.childCount; if (reorderZone.ClassListContains(BuilderConstants.ExplorerItemReorderZoneAboveClassName)) { index = siblingIndex; } else if (reorderZone.ClassListContains(BuilderConstants.ExplorerItemReorderZoneBelowClassName)) { index = siblingIndex + 1; } } else { pickedElement = m_LastHoverElement.GetProperty(BuilderConstants.ExplorerItemElementLinkVEPropertyName) as VisualElement; } }
public void WhenTypeIsString_ShouldNotAddClass() { VisualElement itemSection = new VisualElement(); Handler.SetAddFieldVisibility(itemSection, typeof(string), false); Assert.IsFalse(itemSection.ClassListContains(UxmlClassNames.UseObjectField)); }
protected virtual bool MatchSelectorPart(VisualElement element, StyleSelector selector, StyleSelectorPart part) { bool flag = true; switch (part.type) { case StyleSelectorType.Wildcard: return(flag); case StyleSelectorType.Type: flag = (element.typeName == part.value); return(flag); case StyleSelectorType.Class: flag = element.ClassListContains(part.value); return(flag); case StyleSelectorType.PseudoClass: { int pseudoStates = (int)element.pseudoStates; flag = ((selector.pseudoStateMask & pseudoStates) == selector.pseudoStateMask); flag &= ((selector.negatedPseudoStateMask & ~pseudoStates) == selector.negatedPseudoStateMask); return(flag); } case StyleSelectorType.ID: flag = (element.name == part.value); return(flag); } flag = false; return(flag); }
public void WhenTypeIsObjectAndOptionSet_ShouldNotAddClass() { VisualElement itemSection = new VisualElement(); Handler.SetAddFieldVisibility(itemSection, typeof(TestHelpers.TestObject), false); Assert.IsFalse(itemSection.ClassListContains(UxmlClassNames.UseObjectField)); }
protected virtual bool MatchSelectorPart(VisualElement element, StyleSelector selector, StyleSelectorPart part) { bool match = true; switch (part.type) { case StyleSelectorType.Wildcard: break; case StyleSelectorType.Class: match = element.ClassListContains(part.value); break; case StyleSelectorType.ID: match = (element.name == part.value); break; case StyleSelectorType.Type: //TODO: This tests fails to capture instances of sub-classes match = element.typeName == part.value; break; case StyleSelectorType.PseudoClass: int pseudoStates = (int)element.pseudoStates; match = (selector.pseudoStateMask & pseudoStates) == selector.pseudoStateMask; match &= (selector.negatedPseudoStateMask & ~pseudoStates) == selector.negatedPseudoStateMask; break; default: // ignore, all errors should have been warned before hand match = false; break; } return(match); }
public void WhenOptionTrue_ShouldRemoveClass() { VisualElement itemSection = new VisualElement(); itemSection.AddToClassList(UxmlClassNames.HidePropertyLabel); Handler.SetPropertyLabelVisibility(itemSection, true); Assert.IsFalse(itemSection.ClassListContains(UxmlClassNames.HidePropertyLabel)); }
static void ReduceOpacity(this VisualElement ele) { if (!ele.ClassListContains("autoDim") || k_OpacityProperties[ele].Augmenting) { return; } ele.SetOpacityRecursive(ele, Mathf.Max(ele.GetMinOpacity(), ele.style.opacity.value - ele.GetStepOpacity())); }
public void SetVisibility_adds_hidden_when_HideIfEmpty_and_IsEmptyAreTrue() { var vis = new VisualElement(); var stub = new VisualElementConcealer(vis); stub.HandleSettingChange(new HideCollectionEvent().WithValue(true).WithTarget(vis)); stub.SetVisibility(true); Assert.IsTrue(vis.ClassListContains("hidden")); }
public static bool HasElementClass(VisualElement element, string className) { if (element == null) { return(false); } return(element.ClassListContains(className)); }
static void AlignInspectorLabelWidth(VisualElement element, float topLevelLabelWidth, int indentLevel) { if (element.ClassListContains(UssClasses.Unity.Label)) { element.style.width = Mathf.Max(topLevelLabelWidth - indentLevel * k_Indent, 0.0f); element.style.minWidth = 0; #if UNITY_2020_1_OR_NEWER element.style.textOverflow = TextOverflow.Ellipsis; #endif element.style.flexWrap = Wrap.NoWrap; element.style.overflow = Overflow.Hidden; element.style.whiteSpace = WhiteSpace.NoWrap; } if (element is Foldout) { var label = element.Q <Toggle>().Q(className: UssClasses.ListElement.ToggleInput); if (null != label) { label.style.width = Mathf.Max(topLevelLabelWidth - indentLevel * k_Indent + 16.0f, 0.0f); label.style.minWidth = 0; #if UNITY_2020_1_OR_NEWER label.style.textOverflow = TextOverflow.Ellipsis; #endif label.style.flexWrap = Wrap.NoWrap; label.style.overflow = Overflow.Hidden; label.style.whiteSpace = WhiteSpace.NoWrap; } ++indentLevel; } if (element is IReloadableElement && element.ClassListContains(UssClasses.ListElement.Item)) { --indentLevel; } for (var i = 0; i < element.childCount; ++i) { var child = element[i]; AlignInspectorLabelWidth(child, topLevelLabelWidth, indentLevel); } }
public static void ToggleShow(VisualElement element) { if (element.ClassListContains(HiddenClassName)) { element.RemoveFromClassList(HiddenClassName); } else { element.AddToClassList(HiddenClassName); } }
private static void UpdateElementRecursively(VisualElement element, SerializedProperty prop, Action <VisualElement, SerializedProperty> updateCallback) { VisualElement elementToUpdate = element; if (element is Foldout) { // We only want to apply override styles onto the Foldout header, not the entire contents. elementToUpdate = element.Q(className: Foldout.toggleUssClassName); } else if (element.ClassListContains(BaseCompositeField <int, IntegerField, int> .ussClassName) || element is BoundsField || element is BoundsIntField) { // The problem with compound fields is that they are bound at the parent level using // their parent value data type. For example, a Vector3Field is bound to the parent // SerializedProperty which uses the Vector3 data type. However, animation overrides // are not stored on the parent SerializedProperty but on the component child // SerializedProperties. So even though we're bound to the parent property, we still // have to dive inside and example the child SerializedProperties (ie. x, y, z, height) // and override the animation styles individually. var compositeField = element; // The element we style in the main pass is going to be just the label. elementToUpdate = element.Q(className: BaseField <int> .labelUssClassName); // Go through the inputs and find any that match the names of the child PropertyFields. var propCopy = prop.Copy(); var endProperty = propCopy.GetEndProperty(); propCopy.NextVisible(true); // Expand the first child. do { if (SerializedProperty.EqualContents(propCopy, endProperty)) { break; } var subInputName = "unity-" + propCopy.name + "-input"; var subInput = compositeField.Q(subInputName); if (subInput == null) { continue; } UpdateElementRecursively(subInput, propCopy, updateCallback); }while (propCopy.NextVisible(false)); // Never expand children. } if (elementToUpdate != null) { updateCallback(elementToUpdate, prop); } }
public static bool IsPartiallyVisible(EditorWindow window, VisualElement element) { if (element.ClassListContains(UiConstants.ussHidden)) { return(false); } var windowBounds = window.rootVisualElement.worldBound; var elementBounds = element.worldBound; return(!(elementBounds.x > windowBounds.x + windowBounds.width) && !(elementBounds.x + elementBounds.width < windowBounds.x) && !(elementBounds.y > windowBounds.y + windowBounds.height) && !(elementBounds.y + elementBounds.height < windowBounds.y)); }
public static VisualElement GetFirstAncestorWithClass(this VisualElement element, string className) { if (element == null) { return(null); } if (element.ClassListContains(className)) { return(element); } return(element.parent.GetFirstAncestorWithClass(className)); }
public static bool IsCompletelyVisible(EditorWindow window, VisualElement element) { if (element.ClassListContains(UiConstants.ussHidden)) { return(false); } var windowBounds = window.rootVisualElement.worldBound; var elementBounds = element.worldBound; return(elementBounds.x >= windowBounds.x && elementBounds.y >= windowBounds.y && windowBounds.x + windowBounds.width >= elementBounds.x + elementBounds.width && windowBounds.y + windowBounds.height >= elementBounds.y + elementBounds.height); }
private static bool Match(VisualElement element, ref RuleMatcher matcher) { bool flag = true; StyleSelector styleSelector = matcher.complexSelector.selectors[matcher.simpleSelectorIndex]; int num = styleSelector.parts.Length; int num2 = 0; while (num2 < num && flag) { switch (styleSelector.parts[num2].type) { case StyleSelectorType.Wildcard: break; case StyleSelectorType.Type: flag = (element.typeName == styleSelector.parts[num2].value); break; case StyleSelectorType.Class: flag = element.ClassListContains(styleSelector.parts[num2].value); break; case StyleSelectorType.PseudoClass: { int pseudoStates = (int)element.pseudoStates; flag = ((styleSelector.pseudoStateMask & pseudoStates) == styleSelector.pseudoStateMask); flag &= ((styleSelector.negatedPseudoStateMask & ~pseudoStates) == styleSelector.negatedPseudoStateMask); break; } case StyleSelectorType.RecursivePseudoClass: goto IL_FA; case StyleSelectorType.ID: flag = (element.name == styleSelector.parts[num2].value); break; default: goto IL_FA; } IL_101: num2++; continue; IL_FA: flag = false; goto IL_101; } return(flag); }
private static void SetActive(VisualElement label, bool isActive) { var currentlyActive = label.ClassListContains("active"); switch (isActive) { case true when !currentlyActive: label.AddToClassList("active"); break; case false: label.RemoveFromClassList("active"); break; } }
public void SetProgressStyleFull(bool styleFull) { var isAlreadyFull = progress.ClassListContains("unity-progress-bar__progress__full"); if (isAlreadyFull != styleFull) { if (styleFull) { progress.AddToClassList("unity-progress-bar__progress__full"); } else { progress.RemoveFromClassList("unity-progress-bar__progress__full"); } } }
bool IsElementTheScrollView(VisualElement pickedElement) { if (pickedElement == null) { return(false); } if (pickedElement is ScrollView) { return(true); } if (pickedElement.ClassListContains(ScrollView.viewportUssClassName)) { return(true); } return(false); }
private void BindZebraItem(VisualElement element, int index) { m_BindItem(element, index); if (element.ClassListContains(kItemOdd)) { if (index % 2 == 0) { element.RemoveFromClassList(kItemOdd); } } else { if ((index % 2) == 1) { element.AddToClassList(kItemOdd); } } }
void ElementSelected(VisualElement element) { if (m_SelectionMadeExternally) { return; } if (element == null) { m_Selection.ClearSelection(this); return; } else if (element.ClassListContains(BuilderConstants.ExplorerItemUnselectableClassName)) { m_SelectionMadeExternally = true; m_ElementHierarchyView.ClearSelection(); m_SelectionMadeExternally = false; m_Selection.ClearSelection(this); return; } m_Selection.Select(this, element); }
public static MatchResultInfo MatchesSelector(VisualElement element, StyleSelector selector) { bool match = true; StyleSelectorPart[] parts = selector.parts; int count = parts.Length; for (int i = 0; i < count && match; i++) { switch (parts[i].type) { case StyleSelectorType.Wildcard: break; case StyleSelectorType.Class: match = element.ClassListContains(parts[i].value); break; case StyleSelectorType.ID: match = (element.name == parts[i].value); break; case StyleSelectorType.Type: //TODO: This tests fails to capture instances of sub-classes match = element.typeName == parts[i].value; break; case StyleSelectorType.Predicate: UQuery.IVisualPredicateWrapper w = parts[i].tempData as UQuery.IVisualPredicateWrapper; match = w != null && w.Predicate(element); break; case StyleSelectorType.PseudoClass: break; default: // ignore, all errors should have been warned before hand match = false; break; } } int triggerPseudoStateMask = 0; int dependencyPseudoMask = 0; bool saveMatch = match; if (saveMatch && selector.pseudoStateMask != 0) { match = (selector.pseudoStateMask & (int)element.pseudoStates) == selector.pseudoStateMask; if (match) { // the element matches this selector because it has those flags dependencyPseudoMask = selector.pseudoStateMask; } else { // if the element had those flags defined, it would match this selector triggerPseudoStateMask = selector.pseudoStateMask; } } if (saveMatch && selector.negatedPseudoStateMask != 0) { match &= (selector.negatedPseudoStateMask & ~(int)element.pseudoStates) == selector.negatedPseudoStateMask; if (match) { // the element matches this selector because it does not have those flags triggerPseudoStateMask |= selector.negatedPseudoStateMask; } else { // if the element didn't have those flags, it would match this selector dependencyPseudoMask |= selector.negatedPseudoStateMask; } } return(new MatchResultInfo(match, (PseudoStates)triggerPseudoStateMask, (PseudoStates)dependencyPseudoMask)); }
internal static bool IsParentSelectorElement(VisualElement element) { return(element.ClassListContains(BuilderConstants.StyleSelectorBelongsParent)); }
internal static bool IsDocumentElement(VisualElement element) { return(element.name == "document" && element.ClassListContains("unity-builder-viewport__document")); }
internal static bool IsElementVisible(VisualElement element) { return(element.visible && !element.ClassListContains(DisplayNone)); }