Author Topic: Preferred method for showing UIButton 'Selected' state?  (Read 2581 times)

RobBrooks

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 19
    • View Profile
Preferred method for showing UIButton 'Selected' state?
« on: November 19, 2014, 06:56:03 AM »

At the moment I'm kind of hacking this myself by managing states and swapping normalSprite references as required but I was just wondering whether there's a 'native' way of doing this 'properly' ?

Just to describe via application specifics: I've got a ScrollView which contains a Grid full of buttons. When I click on one button, I want it to highlight in a persistent way that demonstrates the selected state. I also want to ensure that all the other buttons in the Grid are shown as 'Unselected' when this happens.

I have other more complex scenarios which including multiple button states other than just 'on' and 'off' but I'm happy to perform my own state/viz management in those instances. It would be nice to know if there's an officially sanctioned way of doing the basic stuff is all.

Many thanks.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Preferred method for showing UIButton 'Selected' state?
« Reply #1 on: November 19, 2014, 03:51:55 PM »
When using a controller-based input, button's hovered state is automatically assumed as a result of selection changes. If your UICamera is using both mouse and keyboard events though, the selection won't behave the same way as mouse hover will be used for that instead of selection.

Turn off mouse and touch events on UICamera.

RobBrooks

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 19
    • View Profile
Re: Preferred method for showing UIButton 'Selected' state?
« Reply #2 on: November 20, 2014, 10:20:52 AM »

I appreciate that, ArenMook as I am using pad input when the context is appropriate, but when in pure mouse control mode, I sometimes want to click on a button in a grid and what that stay highlighted to show a 'selected' state.

If I then click on another button in the grid, I'd like the same thing to happen to the new button while the previous button reverts to 'unhighlighted'.

As I say, right now, I'm maintaining the states myself and OnClick() altering the sprite and button's normalColor to suit. I generally follow this by forcing a OnHover(false) which refreshes the visual state of the button with my new color.

As I say, this is a hack. It works, but as this seems to me to be a behaviour that probably gets used a lot, I was wondering whether there is native support for it?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Preferred method for showing UIButton 'Selected' state?
« Reply #3 on: November 20, 2014, 08:45:14 PM »
If you want to click on something and have it keep that state, then you are trying to make a toggle, not a button. It's a different type of a control.