Author Topic: Resize background to match UIGrid  (Read 9380 times)

drawmaster77

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 21
    • View Profile
Resize background to match UIGrid
« on: April 13, 2014, 02:29:03 AM »
Hi,

Sorry if this was asked many times before, I couldn't find it.

I have a UIGrid which I populate with items at a run-time. UIGrid itself is located inside a frame (UISprite) which needs to be resized to match updated grid's size (as opposed to clipping contents). How can that be done?

Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Resize background to match UIGrid
« Reply #1 on: April 13, 2014, 02:46:54 AM »
Make the sprite be separate from the grid and put the EnvelopContent script on it, targeting your grid.

drawmaster77

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: Resize background to match UIGrid
« Reply #2 on: April 13, 2014, 05:27:49 PM »
I think there's possibly a bug in SetRect code UIWidget.cs line 623

  1. width = finalWidth;
  2. height = finalHeight;
  3.  

should probably be

  1. this.width = finalWidth;
  2. this.height = finalHeight;
  3.  

since width/height is also a function parameter. It wasn't really working for me until I made that change anyway.

Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Resize background to match UIGrid
« Reply #3 on: April 14, 2014, 03:04:13 AM »
That's what it is. You should always update to the latest first.

drawmaster77

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: Resize background to match UIGrid
« Reply #4 on: April 14, 2014, 03:21:01 AM »
sorry about that.

But it looks like it's enveloping everything, including stuff clipped by panels? I have a scrollview in one of the items I am trying to envelop content on, is there anyway to only envelop visible items?

Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Resize background to match UIGrid
« Reply #5 on: April 14, 2014, 03:42:27 AM »
No, it doesn't consider clipping. It's a simple example script that shows the 3 lines of code necessary to resize one widget to envelop the content of some target object. If you want it to take clipping into consideration, write a custom function instead of calling NGUIMath.CalculateRelativeWidgetBounds, or at least skip the scroll view. However if I was at this point, I'd start wondering why I need to resize one widget to envelop the bounds of something that has been clipped, and why not just leave the widget with a fixed size.

drawmaster77

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: Resize background to match UIGrid
« Reply #6 on: April 14, 2014, 04:14:03 AM »
Well I was trying to do a fancy pop-up window thingy which would scale based on amount of text in it and also contain a long list of options (inside the UIGrid), here's an early screenshot:

(textboxes can be of variable height)

I was using a widget as a way to calculate center of my object, so that I can correctly position it next to the node selected.

I think I will just write my own script to calculate the size, as number of objects inside that affect it doesn't really change.

Thanks