Author Topic: Keep draggable panel within viewport  (Read 5614 times)

WiS3

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Keep draggable panel within viewport
« on: April 23, 2014, 09:29:29 AM »
Hello, i'm trying to keep a Draggable panel within the game viewport.
I know that UIDragObject have the option Keep Visible, in order to constrain the position of the draggable object, but how i do create an object that fills the screen in order to attach it to the Content Rect?

I tried to set the anchor of the main Panel (the first one in Hierarchy) to be all 0, and use that as Content Rect, but the draggable panel is slowly moving off the screen by small amount if i try to drag or simply click on it.
« Last Edit: April 23, 2014, 10:05:13 AM by WiS3 »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Keep draggable panel within viewport
« Reply #1 on: April 24, 2014, 01:06:38 AM »
Create an object that fills the screen in order to attach it to the content rect? I am not sure what you mean by that.

Making a widget or panel stretch itself to fill an area is simple just by using anchors.

I am also unclear on what you did to your main panel. You set what to zero? Draggable panel will move? What's a draggable panel? Do you mean a scroll view, or some other object?

WiS3

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Keep draggable panel within viewport
« Reply #2 on: April 24, 2014, 10:12:20 AM »
Sorry if i did not explain well.

By draggable panel i mean, I have a UIPanel, called PartyPanel, inside i have a UIWidget named DragHandle with attached a UIDragObject, this Component have it's target to the PartyPanel.

By click and drag on DragHandle, i can move PartyPanel.

Now this panel can be dragged outside of the viewport, and can no longer be seen.

I want to prevent that, so i can move the panel freely on the entire viewport, but cannot go outside.
If it get dragged outside, on release it must adjust its position in order to be inside the viewport.

I may did not have understand how UIDragObject.KeepVisible works, but if i did, it is a rect where the panel can be dragged without it getting repositioned, right?

If it is, then by saying "Create an object that fills the screen in order to attach it to the content rect" i mean create a rect that fill the viewport, and use this rect as UIDragObject.ContentRect so the dragged panel can only be moved inside it.

What i have tried is, hight in hierarchy, just after the UICamera, i have a UIWidget named MainPanel, and this is used as Content Rect.



But with this setup, it is not working, i can still drag the panel on the screen, but if i release, it moves down by let's say 50px. Then if i try again to move it, it moves down again by another 50px, till it goes completely out of the screen. It is hard to explain what's going on, sorry.

I hope that i clarified what i want to do, and i apologize if my english is poor, i'm italian.
« Last Edit: April 24, 2014, 10:37:00 AM by WiS3 »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Keep draggable panel within viewport
« Reply #3 on: April 25, 2014, 07:05:13 AM »
Panels don't actually have a rectangle, so they have no dimensions to speak of. If you want there to be dimensions, use a widget like so:

UIWidget (ALT+SHIFT+W to add it, resize to your dimensions)
- PartyPanel
-- DragHandle, pointing to UIWidget

WiS3

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Keep draggable panel within viewport
« Reply #4 on: April 25, 2014, 10:05:29 AM »
I do have a UIWidget, it is called MainPanel, but it is a UIWidget, as you can also see from the picture.
It does stretch to fill the viewport. And DragHandle.ContentRect is pointing to this UIWidget.
« Last Edit: April 25, 2014, 10:27:40 AM by WiS3 »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Keep draggable panel within viewport
« Reply #5 on: April 25, 2014, 10:25:32 AM »
So why is it named Panel, and why does it have a rigidbody on it? Do you have a panel on it as well? You can't have a widget and a panel on the same object. It creates... oddities.

WiS3

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Keep draggable panel within viewport
« Reply #6 on: April 25, 2014, 10:30:45 AM »
Because first it was a panel, then i removed the UIPanel and added a UIWidget, i have removed the Rigidbody just now, and it does only have a UIWidget.
But it does not work, the strange behaviour described 2 post ago still happens.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Keep draggable panel within viewport
« Reply #7 on: April 25, 2014, 10:57:56 AM »
Alright, well if the Content Rect points to the widget, then that widget's bounds is what gets used to determine the content's bounds with the "restrict within panel" set.

WiS3

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Keep draggable panel within viewport
« Reply #8 on: April 25, 2014, 11:49:04 AM »
Edit: I've fixed it.

I didn't undertand how Keep Visible was working. The Content Rect is not the space where you can move the widget, but the Widget itself that is moving.

But let's say that i want a widget to be moveable only inside another widget, how you do that?
« Last Edit: April 25, 2014, 12:21:36 PM by WiS3 »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Keep draggable panel within viewport
« Reply #9 on: April 26, 2014, 01:30:27 PM »
You can't restrict it to another widget, but you can restrict it within a panel if you set its clipping to the area you want the restriction to work.

Note that the panel's clipping can be set to "Constrain But Don't Clip" if you don't want any visible clipping.