Any updates on when a C# pseudo state API can be expected?
This is not something on our radar as far as I know.
Can we explain a bit how you’d envision this API to work ? If you had the ability to apply USS strings (as you requested here ) would it be needed?
What I had in mind was the ability to set the values of different IStyles associated with the VisualElement. Right now we have style, but we could have hoverStyle, activeStyle etc.
Alternatively we could provide an optional enum value when setting StyleValues:
enum PseudoState { Inactive, Active, Hover, Focus, Selected, Enabled, Disabled, Root }
void Example()
{
VisualElement v = new VisualElement();
v.style.width = new StyleLength(new Length(80, LengthUnit.Pixel), PseudoState.Inactive);
v.style.width = new StyleLength(new Length(100, LengthUnit.Pixel), PseudoState.Hover);
}
And is this API needed? Yes. The UI looks very static and unresponsive without pseudostates, and even without transition duration, thaving them would greatly improve the feel. At the moment, only applying the new values when a state changes would be enough.
Ok, thanks for the detail.
Can elaborate on why using USS is not suitable for this (except the fact that USS cannot be constructed dynamically at the moment) ?
Because it is part of a bigger system. The elements are procedurally generated, based on instructions from user defined modules. Currently I can generate entire interfaces with the tool, but it is all static (with the exception of events) and the biggest limitation at the moment is that I can not use pseudo states.
^ This, but also, the USS pseudo state no longer functions once you make a change using C#, which I do all the time for animations. If I animate the background of an item, once it has completed, the previously set USS :hover state no longer functions. USS is great… for some things, but if the USS functionality is going to be broken when I try to make a temporary change in C#, then it would make sense to have a similar way to fix it / achieve the same result.
The quickest example I could come up with that properly demonstrates this would be below. At first, the mouse over is using uss:hover state, then I animate the background color, then the hover no longer works. Being able to define these states in C# and reapply them, or similar, would be ideal vs having to do a whole registration process for mouseover and mouseout for each item.
Thanks,
-MH
Thanks for reviving the thread, I have logged the feature request.
OK, so not sure about how far in development this feature has come or if it has been started on at all, but just want to give a rough idea of what I had in mind:
First of all, the VisualElement would need a list of strings called pseudoClasses.
While some pseudo classes such as hover and focus could be added by internal state changes, it would also be possible for users to add their own. They can also set VisualElement.pickingMode to None and add these pseudo classes by themselves. One example would be to add a hover pseudo class to all children of an element when it is hovered.
The API would give access to a list of C# styles called pseudoStyles which would be the styles responsible for handling pseudo classes.
Each of these styles would have a list of strings for their pseudoClasses
If any of the pseudo classes match with any pseudo class of the element, then apply the style and do necessary transitions.
To manage priorities among pseudo classes (should A be applied before B) you only need to reorganize the pseudoStyles list.
These suggestions are based on how I myself implemented it in a tool I am working on.
Excuse my naivety, but can’t pseudo states be just plain classes? (style resolution-wise)
Something like :active or :hover. It would make it more transparent, easy to script and probably opens up a door for custom pseudo states.
Actually ended up doing this for my own solution. It has all of the benefits you mentioned, like the ability to create custom pseudo-states. I now use this feature for everything, because of how handy it is.
Could you share this feature? Thanks.