Support => NGUI 3 Support => Topic started by: itszander on September 11, 2012, 03:27:48 PM
Title: Scrollbar Foreground image scaling
Post by: itszander on September 11, 2012, 03:27:48 PM
Hi all, I'm having a very strange problem. I'm using a custom foreground png for the scrollbar widget. When I play the game with the scrollbar on, the size of the foreground png scales to 14x120 px.
When I stop the game I can manually resize the scrollbar foreground to its correct size (42x42 px) but then it jumps back to 14x120 on play.
thoughts?
-zander
Title: Re: Scrollbar Foreground image scaling
Post by: itszander on September 11, 2012, 04:02:25 PM
Just found a great workaround for this!
1. make a scrollbar. Make the width of the background the size of the foreground sprite. 2. adjust the size of the sprite in the UIScrollbar script. This will make the foreground sprite look the way it's supposed to. 3. make a copy of the background as JUST a sprite, outside the hierarchy and place this in the correct location. 4. move the scrollbar to the correct location and turn off the background in the inspector.
tada!
-Z
Title: Re: Scrollbar Foreground image scaling
Post by: Nicki on September 12, 2012, 04:10:45 PM
Scrollbar foreground is supposed to scale to fit the content of your drag panel. This is intended behavior. Look at the example, I think you're looking for the "thumb" object, not foreground.
Title: Re: Scrollbar Foreground image scaling
Post by: itszander on September 13, 2012, 08:15:49 AM
Hi Nicky, thanks for the response.
I've attached a screenshot of the issue. I sort of fixed it but then when I hooked it up into the GUI the problems still exist.
Is there a way to make the image square? Am I missing something in terms of implementation?
-zander
Title: Re: Scrollbar Foreground image scaling
Post by: itszander on September 13, 2012, 08:19:19 AM
update: I just looked at the nGUI example 6 (scroll view) which has a scroll bar in it, but didn't see a "thumb" component, game object, etc.
I do see foreground and background for the scroll bar tho.
Title: Re: Scrollbar Foreground image scaling
Post by: Nicki on September 13, 2012, 08:26:57 AM
Ah ok, I remembered it wrong.
I think you're thinking of scrollbars like a windows user, not an iOS user. :)
Foreground is not supposed to be click/draggable. It resizes to the size of the content in your dragpanel, while background is the full size of the content.
On UI Slider (the script on the progress bar you can insert with the widget tool) there's a reference to a transform that's "Thumb". This is what you need to use. You insert a new Sprite under the progress bar as a child of that game object, and you drag the gameobject to thumb. Now you can drag the thumb around and it will move your content.
It can also be set in code if you prefer. This won't change size and always stays like you want it to.
Does that make sense?
Title: Re: Scrollbar Foreground image scaling
Post by: Phong on January 17, 2013, 06:07:53 PM
I looked at the code for UI scrollbar and noticed that the foreground is scaled to fit inside the "center" slice of the background sliced sprite. So if your scrollbar is vertical and it is a sliced sprite with borders specified for the left and right. The foreground image will be squashed horizontally to fit in the center slice. One solution is to set the left and right borders to zero for the background for a vertical scrollbar and set the top and bottom borders to zero for the background for a horizontal scrollbar.
Title: Re: Scrollbar Foreground image scaling
Post by: jeldrez on May 08, 2013, 11:52:26 AM
There's no way Draggable Panel supports UISliders? I want to use a thumb for moving the panel.
Title: Re: Scrollbar Foreground image scaling
Post by: agentsmith666 on June 11, 2013, 06:28:29 PM
I'm running into this issue as well. I have a scrollbar that scrolls a dynamic list of item names and want to use a fixed size scroll bar. I notice there's no option to do this through UIScrollbar (like a check box or something...). Any other ideas besides having a script override the foreground/thumb size?
Update:
I added a bool to UIDraggablePanel.cs called isScrollbarFixedSize defaulted to false. Then I added the checks where UIDraggablePanel.cs adjusts the size of the scrollbar's foreground/thumb. It seems to be working well. UIScrollBar's inspector's slider bars still work and can be used to set the size of the foreground/thumb like normal.
...
if(!isScrollbarFixedSize )
horizontalScrollBar.barSize= 1f - sum;
...
...
...
if(!isScrollbarFixedSize )
verticalScrollBar.barSize= 1f - sum;
Title: Re: Scrollbar Foreground image scaling
Post by: Fireball14 on April 02, 2014, 09:09:16 AM
Thx a LOT! This is really what i need! I wish this was standard feature of NGUI!