Search Unity

Can someone elaborate on the GUIStyle.Draw Parameters?

Discussion in 'Immediate Mode GUI (IMGUI)' started by majeric, Jul 13, 2011.

  1. majeric

    majeric

    Joined:
    Aug 17, 2010
    Posts:
    89
    They aren't entirely clear. The documentation is a bit lacking.

    http://unity3d.com/support/documentation/ScriptReference/GUIStyle.Draw.html

    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
     
  2. KevS

    KevS

    Joined:
    Apr 21, 2010
    Posts:
    51
    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 :

    Code (csharp):
    1. GUIStyle myStyle = GUI.Skin.GetStyle("myCustomStyle");
    2. 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 :

    Code (csharp):
    1. GUIStyle myStyle = GUI.Skin.GetStyle("myCustomStyle");
    2. 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 :)

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

    Code (csharp):
    1. GUIStyle myStyle = GUI.Skin.GetStyle("myCustomStyle");
    2. GUIStyle.Draw(myRect,mystring,false,true,false,false);
    It doesnt draw my content with the Active background and text color of my style :(
    Can someone explain that ? :(

    Please :D
     
  3. gekko22

    gekko22

    Joined:
    Aug 1, 2013
    Posts:
    9
    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?
     
  4. dkozar

    dkozar

    Joined:
    Nov 30, 2009
    Posts:
    1,410
    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.
    Code (csharp):
    1.  
    2. 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.
     
    doneykoo and Mark-Currie like this.
  5. unityBerserker

    unityBerserker

    Joined:
    Mar 31, 2016
    Posts:
    5
    IsActive only works when isHover = true.