Search Unity

ToolbarToggle that behaves like a RadioButton ?

Discussion in 'UIElements' started by aybe, May 25, 2019.

  1. aybe

    aybe

    Joined:
    May 24, 2015
    Posts:
    99
    I am trying to achieve a somewhat simple thing but it turns out to be more convoluted than expected:

    Get ToolbarToggle to behave like a radio button, much like what you can on see the lighting window.

    I do register ChangeEvent<bool> since MouseDownEvent does not work, then on that unified callback I do negate value without notifying for other toggles in the toolbar.

    This works fine except that you can un-toggle one of them ... this is because base class Toggle adds a manipulator which will negate value on click.

    I was hoping to solve that relatively easily, that is, without having to roll-out my own control just to shortcut this behavior.

    Any ideas?

    Thanks!
     
  2. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    155
    You can try to add your own Clickable manipulator to the Toggle like so:
    Code (CSharp):
    1. theToggle.AddManipulator(new Clickable(YourOnClickEventFunc));
    and then make sure to stop event propagation in your YourOnClickEventFunc(evt). That way, you would prevent the default Clickable manipulator from firing.
     
  3. aybe

    aybe

    Joined:
    May 24, 2015
    Posts:
    99
    Thank you!