-
Notifications
You must be signed in to change notification settings - Fork 0
tutorial_gui_skinning
This tutorial is about advanced skinning of an user interface. Most games generally don't need this, as they end up just relying on Label, TextureFrame, TextureButton and TextureProgress.
However, many types of games often need complex user interfaces, like MMOs, traditional RPGs, Simulators, Strategy, etc. These kind of interfaces are also common in some games that include editors to create content, or interfaces for network connectivity.
Godot user interface uses these kind of controls with the default theme, but they can be skinned to resemble pretty much any kind of user interface.
The GUI is skinned through the Theme resource. Theme contains all the information required to change the entire visual styling of all controls. Theme options are named, so it's not obvious which name changes what (specialy from code), but several tools are provided. The ultimate place to look at what each theme option is for each control, which will always be more up to date than any documentation is the file default_theme.cpp. The rest of this document will explain the different tools used to customize the theme.
A Theme can be applied to any control in the scene. As a result, all children and grand-children controls will use that same theme too (unless another theme is specified further down the tree). If a value is not found in a theme, it will be searched in themes higher up in the hierarchy towards the root. If nothing was found, the default theme is used. This system allows for flexible overriding of themes in complex user interfaces.
Each kind of option in a theme can be:
- An integer constant: A single numerical constant. Generally used to define spacing between compoments or alignment.
- A Color: A single color, with or without transparency. Colors are usually applied to fonts and icons.
- A Texture: A single image. Textures are not often used, but when they are they represent handles to pick or icons in a complex control (such as file dialog).
- A Font: Every control that uses text can be assigned the fonts used to draw strings.
- A StyleBox: Stylebox is a resource that defines how to draw a panel in varying sizes (more information on them later).
Every option is associated to:
- A name (the name of the option)
- A Control (the name of the control)
An example usage:
var t = Theme.new()
t.set_color("font_color","Label",Color(1.0,1.0,1.0))
var l = Label.new()
l.set_theme(t)
In the example above, a new theme is created. The "font_color" option is changed and then applied to a label. As a result, the label (and all children and grand children labels) will use that color.
It is possible to override those options without using the theme directly and only for a specific control by using the override API in Control:
var l = Label.new()
l.add_color_override("font_color",Color(1.0,1.0,1.0))