EDIT: attempting to state my question more clearly
In my game the mouse scrollwheel zooms the camera in and out.
I have a GUILayout.Label on the screen that is inside a scrollview.
The code looks something like this:
GUILayout.BeginArea(someRectangle);
scrollVector = GUILayout.BeginScrollView(scrollVector);
GUILayout.Label(textOfArbitraryLength);
GUILayout.EndScrollView();
GUILayout.EndArea();
If textOfArbitraryLength is long enough (such that it is taller than someRectangle and requires a vertical slider) I would like for mouse scrollwheel input to control the scrolling of the text.
If textOfArbitraryLength is small enough (such that it fits inside of someRectangle without scrolling) I would like for mouse scrollwheel input to control the zooming of the camera.
Is it possible to determine if there is a slider present in the scrollview?
I want to be able to determine when the Camera Control script should ignore scrollwheel input.
Sorry if I did a bad job explaining what I was looking for... And thanks in advance for any help.
original post:
Is it possible to determine whether or not a slider is being used inside a scrollview when using GUILayout?
I have a label inside a scrollview and would like to ignore input from the mouse scrollwheel when the mouse is over the label AND the content is scrollable. In other words, I don't want undesired things to happen in the scene when the user is trying to scroll over the text in the label.
If the content of the label fits within the scrollview (ie there is no slider) I would like to process mouse input as usual. Most of the time this is the case...
I can almost accomplish this by checking to see if the scrollPosition vector's y-value is 0, but not quite. If the user scrolls up too much, there will be undesired effects once the slider hits the top and the scroll wheel keeps moving.
Thanks in advance for any help...
Thanks, but this is not what I'm looking for. This would conditionally ignore mouse input for the slider. My goal is NOT to effect the scene when the mouse scrollwheel input is intended for a scrollview. In my game the mouse scrollwheel causes the camera to zoom. I would like to ignore this effect when the user's mouse is over a scrollview area.
– jahroyOk, that's quite simple, i will add it to my answer ;)
– Bunny83Will that really tell me whether or not there is a slider present? It's very easy to tell if the mouse is over a given rectangle... I'm wondering if you can determine whether or not the contents of the scrollview are large enough to require a slider. In other words if the contents of scrollview A are taller than scrollview A's rectangle, let scrollwheel input scroll the text. If they are not (if all of the text fits in the rect w/o scrolling) let scrollwheel input zoom the camera. Is it possible to tell whether or not there's a slider in the scrollview?
– jahroyThanks for your answers. I apologize if my question was not clear. I just tried to re-word my original post...
– jahroyGreat, thanks for the update ;). Ok, as far as i know there's no generic way to determine if the scrollbars are visible for a scrollview (you can't even prevent them). However in your case (if that's not just an example) if you display only one element inside the scrollview you can use
– Bunny83GUIStyle.CalcSizeor if you use wordwrapGUIStyle.CalcHeightto get the required size of an gui element. Just match it with your Rect.