Author Topic: Anchoring a row of buttons  (Read 4523 times)

Paul5

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
Anchoring a row of buttons
« on: September 25, 2014, 04:19:29 PM »
Hello,
I have a row of buttons that I want to anchor to the top of the screen. I've tried various methods including anchoring them to each other, anchoring them to the root etc. but none of them have produced the desired effect. I want them to be spaced evenly regardless of the resolution. Currently, however, the middle two buttons just get stretched out instead of spaced evenly. Any ideas?

Thanks
« Last Edit: September 25, 2014, 04:34:33 PM by Paul5 »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Anchoring a row of buttons
« Reply #1 on: September 25, 2014, 07:52:36 PM »
Use Advanced anchoring with Custom settings, specifying 0 for Absolute and some 0 to 1 value for the relative fields (the slider). For example 0.3 means 30% from the left if it's on Left/Right, or 30% from the bottom if it's on Top/Bottom.

Paul5

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: Anchoring a row of buttons
« Reply #2 on: September 25, 2014, 08:48:49 PM »
Use Advanced anchoring with Custom settings, specifying 0 for Absolute and some 0 to 1 value for the relative fields (the slider). For example 0.3 means 30% from the left if it's on Left/Right, or 30% from the bottom if it's on Top/Bottom.
Thanks for the reply. I played with this for a bit and basically had the same results with a variety of methods. I want some blank space between the buttons when the resolution gets bigger, but when the buttons are anchored they always just stretch themselves instead of leaving some space. I've anchored them to the root, other buttons, some of both, and they all seem to have the same sort of behavior.

Paul5

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: Anchoring a row of buttons
« Reply #3 on: September 26, 2014, 04:10:19 PM »
So I gave up on the anchors and decided to use a simple script instead. This accomplished the task, however, I seem to have a hard time with the constrained mode using my script. In the pixel perfect mode this script works fine, however, in constrained mode it doesn't (I'm guessing it has something to do with the resolution being different or something). Any ideas? Thanks.

http://pastebin.com/a6Es5SpR


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Anchoring a row of buttons
« Reply #4 on: September 27, 2014, 07:12:24 PM »
You need to take UIRoot's pixelSizeAdjustment into account. When UIRoot is set to Constrained, it means its virtual pixels don't match your screen pixels, so you can't simply use Screen.width and height.

Paul5

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: Anchoring a row of buttons
« Reply #5 on: September 27, 2014, 08:21:23 PM »
You need to take UIRoot's pixelSizeAdjustment into account. When UIRoot is set to Constrained, it means its virtual pixels don't match your screen pixels, so you can't simply use Screen.width and height.
That is what I needed.
Thanks!