public float GetBlockIndexY(int index, bool middle) { float y = 0; if (m_BlockContainer.childCount == 0) { return(0); } if (index >= m_BlockContainer.childCount) { return(m_BlockContainer.ElementAt(m_BlockContainer.childCount - 1).layout.yMax); } else if (middle) { return(m_BlockContainer.ElementAt(index).layout.center.y); } else { y = m_BlockContainer.ElementAt(index).layout.yMin; if (index > 0) { y = (y + m_BlockContainer.ElementAt(index - 1).layout.yMax) * 0.5f; } } return(y); }
// For custom display item void BindAnimationItem(VisualElement e, int i) { if (Asset == null) { return; } var taggedClips = Asset.AnimationLibrary; if (taggedClips.Count <= i) { return; } var taggedClip = taggedClips[i]; //TODO - remove tooltip and reference to AnimationClip? var clipValid = taggedClip.Valid; (e.ElementAt(k_ClipFieldIndex) as Label).text = taggedClip.ClipName; e.ElementAt(k_ClipWarningIndex).style.display = clipValid ? DisplayStyle.None : DisplayStyle.Flex; if (clipValid) { e.tooltip = $"Duration {taggedClip.DurationInSeconds:F2}s/{Mathf.RoundToInt(taggedClip.DurationInSeconds * taggedClip.SampleRate )} frames"; } else { e.tooltip = TaggedAnimationClip.k_MissingClipText; } e.userData = taggedClip; }
public void Select(int index) { index = Mathf.Clamp(index, -1, _itemsContainer.childCount - 1); if (_selectedLine == index) { return; } if (_selectedLine != -1 && _selectedLine < _itemsContainer.childCount) { _itemsContainer.ElementAt(_selectedLine).RemoveFromClassList("selected"); } _selectedLine = index; if (_selectedLine != -1 && _selectedLine < _itemsContainer.childCount) { _itemsContainer.ElementAt(_selectedLine).AddToClassList("selected"); } if (_selectedLine >= 0) { onItemSelected?.Invoke(_selectedLine); } }
private void UpdateItem(int index) { var item = _itemsContainer.ElementAt(index); item.EnableInClassList(ItemEvenUssClassName, index % 2 == 0); item.EnableInClassList(ItemOddUssClassName, index % 2 != 0); if (Proxy.NeedsUpdate(item, index)) { var content = Proxy.CreateField(index); content.AddToClassList(ItemContentUssClassName); item.RemoveAt(1); item.Insert(1, content); } }
public void OnEnable() { #region UXML and USS set-up // Each editor window contains a root VisualElement object VisualElement root = rootVisualElement; // Import UXML and USS VisualTreeAsset visualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>("Assets/_ACTools/_Data Manager/Editor/DataManagerWindow.uxml"); StyleSheet styleSheet = AssetDatabase.LoadAssetAtPath <StyleSheet>("Assets/_ACTools/_Data Manager/Editor/DataManagerWindow.uss"); // Adds style sheet to root. root.styleSheets.Add(styleSheet); // Clones the visual tree and adds it to the root. VisualElement tree = visualTree.CloneTree(); root.Add(tree); #endregion #region Mini-Row // Sets up the add fields, buttons, and events. CheckForTypesButton = (Button)tree.hierarchy.ElementAt(0).ElementAt(0); CheckForTypesButton.clickable.clicked += CheckForTypesAction; #endregion #region Main Row // Sets selected values to null; DataTypeSelected = false; ItemSelected = false; // Gets the main row element. VisualElement row = tree.hierarchy.ElementAt(2); #region Left Column // Gets the left column. leftColumnItems = row.ElementAt(0); DrawLeftColumnItems(); #endregion #region Right Column // Gets the middle column. rightColumnItems = row.ElementAt(1); DrawRightColumnItems(); #endregion #endregion }
/// <summary> /// Invokes <see cref="IEditorElement.CreateInspectorElement"/> followed by a layout until the given <paramref name="viewport"/> is filled. /// </summary> /// <param name="viewport">The viewport to build elements for.</param> /// <param name="contentContainer"></param> public void CreateInspectorElementsForViewport(ScrollView viewport, VisualElement contentContainer) { if (m_Index >= m_EditorElements.Count) { return; } var scroll = viewport.verticalScroller.value; while (m_Index < m_EditorElements.Count) { var element = m_EditorElements[m_Index++]; element.CreateInspectorElement(); // If this element contributes to the layout, re-compute it immediately to determine how much of the viewport is occupied. if (null != element.editor && InternalEditorUtility.GetIsInspectorExpanded(element.editor.target)) { Panel?.UpdateWithoutRepaint(); if (contentContainer.ElementAt(m_Index - 1).layout.yMax - scroll > viewport.layout.height) { break; } } } viewport.verticalScroller.value = scroll; }
private void SwapStage(LessonStage stage, VisualElement element, bool up) { if (!m_BaseVisualElement.Contains(element)) { return; } int elementIndex = m_BaseVisualElement.IndexOf(element); int swapElementIndex = elementIndex + (up ? -1 : 1); if (swapElementIndex < 0 || swapElementIndex >= m_BaseVisualElement.childCount) { return; } VisualElement swapElement = m_BaseVisualElement.ElementAt(swapElementIndex); if (swapElement.GetType() != element.GetType()) { return; } if (!m_BaseVisualElement.SwapElementsAt(elementIndex, swapElementIndex)) { return; } m_LessonStageFactory.SwapStages(stage, up); }
internal static void ApplyButtonStripStylesToChildren(VisualElement root) { int count = root.hierarchy.childCount; int begin = -1, end = -1; for (int i = count - 1; end < 0 && i > -1; i--) { if (IsRendered(root.ElementAt(i))) { end = i; } } for (var i = 0; i < count; ++i) { var element = root.hierarchy.ElementAt(i); if (!IsRendered(element)) { continue; } if (begin < 0) { begin = i; } element.EnableInClassList(aloneStripElementClassName, i == begin && i == end); element.EnableInClassList(leftStripElementClassName, i == begin && i != end); element.EnableInClassList(rightStripElementClassName, i == end && i != begin); element.EnableInClassList(middleStripElementClassName, i != begin && i != end); } }
public static bool SwapElementsAt(this VisualElement visualElement, int a, int b) { if (a == b) { return(false); } if (a < 0 || a >= visualElement.childCount) { return(false); } if (b < 0 || b >= visualElement.childCount) { return(false); } int lowerIndex = a; int higherIndex = b; if (a > b) { lowerIndex = b; higherIndex = a; } VisualElement higherElement = visualElement.ElementAt(higherIndex); visualElement.RemoveAt(higherIndex); visualElement.Insert(lowerIndex, higherElement); return(true); }
private void BindTwoPaneSplitView() { // Import UXML var visualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>("Assets/CPM/Scripts/Editor/ConvergePackageManager.uxml"); VisualElement twoPaneSplitViewTemplate = visualTree.CloneTree(); rootVisualElement.Add(twoPaneSplitViewTemplate.ElementAt(0)); }
void SyncAnchors(ReadOnlyCollection <VFXDataAnchorController> ports, VisualElement container) { var existingAnchors = container.Children().Cast <VFXDataAnchor>().ToDictionary(t => t.controller, t => t); Profiler.BeginSample("VFXNodeUI.SyncAnchors Delete"); var deletedControllers = existingAnchors.Keys.Except(ports).ToArray(); foreach (var deletedController in deletedControllers) { //Explicitely remove edges before removing anchor. GetFirstAncestorOfType <VFXView>().RemoveAnchorEdges(existingAnchors[deletedController]); container.Remove(existingAnchors[deletedController]); existingAnchors.Remove(deletedController); } Profiler.EndSample(); Profiler.BeginSample("VFXNodeUI.SyncAnchors New"); var order = ports.Select((t, i) => new KeyValuePair <VFXDataAnchorController, int>(t, i)).ToDictionary(t => t.Key, t => t.Value); var newAnchors = ports.Except(existingAnchors.Keys).ToArray(); foreach (var newController in newAnchors) { Profiler.BeginSample("VFXNodeUI.InstantiateDataAnchor"); var newElement = InstantiateDataAnchor(newController, this); Profiler.EndSample(); (newElement as VFXDataAnchor).controller = newController; container.Add(newElement); existingAnchors[newController] = newElement; } Profiler.EndSample(); Profiler.BeginSample("VFXNodeUI.SyncAnchors Reorder"); //Reorder anchors. if (ports.Count > 0) { var correctOrder = new VFXDataAnchor[ports.Count]; foreach (var kv in existingAnchors) { correctOrder[order[kv.Key]] = kv.Value; } correctOrder[0].SendToBack(); correctOrder[0].AddToClassList("first"); for (int i = 1; i < correctOrder.Length; ++i) { if (container.ElementAt(i) != correctOrder[i]) { correctOrder[i].PlaceInFront(correctOrder[i - 1]); } correctOrder[i].RemoveFromClassList("first"); } } Profiler.EndSample(); }
private void Start() { visualTree = Resources.Load <VisualTreeAsset>("UI/Options.uxml"); VisualElement labelFromUXML = visualTree.CloneTree(); VisualElement options = new VisualElement(); VisualElement buttons = new VisualElement(); for (int i = 0; i < labelFromUXML.childCount; i++) { VisualElement child = labelFromUXML.ElementAt(i); if (child.name == "Options") { options = child; } else if (child.name == "Buttons") { buttons = child; } } VisualElement resolution = new VisualElement(); VisualElement graphics = new VisualElement(); VisualElement volume = new VisualElement(); for (int i = 0; i < options.childCount; i++) { VisualElement child = labelFromUXML.ElementAt(i); string name = child.name; if (name == "Resolution") { resolution = child; } else if (name == "Graphics") { graphics = child; } else if (name == "Volume") { volume = child; } } //((DropdownField)resolution). }
void RemoveDragFromItem(VisualElement item) { if (item.childCount < 1 || item.ElementAt(0).name != "DraggingHandle") { return; } item.RemoveAt(0); }
public List(Func <K> addCallback, Action <int> removeCallback) { var sheet = AssetDatabase.LoadAssetAtPath <StyleSheet>(k_uss); if (sheet != null) { styleSheets.Add(sheet); } Add(m_List = new VisualElement() { name = "Content" }); VisualElement footer = new VisualElement(); footer.AddToClassList(k_FooterClass); Add(footer); Button removeButton = new Button(() => { if (m_Selected == null) { return; } int index = m_List.IndexOf(m_Selected); bool removeFirst = index == 0; m_List.Remove(m_Selected); m_Selected = null; removeCallback?.Invoke(index); if (removeFirst && m_List.childCount > 0) { m_List.ElementAt(0).AddToClassList(k_FirstContainerClass); } }) { text = "-" }; footer.Add(removeButton); Button addButton = new Button(() => { AddItem(new T()); Select(m_List.childCount - 1); K newData = addCallback?.Invoke(); if (newData != null) { m_Selected.Bind(newData); } }) { text = "+" }; footer.Add(addButton); }
void BindItem(VisualElement element, int index) { if (m_JointNames == null || index >= m_JointNames.Count) { return; } Toggle t = element.ElementAt(0) as Toggle; t.value = m_Metric.joints.Contains(m_JointNames[index]); Label joint = element.ElementAt(1) as Label; joint.text = m_JointNames[index]; if (EditorApplication.isPlaying || m_ForceDisabled) { element.SetEnabled(false); } }
void BindDependencyElement(VisualElement el, int modelIndex) { var property = m_DependenciesProperty[modelIndex]; var icon = (Image)el.ElementAt(0); var label = (Label)el.ElementAt(1); var depProperty = property.FindPropertyRelative(k_DependencyPropertyName); var content = EditorGUIUtility.ObjectContent(depProperty.objectReferenceValue, depProperty.objectReferenceValue.GetType()); icon.image = content.image; label.text = content.text; #if SCENE_TEMPLATE_DEBUG label.text += $"({depProperty.objectReferenceValue.GetType().ToString()})"; #endif el.userData = property; var instantiationModeProperty = property.FindPropertyRelative(k_InstantiationModePropertyName); var cloneToggle = (Toggle)el.ElementAt(2); cloneToggle.value = IsCloning(instantiationModeProperty); cloneToggle.SetEnabled(SceneTemplateProjectSettings.Get().GetDependencyInfo(depProperty.objectReferenceValue).supportsModification); cloneToggle.RegisterValueChangedCallback <bool>(evt => { if (evt.newValue == IsCloning(instantiationModeProperty)) { return; } var newInstantiationType = (evt.newValue ? TemplateInstantiationMode.Clone : TemplateInstantiationMode.Reference); instantiationModeProperty.enumValueIndex = (int)newInstantiationType; // Sync Selection if the dependency is part of it: if (m_ZebraList.listView.selectedIndices.Contains(modelIndex)) { SyncListSelectionToValue(newInstantiationType); } serializedObject.ApplyModifiedProperties(); m_CloneHeaderToggle.SetValueWithoutNotify(AreAllDependenciesCloned()); }); }
private void OnCustomStyleResolved(CustomStyleResolvedEvent e) { var customStyle = e.customStyle; customStyle.TryGetValue(s_BitImage, out m_BitImage); customStyle.TryGetValue(s_BitBkgndImage, out m_BitBkgndImage); for (int i = 0; i < m_Background.childCount - 1; ++i) { m_Background.ElementAt(i).style.backgroundImage = m_BitBkgndImage; } ValueToGUI(true); }
private void HandleDeleteCompositeRow(VisualElement Container) { if (Container.childCount > 2) { var lastElement = Container.ElementAt(Container.childCount - 1); var oldVal = RetrievePathFromElementName(lastElement.name); foreach (var name in oldVal) { RemoveFromRecordingsToCombine(name); } Container.Remove(lastElement); } }
private void BindItem(VisualElement container, int index) { var label = container.ElementAt(0) as Label; label.text = HistoryList.GetName(index); if (index == HistoryList.Current) { label.AddToClassList("current"); } else { label.RemoveFromClassList("current"); } }
private void InitNodes(VisualElement ve) { var count = ve.childCount; if (count > 0) { for (int i = 0; i < count; i++) { var node = ve.ElementAt(i); if (node == null) { continue; } node.RegisterCallback <MouseUpEvent, VisualElement>(OnSelectNodeCallback, node); } } }
void BindItem(VisualElement element, ITreeViewItem item) { var builderItem = item as LibraryTreeItem; // Pre-emptive cleanup. var row = element.parent.parent; row.RemoveFromClassList(BuilderConstants.ExplorerHeaderRowClassName); row.SetEnabled(true); // If this is the uxml file entry of the currently open file, don't allow // the user to instantiate it (infinite recursion) or re-open it. if (builderItem.sourceAsset == m_PaneWindow.document.visualTreeAsset) { row.SetEnabled(false); row.AddToClassList(BuilderConstants.LibraryCurrentlyOpenFileItemClassName); } // Header if (builderItem.isHeader) { row.AddToClassList(BuilderConstants.ExplorerHeaderRowClassName); } // Set label. var label = element.ElementAt(0) as Label; label.text = builderItem.data; // Set open button visibility. var openButton = element.Q <Button>(k_OpenButtonClassName); openButton.userData = item; if (builderItem.sourceAsset == null) { openButton.AddToClassList(BuilderConstants.HiddenStyleClassName); } else { openButton.RemoveFromClassList(BuilderConstants.HiddenStyleClassName); } element.userData = item; element.SetProperty(BuilderConstants.LibraryItemLinkedManipulatorVEPropertyName, builderItem); }
void AssignTreeItemIcon(VisualElement itemRoot, Texture2D icon) { var iconElement = itemRoot.ElementAt(0); if (icon == null) { iconElement.style.display = DisplayStyle.None; } else { iconElement.style.display = DisplayStyle.Flex; var styleBackgroundImage = iconElement.style.backgroundImage; styleBackgroundImage.value = new Background { texture = icon }; iconElement.style.backgroundImage = styleBackgroundImage; } }
private VisualElement CreateRemainingElement(int count, VisualElement container) { if (count > UNEXPANDED_COLOUR_COUNT) { container.ElementAt(container.childCount - 1).SetVisible(false); var remainingElement = new TextElement(); var remainingColourCount = count - (UNEXPANDED_COLOUR_COUNT - 1); remainingElement.AddToClassList("preview__color-element"); remainingElement.text = $"+{remainingColourCount}"; remainingElement.RegisterCallback <MouseDownEvent, VisualElement>(OnClickRemainingColors, remainingElement); remainingElement.tooltip = $"Click to show {remainingColourCount} more colours"; container.Add(remainingElement); return(remainingElement); } return(null); }
private void SetDependencyInstantiationMode(VisualElement row, TemplateInstantiationMode mode) { var prop = (SerializedProperty)row.userData; var toggle = (Toggle)row.ElementAt(2); if (!toggle.enabledSelf) { return; } toggle.SetValueWithoutNotify(mode == TemplateInstantiationMode.Clone); var depProp = prop.FindPropertyRelative(k_InstantiationModePropertyName); if (depProp.enumValueIndex != (int)mode) { depProp.enumValueIndex = (int)mode; } }
private void BindToolbar() { // Import UXML var visualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>("Assets/CPM/Scripts/Editor/UIElements/ConvergeToolbar.uxml"); VisualElement toolbar = visualTree.CloneTree(); rootVisualElement.Add(toolbar.ElementAt(0)); m_toolbar = rootVisualElement.Query <ConvergeToolbar>("converge-toolbar"); m_toolbar.Initialize(); m_toolbar.RegisterCallback <KeyUpEvent>(ToolbarKeyUpEvent); m_toolbar.BindSearchField((evt => { m_pendingSearchString = evt.newValue; // TODO: Convert this so that it doesn choke the main thread. Need to rewrite in NuGetHelper.cs WWW in line 1441 // new Task(Search).Start(); })); }
private void RefreshView() { // Calculate slice of list to be rendered. var firstIndex = currentPage * elementsPerPage; var length = Math.Min(elementsPerPage, data.Count - firstIndex); // If the child count is the same, don't adjust it. // If the child count is less, add the requisite number. // If the child count is more, pop elements off the end. var diff = container.childCount - length; if (diff > 0) { for (var i = 0; i < diff; i++) { var element = container.ElementAt(container.childCount - 1); container.RemoveAt(container.childCount - 1); elementPool.Return((TElement)element); } } else if (diff < 0) { for (var i = diff; i < 0; i++) { container.Add(elementPool.GetOrCreate()); } } // At this point, container.Children() has the same length as the slice. var elementIndex = firstIndex; foreach (var child in container.Children()) { bindElement(elementIndex, data[elementIndex], (TElement)child); elementIndex++; } backButton.SetEnabled(currentPage != 0); forwardButton.SetEnabled(currentPage != numPages - 1); }
internal static void AddTooltip(this VisualElement e, string tooltip) { if (string.IsNullOrEmpty(tooltip)) { RemoveTooltip(e); return; } TooltipElement tooltipElement = e.Query().Children <TooltipElement>(); if (tooltipElement == null) { tooltipElement = new TooltipElement(); } tooltipElement.style.positionType = PositionType.Absolute; tooltipElement.style.positionLeft = tooltipElement.style.positionRight = tooltipElement.style.positionTop = tooltipElement.style.positionBottom = 0; tooltipElement.tooltip = tooltip; if (e.childCount < 1 || e.ElementAt(0) != tooltipElement) { e.Insert(0, tooltipElement); } }
public void RefreshContext() { Profiler.BeginSample("VFXContextUI.RefreshContext"); var blockControllers = controller.blockControllers; int blockControllerCount = blockControllers.Count(); bool somethingChanged = m_BlockContainer.childCount < blockControllerCount || (!m_CanHaveBlocks && m_NoBlock.parent != null); int cptBlock = 0; for (int i = 0; i < m_BlockContainer.childCount; ++i) { var child = m_BlockContainer.ElementAt(i) as VFXBlockUI; if (child != null) { if (!somethingChanged && blockControllerCount > cptBlock && child.controller != blockControllers[cptBlock]) { somethingChanged = true; } cptBlock++; } } if (somethingChanged || cptBlock != blockControllerCount) { foreach (var controller in blocks.Keys.Except(blockControllers).ToArray()) { GetFirstAncestorOfType <VFXView>().RemoveNodeEdges(blocks[controller]); m_BlockContainer.Remove(blocks[controller]); blocks.Remove(controller); } if (blockControllers.Count() > 0 || !m_CanHaveBlocks) { m_NoBlock.RemoveFromHierarchy(); } else if (m_NoBlock.parent == null) { m_BlockContainer.Add(m_NoBlock); } if (blockControllers.Count > 0) { VFXBlockUI prevBlock = null; foreach (var blockController in blockControllers) { VFXBlockUI blockUI; if (blocks.TryGetValue(blockController, out blockUI)) { if (prevBlock != null) { blockUI.PlaceInFront(prevBlock); } else { blockUI.SendToBack(); } } else { blockUI = InstantiateBlock(blockController); m_BlockContainer.Add(blockUI); m_BlockContainer.Insert(prevBlock == null ? 0: m_BlockContainer.IndexOf(prevBlock) + 1, blockUI); } prevBlock = blockUI; } VFXBlockUI firstBlock = m_BlockContainer.Query <VFXBlockUI>(); firstBlock.AddToClassList("first"); } } Profiler.EndSample(); }
public void Select(int containerIndex) => Select(m_List.ElementAt(containerIndex) as Container);
public void Activate(VisualElement hierarchyParentElement, int hierarchyIndex) { Reset(); if (hierarchyParentElement.childCount == 0 || hierarchyParentElement == documentRootElement) { return; } var mouseOverElement = hierarchyIndex > -1 && hierarchyIndex < hierarchyParentElement.childCount - 1 ? hierarchyParentElement.ElementAt(hierarchyIndex) : hierarchyParentElement.ElementAt(hierarchyParentElement.childCount - 1); var mouseOverElementCanvasRect = BuilderTracker.GetRelativeRectFromTargetElement(mouseOverElement, this.hierarchy.parent); var shouldGoLast = hierarchyIndex >= hierarchyParentElement.childCount; var isRow = hierarchyParentElement.resolvedStyle.flexDirection == FlexDirection.Row || hierarchyParentElement.resolvedStyle.flexDirection == FlexDirection.RowReverse; var reverseOrder = hierarchyParentElement.resolvedStyle.flexDirection == FlexDirection.ColumnReverse || hierarchyParentElement.resolvedStyle.flexDirection == FlexDirection.RowReverse; if (isRow) { if (!reverseOrder && !shouldGoLast) { style.top = mouseOverElementCanvasRect.y; style.left = mouseOverElementCanvasRect.x - k_IndicatorHalfSize; style.width = k_IndicatorSize; style.height = mouseOverElementCanvasRect.height; } else if (reverseOrder || shouldGoLast) { style.top = mouseOverElementCanvasRect.y; style.left = mouseOverElementCanvasRect.xMax - k_IndicatorHalfSize; style.width = k_IndicatorSize; style.height = mouseOverElementCanvasRect.height; } } else if (!isRow) { if (!reverseOrder && !shouldGoLast) { style.top = mouseOverElementCanvasRect.y - k_IndicatorHalfSize; style.left = mouseOverElementCanvasRect.x; style.width = mouseOverElementCanvasRect.width; style.height = k_IndicatorSize; } else if (reverseOrder || shouldGoLast) { style.top = mouseOverElementCanvasRect.yMax - k_IndicatorHalfSize; style.left = mouseOverElementCanvasRect.x; style.width = mouseOverElementCanvasRect.width; style.height = k_IndicatorSize; } } else { return; } style.display = DisplayStyle.Flex; }