Author Topic: method/function to move widget to screen edge?  (Read 5937 times)

tr4np

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 17
    • View Profile
method/function to move widget to screen edge?
« on: April 09, 2014, 10:34:13 AM »
I'm trying to "anchor" a widget to the side of the screen.  However, I only want to do this on demand, since this will be a moveable window (which I sometimes want to reset back to its anchored position).  Is there a method that already does this?

I found UIAnchor, but that uses the widget's anchor point, so I have to compensate for it using offsets.  Also, once I drag the window somewhere else, the anchor no longer works properly when I re-activate it (since its transform has changed; I have to reset both the anchor's and widget's position for it to work again).

What I would love to have is a method that will move a widget to the specified edge/corner, while also taking into account the widget's bounds instead of its anchor point.  For instance, if I move it to the bottom left of the screen, the bottom left corner of the widget should touch the bottom left of the screen.  Like-wise, if I move it to the top right of the screen, the top right of the widget should touch the top right of the screen.  Currently, if the widget's anchor point is at the top left, then moving it to the bottom right of the screen would move it's top left point to the bottom right of the screen (i.e. it moves off of the screen).

This seems like a common use case, so I'm hoping this functionality already exists. 

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: method/function to move widget to screen edge?
« Reply #1 on: April 10, 2014, 06:40:17 AM »
UIAnchor is a legacy component. Widget shave anchoring built-in now. If you don't want it to update every frame, choose "OnEnable" as the Execute option, then call UpdateAnchors() yourself.

tr4np

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: method/function to move widget to screen edge?
« Reply #2 on: April 10, 2014, 02:29:36 PM »
UIAnchor is a legacy component. Widget shave anchoring built-in now. If you don't want it to update every frame, choose "OnEnable" as the Execute option, then call UpdateAnchors() yourself.

Does choosing "OnEnable" never move the widgets automatically, or only moves them one time (on startup)?  I saw that option, but the name made me think that it would run each time the widget was activated (since we set an object to Active to enable it).  I don't want the widget moved each time it is re-activated.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: method/function to move widget to screen edge?
« Reply #3 on: April 11, 2014, 07:08:53 AM »
Yes it would execute every time the widget gets enabled. The other option is every Update.

tr4np

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: method/function to move widget to screen edge?
« Reply #4 on: April 11, 2014, 08:28:48 AM »
Yes it would execute every time the widget gets enabled. The other option is every Update.

So does this mean choosing "OnEnable" is not an option for me?  I don't want it to execute each time I activate the widget.  I have a moveable window with a close button that deactivates/hides the window.  When I reactivate it, I want it to show up at the same place it was before.  However, I want to be able to reset the layout as needed.  What is the best way to go about doing this?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: method/function to move widget to screen edge?
« Reply #5 on: April 12, 2014, 04:18:18 AM »
If you don't want it to execute at all except when you deem it necessary, then no, it won't work for you then. Removing the anchor or modifying the script will then your only options.