Author Topic: Having trouble with toggles  (Read 5150 times)

camlost

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Having trouble with toggles
« on: April 01, 2014, 08:04:49 PM »
Hi all,

I'm having a trouble getting object toggles working in certain scenarios.

Is there a way of having a button turn on some objects and others off but not have the others toggle back on when the initial object is turned off again?

Ok, so say I have 3 buttons and 3 objects.
I want to be able to tap button 1 to turn object 1 on and objects 2 and/or 3 off. When I tap button 1 again I want object 1 to turn off and not have any other object turn on.

Setting toggle groups almost works but this ends up with the objects that were off turning on again when they should only turn on when their button in pressed.

I'm sure I must be missing something obvious here.

thanks,

wallabie

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 200
    • View Profile
Re: Having trouble with toggles
« Reply #1 on: April 02, 2014, 12:13:07 AM »
I have the same question.

On IOS,

The idea is tap item to Select, tap on the same item again to deselect.

camlost

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Having trouble with toggles
« Reply #2 on: April 02, 2014, 02:35:35 PM »
How about this one.

I have a number of buttons which toggle between panels containing scrollviews. toggling between them is fine.

I have added close buttons to the panels but once the panel has been toggled off once the close button does not function, the scroll view still functions however.

I am using the toggle object script to both toggle between the panels and close them. Should this work or am I coming at it the wrong way?

wallabie

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 200
    • View Profile
Re: Having trouble with toggles
« Reply #3 on: April 05, 2014, 05:59:05 AM »
Hello, is there an answer to this ?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Having trouble with toggles
« Reply #4 on: April 05, 2014, 11:47:05 AM »
@wallabie: tap to select, tap to deselect? That just makes it a toggle, not a button.

@camlost: I am not clear on what it is you're trying to do. You're talking about buttons, yet describing behaviour of a toggle (binary state -- on and off). How are you turning off whatever it is you're turning off?

wallabie

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 200
    • View Profile
Re: Having trouble with toggles
« Reply #5 on: April 05, 2014, 12:15:37 PM »
Ok here's another attempt at describing the situation:

1. a horizontal scrollList with 5 photos.
2. each item is a clickable photo.
3. Initial state is no photos are selected/highlighted.
4. User clicks on the 1st photo.  This then gets highlighted.
5. User clicks on 2nd photo, the 1st photo is un-highlighted and the 2nd is highlighted.
6. User clicks on 2nd photo again and now it also gets un-highlighted.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Having trouble with toggles
« Reply #6 on: April 06, 2014, 02:34:11 AM »
Right, that's a set of toggles with the same Group ID with "Option can be none" turned on.

wallabie

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 200
    • View Profile
Re: Having trouble with toggles
« Reply #7 on: April 06, 2014, 08:00:59 AM »
It's not exposed in the inspector for UIToggle.

wallabie

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 200
    • View Profile
Re: Having trouble with toggles
« Reply #8 on: April 06, 2014, 08:46:37 AM »
Ok, I set it in code.   

How to get the state of the button ? because when a photo item is selected I need to update another text object  to the name of the selected photo.  If its deselected, then I also need to update to nill.

If I know what state the button is in, either normal or highlighted, then I can act accordingly.  I can only find setState but not getState.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Having trouble with toggles
« Reply #9 on: April 06, 2014, 01:30:21 PM »
UIToggle.value is the state of the toggle.

There is no button "state".

wallabie

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 200
    • View Profile
Re: Having trouble with toggles
« Reply #10 on: April 06, 2014, 10:54:16 PM »
How then do we know what state a button is in ?   If there is not state property for the button then this is definitely has to be added.  Just look at any other GUI systems.  Also strange that you mentioned that there is no "state" for the button. Looking the the button code, there is SetState(), but not a way to Get the State. 
« Last Edit: April 06, 2014, 11:10:45 PM by wallabie »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Having trouble with toggles
« Reply #11 on: April 08, 2014, 12:35:03 AM »
Let me rephrase... there is no public "state" on the button because it's an internal value used for state visualization. In any case, you can always add a property like this if you really need it:
  1.         /// <summary>
  2.         /// Button's current state.
  3.         /// </summary>
  4.  
  5.         public State state { get { return mState; } set { SetState(value, false); } }
I'll include it in the next update.