VisualElementExtensions

Extension methods for UnityEngine.UIElements.VisualElement. Provides convenience helpers for visibility toggling and stylesheet management in UI Toolkit-based editor UI.

Definition

Namespace: Paragon.Editor Assembly: Editor assembly

public static class VisualElementExtensions

Quick Lookup

Goal
Method

Show/hide an element

element.SetDisplay(true) or element.SetDisplay(false)

Copy stylesheets between elements

source.CopyStyleSheets(target)

Methods

SetDisplay

Sets the display style of a VisualElement to DisplayStyle.Flex (visible) or DisplayStyle.None (hidden) based on a boolean value.

public static void SetDisplay(this VisualElement element, bool value)
Parameter
Type
Description

element

VisualElement

The element to show or hide

value

bool

true to show (Flex), false to hide (None)

circle-info

Uses DisplayStyle.Flex for visible (not DisplayStyle.Initial). This means the element participates in flex layout when shown. For elements that need a specific display mode other than Flex, set style.display directly.

CopyStyleSheets

Copies all StyleSheet assets from a source element to a target element. Iterates the source's styleSheets set and adds each to the target.

Parameter
Type
Description

source

VisualElement

The element whose stylesheets are copied

target

VisualElement

The element to receive the stylesheets

circle-info

This adds stylesheets to the target without removing any existing ones. If the target already has stylesheets, the source's sheets are appended.

Common Pitfalls

circle-exclamation
circle-exclamation

Examples

Conditional panel visibility

Cloning stylesheets to a new element

See Also

Last updated