Search Unity

Feature request: USS functionality in c# (without separate uss file)

Discussion in 'UIElements' started by rawna, Jan 21, 2019.

  1. rawna

    rawna

    Joined:
    Aug 13, 2015
    Posts:
    10
    Having separate UXML and USS files is great. but for simple editor windows, I'd prefer to keep it all in one file.

    I'm aware that I can query the elements and set their style individually, but this would not work when you are adding new elements or changing their classes dynamically

    It would be great if we had an API that looks similar to the Query API, but would work like a uss file (dynamically). or at the very least something like
    VisualElement.AddStyleSheetString(@"//uss code")


    Thanks
     
  2. Rocktavious

    Rocktavious

    Joined:
    May 10, 2017
    Posts:
    41
    @rawna - I've actually built a UIElements library framework that has a feature kinda like this - https://github.com/rocktavious/UIEX#uss - is the specific documentation on it - but i also like your idea of using a multiline string to apply USS directly from C# - i think it would be totally doable with an extension method in my framework. Thoughts?
     
    Last edited: Jan 21, 2019
  3. rawna

    rawna

    Joined:
    Aug 13, 2015
    Posts:
    10
    @Rocktavious
    I was actually looking at your library earlier today, but the attribute that you linked me seems to also require a separate USS file, what I want is to write the USS rules in the C# editor class.

    But cool library nonetheless, i'll keep an eye on it.
     
  4. Rocktavious

    Rocktavious

    Joined:
    May 10, 2017
    Posts:
    41
    @rawna - ya which is why i said "kinda like" - i think what i'd need to do is add an attribute or extension method `InlineUSS` that takes a USS multiline string, turns that into a StyleSheet asset and then feeds it to the VisualElement - from what i can tell this isn't doable in 2018.3 but looks like it might be in 2019.1 (they've made some API changes that seems like would enable it) I'll let you know if i add it (havn't played with 2019.1 yet - was waiting for the general release)
     
  5. Kirsche

    Kirsche

    Joined:
    Apr 14, 2015
    Posts:
    37
    QT lets you do this too:

    myButton->setStyleSheet("...");


    It would be handy to have something like this in Unity.