Search Unity

[UIElements] GUI.skin.* equivalents

Discussion in 'UI Toolkit' started by Shikshen, May 7, 2019.

  1. Shikshen

    Shikshen

    Joined:
    Feb 21, 2015
    Posts:
    25
    Are there equivalents to the built-in IMGUI skins in UIElements?

    For example, I use GUI.skin.window a lot (e.g.
    GUILayout.BeginVertical("Title", GUI.skin.window);
    )

    Is there a simple replacement for this skin, or do we have to recreate everything?
     
  2. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    In UIElements, shared styling is done via StyleSheets (similar to CSS). If you put down a Button in UIElements, it will automatically look like a standard Unity Editor button because we assign it the "unity-button" class and we have a global StyleSheet applied to all windows. All common Editor styles are done like this, via CSS classes, and normally come automatically with the base controls in C#/UXML (ie. Button, Slider, Field, etc..).
     
  3. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    I don't think there is any style defined which looks like the "GUI.skin.window".

    If you use the `Windows > Analysis > UI Elements Debugger` you could inspect a windows which includes something which looks similar and try replicate that. The `Edit > Shortcuts` windows for example has a list which looks a lot like the window (which heading and body areas). Inspect that element's style `#categoryContainer`.
     
  4. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    Ah, you are asking for that specific style. Sorry, I misread. We actually do have that style in UIElements. It's under the form of a custom element,
    PopupWindow


    So for this IMGUI snippet:
    Code (CSharp):
    1. GUILayout.BeginVertical("Title", GUI.skin.window);
    2. GUILayout.Label("blue");
    3. GUILayout.EndVertical();
    The UIElements equivalent would be:
    Code (CSharp):
    1. var win = new UnityEngine.UIElements.PopupWindow() { text = "Title" };
    2. win.Add(new Label("blue"));
    You have to be careful not to create the
    UnityEditor.PopupWindow
    instead. That's why I fully qualify it above (but you can always use a
    using
    ).

    As for WHY it's named "PopupWindow", I have no idea what I was thinking when I chose it. :(
     
    firstuser and Leslie-Young like this.