Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Toggle Group in UI Toolkit

Discussion in 'UI Toolkit' started by Shiruichi, Dec 9, 2020.

  1. Shiruichi

    Shiruichi

    Joined:
    Dec 9, 2020
    Posts:
    1
    Hello, I was trying out to create a simple UI, which contain a simple form. In this form I wanted to have some text input field and toggles. The problem I have right now is that I can't find any simple way to group my toggles. I would like to have only one enabled (or set to true) toggle in the group. Is such a feature built in the UI Toolkit?

    Screenshot of simple UI for reference:
    upload_2020-12-9_17-36-4.png

    Like in the attached screenshot, users should be able to choose only 1 race and 1 class.
    Thanks for your help!
     
  2. JuliaP_Unity

    JuliaP_Unity

    Unity Technologies

    Joined:
    Mar 26, 2020
    Posts:
    666
    Hello, we have this type of control coming but I can't say the exact version yet - coming soon, though!
     
  3. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,184
    Hey, what's the status on UI Toolkit toggle groups? Or the same functionality as GUI.Toolbar from the previous system? Something like this:

    upload_2021-2-12_10-53-53.png

    Should we just implement them as buttons in a horizontal layout and manage the checked state with styling or is there a built-in control that ensures the editor styling is consistent?
     
    Gekigengar likes this.
  4. shiena

    shiena

    Joined:
    May 19, 2017
    Posts:
    44
  5. JuliaP_Unity

    JuliaP_Unity

    Unity Technologies

    Joined:
    Mar 26, 2020
    Posts:
    666
    RadioButton
    and
    GroupBox
    are out on 2021.1 already!

    For Toolbars you can use separate
    ToolbarToggle
    instances to have that behavior.
     
    Xarbrough likes this.
  6. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,058
    So for 2021.1, there still isn't a replacement for the GUI.Toolbar as UI Toolkit control?
    I've already asked this a long time ago, which if I remember correctly, was also replied with "not at the moment, use ToolbarToggle".

    So now theres a
    GroupBox
    which is a foundation for
    RadioButtonGroup
    , but it doesn't manage the
    ToolbarToggle
    because it doesn't implement
    IGroupBoxOption
    right?
    Are we supposed to inherit from
    ToolbarToggle
    and add
    IGroupBoxOption
    ?

    Edit: just noticed
    IGroupBoxOption
    is internal, so you cannot even use it
     
  7. JuliaP_Unity

    JuliaP_Unity

    Unity Technologies

    Joined:
    Mar 26, 2020
    Posts:
    666
    I completely misunderstood what the
    GUI.Toolbar
    does, sorry about that! :confused:
    But we indeed don't have that same control on the UI Toolkit side, so you'd have to implement your own.

    You have an example on the UI Builder, it's called
    ButtonStrip
    . If you use the UI Builder from a package (with Unity 2020.3 or 2021.1 for example), you have easy access to the source code.

    Screen Shot 2021-08-31 at 13.57.59.png

    Hope that helps! :)
     
    MaskedMouse likes this.
  8. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,058
    Ah right, I completely missed that one! haha, thanks for the tip I'll have a look at it later.
     
    JuliaP_Unity likes this.
  9. Gekigengar

    Gekigengar

    Joined:
    Jan 20, 2013
    Posts:
    706
    Why is ButtonStrip not available as a default control? It seems like something very commonly used.

    Anyways, UI Toolkit source is not available on 2022.2.0b16.

    EDIT: Found it!
    https://github.com/Unity-Technologi...r/Editor/Utilities/ButtonStrip/ButtonStrip.cs
     
    Last edited: Nov 21, 2022
    Protagonist likes this.
  10. JuliaP_Unity

    JuliaP_Unity

    Unity Technologies

    Joined:
    Mar 26, 2020
    Posts:
    666
    Sometimes some controls get implemented in a fashion that we are not comfortable making available to the public because we didn't have the time to really validate the API and usability are the correct one, but we still need to have the component internally. That doesn't mean it'll never be out to public, just means the current implementation is not ready to be public yet! I can assure you that such a common use case is on our radar and there will be some default implementation at some point ;)
     
  11. Gekigengar

    Gekigengar

    Joined:
    Jan 20, 2013
    Posts:
    706
    Hello, thanks for the reply! I do hope there is also an alternate to RadioButtonGroup, which is BaseField<int>, so we can have IMGUI GUILayout.Toolbar equivalent like this use case.

    Maybe call is ToggleButtonGroup or something.

    Code (CSharp):
    1. _selectedToolIndex.intValue = GUILayout.Toolbar(_selectedToolIndex.intValue, _toolNames, "Button");
    Love the constructor, and its very handy!