- Home /
Put toggle label on left side of button and hover
I would like to have toggle buttons with text labels on their left side.
I've set GUISkin.toggle.contentOffset to a negative integer to position the text correctly, but would like to make it so the button becomes 'active' when the mouse hovers over the text (not just the button). The default behavior is for the 'hover zone' of a toggle button is to begin at the left edge of the button and extend to the right based on the position:Rect parameter.
Can this be achieved without creating a new background image? I really like the way the default toggle button style looks.
Any help would be greatly appreciated...
Answer by jahroy · Apr 20, 2011 at 10:10 PM
I figured it out...
Rather than position the label to the left of the button by setting GUI.skin.toggle.contentOffset to a negative value, I'm going to position my button to the right of the label by setting GUI.skin.toggle.overflow.left to a negative number.
var isActive : boolean = false; var theRect : Rect = Rect(0, 0, 200, 20); var txt : String = "Select";
function OnGUI() { var theStyle : GUIStyle = GUI.skin.toggle; theStyle.overflow.left = theRect.width * -1; isActive = GUI.Toggle(theRect, isActive, txt, theStyle); }
The result will be a toggle button that enters its 'active' state whenever the mouse hovers over the label on the left side of the button.
Your answer
Follow this Question
Related Questions
Toggle GuiTexture 1 Answer
Can I have toggle buttons in a selection grid? 1 Answer
How does GUI.Toggle work? 2 Answers
Actually do something with GUI selection grid 1 Answer
Toggle GUITexture V.2 1 Answer