Support => NGUI 3 Support => Topic started by: drawmaster77 on April 13, 2014, 02:29:03 AM
Title: Resize background to match UIGrid
Post by: drawmaster77 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
Title: Re: Resize background to match UIGrid
Post by: ArenMook 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.
Title: Re: Resize background to match UIGrid
Post by: drawmaster77 on April 13, 2014, 05:27:49 PM
I think there's possibly a bug in SetRect code UIWidget.cs line 623
width = finalWidth;
height = finalHeight;
should probably be
this.width= finalWidth;
this.height= finalHeight;
since width/height is also a function parameter. It wasn't really working for me until I made that change anyway.
Thanks
Title: Re: Resize background to match UIGrid
Post by: ArenMook on April 14, 2014, 03:04:13 AM
That's what it is. You should always update to the latest first.
Title: Re: Resize background to match UIGrid
Post by: drawmaster77 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
Title: Re: Resize background to match UIGrid
Post by: ArenMook 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.
Title: Re: Resize background to match UIGrid
Post by: drawmaster77 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: (https://dl.dropboxusercontent.com/u/5102757/TankGame/44.png) (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.