Click or drag to resize

GuiScaledSkin Class

Component for automatic GUISkin rescaling, based on the current game's GUI scale setting.
Inheritance Hierarchy
SystemObject
  KSPDev.GUIUtilsGuiScaledSkin

Namespace:  KSPDev.GUIUtils
Assembly:  KSPDev_Utils.2.6 (in KSPDev_Utils.2.6.dll) Version: 2.6 for KSP v1
Syntax
C#
public class GuiScaledSkin
Request Example View Source

The GuiScaledSkin type exposes the following members.

Constructors
  NameDescription
Public methodGuiScaledSkin
Creates a scaled skin instance.
Top
Properties
  NameDescription
Public propertyguiScale
The scale setting which this instance currently tracks.
Public propertyguiTitleHeight
The dialog title height with this skin applied.
Public propertyscaledSkin
The skin that is scaled to the current game's settings.
Top
Methods
  NameDescription
Protected methodFinalize
Unregisters any game's callbacks.
(Overrides ObjectFinalize.)
Public methodStatic memberScaleGuiStyle
Makes a style that respects the provided scale factor.
Public methodStatic memberScaleRectOffset
Scales the provided RectOffset by the scale factor.
Top
Fields
  NameDescription
Public fieldscaledSkinIsDirty
Tells if the skin must be recalculated on the next access to scaledSkin.
Top
Remarks

The scaling is achieved by proportional increase/decrease of the font size and margin/padding rects. The default font stays unchanged, but all the controls that use default font size will get overrides for the nwe scaled size. Some more elements will not get scaled:

  • The background images.
  • The textures, rendered via Label and DrawTexture controls.
  • The GUILayoutOption size settings.
  • The GUILayout.Space() control.

Examples
GuiScaledSkin _guiScaledSkin;

void OnAwake() {
  _guiScaledSkin = new GuiScaledSkin(() => GUI.skin);
}

void OnGUI() {
  using (new GuiSkinScope(GuiScaledSkin.scaledSkin) {
    _windowRect = GUILayout.Window(GetInstanceID(), _windowRect, WindowFunc, WindowTitle);
  }
}
See Also