Open Maesla opened 5 months ago
You can start with all elements of a toggle group deselected by setting CurrentIndex to something like -1 (anything outside the valid range of 0 to (Toggles.Count - 1)).
By doing so the condition in line 141 (specifically CurrentIndex >= 0) is not met and therefore no element will be toggled / selected during Start().
When setting the Toggles list during runtime CurrentIndex is clamped to the valid range of indices and the corresponding toggle is selected. https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/blob/b2fba1fbbc180b3118a03b99f7827fbe4d015b0c/org.mixedrealitytoolkit.uxcore/Toggle/ToggleCollection.cs#L46-L47 To achieve a state where all toggles are deselected after setting the list through code one must disable the currently selected button by using e.g. ForceSetToggled(false) or ForceSetToggled(false, false) to suppress the resulting toggle events. Only the initial toggle selection event must be handled or discarded using a condition in the called function.
Describe the problem
ToggleCollection has a flag to allow switch off, but it doesn't have a flag to start all the toggle buttons in an off state
Describe the solution you'd like
To be possible to start the toggle group with all the elements off, in the same way it is possible during the execution
Possibly changing this line would be enough
https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/blob/9ae2140007b47fd081d9f5605cc94bbd2131e2c5/org.mixedrealitytoolkit.uxcore/Toggle/ToggleCollection.cs#L141
Describe alternatives you've considered
N/A
Additional context
If we allow to be all the toggles off as a valid state, it should be valid and possible too in the initial state.
PS: ToggleSelectedEvent would be nice to have the information of the previous index and also be raised when all the toggles are off (maybe with a -1 as index?)