Author Topic: feature suggestion: UIDraggablePanel bound offset  (Read 5916 times)

serioustommy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
feature suggestion: UIDraggablePanel bound offset
« on: June 15, 2012, 01:52:41 PM »
Currently the bounds for the content within a UIDraggablePanel is the union of the bounds of all the widgets within it. However this means that the content will always spring back so that the edge of the content aligns with the edge of the UIDraggablePanel's clipping box, without any space in between.

I've added a very simple offset support for modifying the bounds in UIDraggablePanel if anyone is interested:

  1. public float    boundTopOffset;
  2. public float    boundBottomOffset;
  3. public float    boundLeftOffset;
  4. public float    boundRightOffset;
  5.  
  6. public Bounds bounds
  7.         {
  8.                 get
  9.                 {
  10.                         if (!mCalculatedBounds)
  11.                         {
  12.                                 mCalculatedBounds = true;
  13.                                 mBounds = NGUIMath.CalculateRelativeWidgetBounds(mTrans, mTrans);
  14.                                
  15.                                 // apply bound offsets
  16.                                 Vector2 min = mBounds.min;
  17.                                 min.x -= boundLeftOffset;
  18.                                 min.y -= boundBottomOffset;
  19.                                 mBounds.min = min;
  20.                                
  21.                                 Vector2 max = mBounds.max;
  22.                                 max.x += boundRightOffset;
  23.                                 max.y += boundTopOffset;
  24.                                 mBounds.max = max;
  25.                         }
  26.                         return mBounds;
  27.                 }
  28.         }
  29.  

Perhaps something similar can be added to the official release as well, if there's a cleaner way of handling this.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: feature suggestion: UIDraggablePanel bound offset
« Reply #1 on: June 17, 2012, 07:09:51 PM »
You could always just move / resize the clipping area if you wanted it to be elsewhere.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: feature suggestion: UIDraggablePanel bound offset
« Reply #2 on: June 18, 2012, 12:31:38 PM »
I ended up have en 1x1 transparent sprite at the edges of the widgets in my grid inside the draggable panel - that makes it margin to that. It's a hack, but it works. ;)

serioustommy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
Re: feature suggestion: UIDraggablePanel bound offset
« Reply #3 on: June 20, 2012, 05:06:00 AM »
yeah I thought about that Nicki but the thought of having to waste rendering time on a transparent sprite makes me feel dirty for some reason :) I know it doesn't cost much though so that's another solution.

Aren, the problem is that if you move or resize the clipping area of the panel the contents will end up being clipped in the wrong place. An example is that you want to leave a margin on the edge of the screen but you still want the contents to be clipped by the edge of the screen. Hence I thought a tweakable offset would be beneficial.

Again I'm just hoping that if it's supported officially I wouldn't have to apply my changes after every update. Not a big issue though. Thanks for being a good support.