GUIStyle Manual     Reference     Scripting  
Scripting > Runtime Classes > GUIStyle
GUIStyle

Style settings for a GUI element.

This class contains all information for how a gui element should be rendered. It contains information for font, icon placement, background images, and spacing. It does not contain information for what it contains - just defines how any text rendered with this style should be displayed. It does not define what interactions can occur with the element, but defines the display settings commonly used in by the interactions.

The settings of a GUIStyle. It is modelled after a CSS Style. It contains settings for the following items:

Background images
These are rendered behind the contents. Different images can be assigned for normal display, when the user hovers the mouse over the element, when the user presses it down - as well as alternatives for when the element has been turned on - like toggle butons do. Below, these are referred to as style states. See Also: normal, hover, active, onNormal, onHover, onActive - these contain the background image & text color properties for each state.
Text rendering
The style can define a font for text rendering, as well as alignment, wordwrap and clipping settings. It also defines colors for the text in the various states of the style element See Also: font, alignment, wordWrap, normal, hover, active, onHover, onActive
Icon Placement
GUIStyles can be rendered with either text, and icon or both. The GUIStyle defines where these two are rendered in relation to each other (or can force it to only display one of them). See Also: imagePosition
Sizing and Spacing Options
GUIStyles contain padding, margins and borders. These corresponds loosely to the similar named CSS properties. A GUIStyle can optionally define a fixed width and height. See Also: margin, padding, border, fixedWidth, fixedHeight

Variables
name

The name of this GUIStyle. Used for getting them based on name....

normal

Rendering settings for when the component is displayed normally.

hover

Rendering settings for when the mouse is hovering over the control

active

Rendering settings for when the control is pressed down.

onNormal

Rendering settings for when the control is turned on.

onHover

Rendering settings for when the control is turned on and the mouse is hovering it.

onActive

Rendering settings for when the element is turned on and pressed down.

focused

Rendering settings for when the element has keyboard focus.

onFocused

Rendering settings for when the element has keyboard and is turned on.

border

The borders of all background images.

margin

The margins between elements rendered in this style and any other GUI elements

padding

Space from the edge of GUIStyle to the start of the contents.

overflow

Extra space to be added to the background image.

font

The font to use for rendering. If null, the default font for the current GUISkin is used instead.

imagePosition

How image and text of the GUIContent is combined.

alignment

Text alignment.

wordWrap

Word wrap the text?

clipping

What to do when the contents to be rendered is too large to fit within the area given.

contentOffset

Pixel offset to apply to the content of this GUIstyle

fixedWidth

If non-0, any GUI elements rendered with this style will have the width specified here.

fontSize

The font size to use (for dynamic fonts)

fontStyle

The font style to use (for dynamic fonts)

fixedHeight

If non-0, any GUI elements rendered with this style will have the height specified here.

stretchWidth

Can GUI elements of this style be stretched horizontally for better layouting?

stretchHeight

Can GUI elements of this style be stretched vertically for better layouting?

lineHeight

The height of one line of text with this style, measured in pixels. (Read Only)

Constructors
GUIStyle

Constructor for empty GUIStyle.

Functions
Draw

Draw plain GUIStyle without text nor image.

DrawCursor

Draw this GUIStyle with selected content.

DrawWithTextSelection

Draw this GUIStyle with selected content.

GetCursorPixelPosition

Get the pixel position of a given string index.

GetCursorStringIndex

Get the cursor position (indexing into contents.text) when the user clicked at cursorPixelPosition

CalcSize

Calculate the size of a some content if it is rendered with this style.

CalcScreenSize

Calculate the size of an element formatted with this style, and a given space to content.

CalcHeight

How tall this element will be when rendered with content and a specific width.

CalcMinMaxWidth

Calculate the minimum and maximum widths for this style rendered with content.

Class Variables
none

Shortcut for an empty GUIStyle.

Class Functions
operator GUIStyle

Get a named GUI style from the current skin.