Author Topic: Toggle group not working in accordion when item is collapsed.  (Read 4244 times)

wallabie

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 200
    • View Profile
This is a bug report.

Steps to replicate:

1. AccordionSV with 2 item.
2. Item 1  is a Horizontal SV with 3 buttons with toggle number of 10
3. Item 2  is a Horizontal SV with 3 buttons with toggle number of 10
4. Click button 1 in accordion Item 1.
5. Collapse accordion Item 1.
6. Open accordion Item 2.
7. Click button 1 in Item 2.
8. Open accordion item1. 
9. Both buttons are highlighted instead of only one button.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Toggle group not working in accordion when item is collapsed.
« Reply #1 on: June 11, 2014, 06:04:20 AM »
Just a note, unless it's a very simple repro case or the scene file is included, I won't be able to have a look at it. The more complex the description, the less likely I am to understand and reproduce the issue. Your description skips over a lot of things, such as what scripts are on buttons and how they interact. Should clicking be rigged to shrink something? Please provide the actual scene for me to look at.

Fireball14

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 1
  • Posts: 23
    • View Profile
Re: Toggle group not working in accordion when item is collapsed.
« Reply #2 on: June 11, 2014, 06:32:59 AM »
This is a bug report.

Steps to replicate:

1. AccordionSV with 2 item.
2. Item 1  is a Horizontal SV with 3 buttons with toggle number of 10
3. Item 2  is a Horizontal SV with 3 buttons with toggle number of 10
4. Click button 1 in accordion Item 1.
5. Collapse accordion Item 1.
6. Open accordion Item 2.
7. Click button 1 in Item 2.
8. Open accordion item1. 
9. Both buttons are highlighted instead of only one button.

Just fought this bug yesterday. This is happening, because you need to reset Toggle groupe to initial state before you disable your items.
How to replicate this bug:

Toggle groupe contains 2 items - Toggle1 and Toggle2.
Both toggles are in group 1.
Toggle 1 has Starting state bool active.

When panel with troggles goes active, Toggle1 is checked, Toggle2 is not.
If you select Toggle2 by clicking on it. Then Toggle2 goes checked, and Toggle1 is not.
To this point everything goes normal. But then:
If you deactivate panel gameObject, and then you activate it again, you will have both  toggles checked.

To fight it i just use on toggle root panel this script.
  1. OnDisable()
  2. {
  3.         foreach (var toggle in GetComponentsInChildren<UIToggle>())
  4.         {
  5.             toggle.value = toggle.startsActive;
  6.         }
  7. }
  8.  

wallabie

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 200
    • View Profile
Re: Toggle group not working in accordion when item is collapsed.
« Reply #3 on: June 11, 2014, 01:26:56 PM »
fireball14,

Yes, this is exactly the bug. 

Basically, to replicate the problem, take the example Accordion.  Make all of the button inside of the horizontal scrollviews  have the same toggle group. 

1. Click on one button
2. Collapse the header
3. click on another button
4. Expand previously collapsed header, you will see that now you have two highlighted buttons instead of one.
« Last Edit: June 11, 2014, 01:39:33 PM by wallabie »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Toggle group not working in accordion when item is collapsed.
« Reply #4 on: June 12, 2014, 02:11:35 AM »
@Fireball14: I am not seeing this.

1. New scene.
2. Added 2 checkboxes (Control - Simple Checkbox).
3. Assigned them to group 1 and made only one of them start checked.
4. Hit Play. One checkbox is checked, as expected. Click on the second one to make it be checked instead.
5. Disable the panel game object via inspector, then re-enable it.
6. The second checkbox remains checked, the first one does not get checked.

Look at the code for UIToggle. It does nothing in OnEnable. It only processes the starting state in its Start() function which is fired only once.

@wallabie: If I understand you correctly you are saying you have a bunch of toggles all in the same group, and you show some of them while hiding others? The toggle groups only work for enabled toggles. Meaning if some are disabled at the time of you changing the state, those disabled toggles will not be "unset" because as far as NGUI is concerned disabled objects don't actually exist as a part of the UI.

You need to use different groups. Choose a unique group ID for each of your accordion.

Fireball14

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 1
  • Posts: 23
    • View Profile
Re: Toggle group not working in accordion when item is collapsed.
« Reply #5 on: June 12, 2014, 05:53:35 AM »
Ok im really sorry. You right!
I forgot to mention i needed to reset toggle grope to initial state.
So i made this script on parent panel:
  1. public Toggle1;
  2. void OnEnable()
  3. {
  4.      Toggle1.value = true; // <- Thats where both are on.
  5. }
  6.  
Because there is no native way i could find to do it.
So yeh... basically its my own fault. But it would be nice if i could have a method to reset groupe as i need.

wallabie

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 200
    • View Profile
Re: Toggle group not working in accordion when item is collapsed.
« Reply #6 on: June 13, 2014, 02:06:16 AM »
"@wallabie: If I understand you correctly you are saying you have a bunch of toggles all in the same group, and you show some of them while hiding others? The toggle groups only work for enabled toggles. Meaning if some are disabled at the time of you changing the state, those disabled toggles will not be "unset" because as far as NGUI is concerned disabled objects don't actually exist as a part of the UI.

You need to use different groups. Choose a unique group ID for each of your accordion."

I cannot do this because the items in the accordion are thumbnails of photos, each accordion header is a category.  So clicking on one photo thumbnail highlights it and should unhighlight the previously selected photo thumbnail that is in the other categories.



ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Toggle group not working in accordion when item is collapsed.
« Reply #7 on: June 13, 2014, 05:05:30 AM »
@wallabie: Ah, I see. Well in that case, I advise adding a script to your toggle (or better yet -- to whatever is affected by the toggle's change event) to run through all of your toggles and set their state to (thisToggle == UIToggle.current) so that only the one whos state is 'true' remains active.

wallabie

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 200
    • View Profile
Re: Toggle group not working in accordion when item is collapsed.
« Reply #8 on: June 14, 2014, 04:36:01 AM »
I ended up taking out the toggle and rolling my own way of managing the highlighting.