Can someone elaborate on the GUIStyle.Draw Parameters?

They aren’t entirely clear. The documentation is a bit lacking.

position : Rect, - Kind of poorly named because it’s more than position. Itpretty much defines the boundaries for the component.
content : GUIContent, - Straight forward for the most part.
isHover : bool, - Flags if the mouse is over top of it. Makes sense.
isActive : bool, - ???
on : bool, - ???
hasKeyboardFocus : bool - I’m guessing it gives the component the keyboard focus in the way that the isHover evokes the hover content.

on and isActive is a bit confusing.

To my understanding of component states. One generally has an “enabled” state which is an overriding state that greys out a component. The other is evoking the appearance to indicate that it’s engaged. Like making button text go green or something or setting an “depressed” state visual.

I’m just not sure what does what.

Any clarifications would be most appreciated.

Jeremy

Up ! Need help with isActive parameter

Here is what I have deduced :

isHover and isActive parameters refer to the GUIStyle.hover and GUIStyle.active fields. Use a GUISkin and it makes more clear :

GUIStyle myStyle = GUI.Skin.GetStyle("myCustomStyle");
GUIStyle.Draw(myRect,mystring,true,false,false,false);

It will draw your string with your custom style with the Hover background and Hover text color you defined with the GUISkin.

The on parameter seems to refer to the OnHover and OnActive fields of a style. For example, if you want to draw your content with the OnHover look, you write :

GUIStyle myStyle = GUI.Skin.GetStyle("myCustomStyle");
GUIStyle.Draw(myRect,mystring,true,false,true,false);

It makes sense : isHover + on = OnHover, same with isActive.

Then there is the hasKeyboardFocus parameter. I think it refers to the Focused/OnFocused field, but there is no isFocus parameter ^^ It simply use the isHover parameter (I mean, focus is use for keyboard and hover for mouse but it is the same “action”)

My tests seem to agree with that explanation :slight_smile:

The only problem is the isActive parameter which doesn’t seem to work :frowning:
When I write :

GUIStyle myStyle = GUI.Skin.GetStyle("myCustomStyle");
GUIStyle.Draw(myRect,mystring,false,true,false,false);

It doesnt draw my content with the Active background and text color of my style :frowning:
Can someone explain that ? :frowning:

Please :smile:

Thanks KevS,

I had the same thoughts on the “on” parameter. But needed someone, who agrees.

Unfortunately, I have the same problem like you:
My active state is not drawn. Hover works fine, though. I tried every combination.
Please, can someone explain?

There are 8 states: the “on” states are states 5-8. These have to be defined in your style if you want to see them when using the “on” parameter set to true.

GUIStyle.Draw(position: Rect, isHover: bool, isActive: bool, on: bool, hasKeyboardFocus: bool): void;

When isHover, isActive and hasKeyboardFocus are false, draws the “Normal” state.

The following switches kick in, each taking precedence from the previous one:

isHover = true → draws the “Hover” state
isActive = true → draws the “Active” state
hasKeyboardFocus = true → draws the “Focused” state

Additionally, when the on switch is true, draws the “OnNormal”, “OnHover”, “OnActive” and “onFocused” state.

2 Likes

IsActive only works when isHover = true.