Author Topic: UIRect  (Read 38729 times)

Bobbin

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
Re: UIRect
« Reply #15 on: May 14, 2014, 07:08:11 AM »
Ok.
But how do I know which side of the target the anchor attaches to?
No one ever said being a Heretic was easy.
So may we meet in Less Interesting Times.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UIRect
« Reply #16 on: May 14, 2014, 07:17:05 AM »
widget.leftAnchor.relative = 0f; <-- left for horizontal anchors (bottom for vertical)
widget.leftAnchor.relative = 1f; <-- right for horizontal anchors (top for vertical)
widget.leftAnchor.relative = 0.5f; <-- center
widget.leftAnchor.relative = 0.25f; <-- 25% from the left, etc.
« Last Edit: May 14, 2014, 07:22:28 AM by ArenMook »

Bobbin

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
Re: UIRect
« Reply #17 on: May 14, 2014, 07:20:27 AM »
So the absolute value of the AnchorPoint is a flag of sorts and I need the relative for offset?
Uhm... looking at UIRect.cs, I think it's the other way around.
No one ever said being a Heretic was easy.
So may we meet in Less Interesting Times.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UIRect
« Reply #18 on: May 14, 2014, 07:22:56 AM »
Yes, relative is what I meant. Final position = Parent's width or height * relative + absolute.

Bobbin

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
Re: UIRect
« Reply #19 on: May 14, 2014, 07:24:01 AM »
Excellent. Thank you.
No one ever said being a Heretic was easy.
So may we meet in Less Interesting Times.

honeal

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: UIRect
« Reply #20 on: May 15, 2014, 07:39:42 PM »
ArenMook, have you given any thought to adding a max/min width/height option to UIWidget similar to the native Android layout system? I find myself missing that functionality quite often when designing for multiple screens.

toto007

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Re: UIRect
« Reply #21 on: May 16, 2014, 03:55:50 AM »
I'm trying to understand what it means to activate the voice Execute: "onEnable."

I imagine that the anchoring is done only when the widget is enabled. So I try to manually move the object on the scene after it has been activated but remains fixed and does not move.

Why?

Don't use Instantiate. Use NGUITools.AddChild.

OnEnable still does it in Update, but only once, so if you change the position immediately after instantiation, then you are doing it before it runs.

SetAnchor(null) will indeed clear it.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UIRect
« Reply #22 on: May 16, 2014, 03:03:58 PM »
"OnEnable" means it's updated once -- after the widget is first enabled. After that the anchor will not be updating, so moving the target object won't move the anchored widget. "OnUpdate" means it will update every Update call (every frame), so it will always track the target's movement.

RDeluxe

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
Re: UIRect
« Reply #23 on: May 29, 2014, 06:08:14 PM »
Hi !

Edit : I posted the question here
« Last Edit: May 30, 2014, 06:03:34 AM by RDeluxe »

hojjatjafary

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: UIRect
« Reply #24 on: February 07, 2016, 07:24:58 AM »
Does the anchoring supports chaining? I have 4 buttons from left to right in a row [A B C D], I anchored B's left to A's right and so on.

Size of buttons change at runtime according to their label size, because labels are localized strings, the size of labels set to widget size using a property binding component.

but seems this depends on the order of calling update by Unity.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UIRect
« Reply #25 on: February 08, 2016, 01:59:54 AM »
Yes, it should work fine with chained elements assuming the anchors are set to update in Update rather than OnEnable/OnStart, although I would caution you to use that sparingly. Anchoring calculations can quickly add up to become expensive. Also note that if you have nested elements, anchoring can become unpredictable when your anchored objects happen to result in a child element being moved that already completed its anchoring calculations. The way it works is when NGUI does an update it checks -- has the widget that the current one is anchored to completed its anchoring calculations? If not, the pre-requisite widget's anchoring code is ran first. It's nested.

skatola

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: UIRect
« Reply #26 on: May 29, 2016, 11:41:51 AM »
excuse me...there's a way to execute anchors in runtime?
for example if i set anchors execute "on start" and i need to execute again in runtime, how can i do that? thanks a lot like always

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UIRect
« Reply #27 on: May 29, 2016, 11:50:16 AM »
That would be the OnUpdate setting.

skatola

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: UIRect
« Reply #28 on: May 29, 2016, 03:33:11 PM »
That would be the OnUpdate setting.

but i don't want to update the anchors every frame, but only when i want, there's no way to update anchors via script?
try to explain it better:
i have a 2d ui texture on screen in full screen, anchored to camera for take the fullscreen and with fixed aspect enabled for manteining img ratio, when i rotate the device the image appear small in the center of the screen, i just want recalculate the anchors to adapt the texture in full screen with the new device orientation.
sorry for my english, hope it is understandable : )
« Last Edit: May 29, 2016, 03:46:56 PM by skatola »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UIRect
« Reply #29 on: June 01, 2016, 10:43:01 PM »
UIRect.UpdateAnchors(). Check first, ask later. :P