Disclosure: I make these and sell them: this book, Godot 4.x UI Theming Cookbook, $9.99 (sold by Fortress MSSP LLC).
Primary and secondary Buttons can share one Theme if you define each as a theme type variation. Here is how recipe 2 of the Godot 4.x UI Theming Cookbook does it in GDScript: the script builds a Theme in code, registers two variation names, and the Button nodes only pick a name.
1. Names and theme. Two constants name the variations (PRIMARY_BUTTON, SECONDARY_BUTTON). _ready() builds a Theme in code and assigns it to the Control’s theme property.
2. Register each name as a variation of Button:
t.set_type_variation(PRIMARY_BUTTON, "Button")
t.set_type_variation(SECONDARY_BUTTON, "Button")
3. Fill in each variation with one helper. configure_button_variation takes the Theme, a variation name and six colors. It sets five font colors and five StyleBoxes under that name, for the normal, hover, pressed, disabled and focus slots:
t.set_stylebox("normal", variation_name, pill_box(normal_bg, border, 1))
t.set_stylebox("hover", variation_name, pill_box(hover_bg, border, 1))
t.set_stylebox("pressed", variation_name, pill_box(pressed_bg, border, 1))
t.set_stylebox("disabled", variation_name, pill_box(Color(0.10, 0.11, 0.14), Color(0.20, 0.22, 0.28), 1))
t.set_stylebox("focus", variation_name, focus_box(Color(0.78, 0.86, 1.0)))
The script calls the helper twice, once per variation, with different color values.
4. The Buttons only name the variation. In build_demo_buttons() each Button sets its text, size and position and theme_type_variation. None of them sets colors or StyleBoxes itself:
primary.theme_type_variation = PRIMARY_BUTTON
The secondary Button does the same with SECONDARY_BUTTON. The demo also adds a disabled primary Button that uses the same variation with disabled = true.
These excerpts are copied unchanged from the recipe’s snippet, and they have not been tested in the Godot editor. In the book, the recipe has the complete snippet, then explains how it works, suggests variations and lists common pitfalls.
What it is. A text-and-code ebook for developers who want a searchable reference for styling Godot Control UI with themes and GDScript. It has 10 recipes. Each one starts from a practical UI-theming problem, lists the Godot classes and APIs it uses, gives a complete GDScript snippet, then explains how it works, suggests variations and lists common pitfalls. Recipe 2 is “Use theme type variations for primary and secondary Buttons.”
Format. A 33-page PDF, an EPUB version of the same book, and the 10 snippets as separate .gd files, in one zip.
Code-only by design. The recipes build their styles in GDScript, so the book ships no reusable UI art, HUD assets, icon files, font files or scene/source asset packs.
Limits:
- All 10 GDScript snippets were loaded and run headless with
godot --headlesson Godot 4.7.2.stable. 10 of 10 produced no script errors and exit code 0. - This does not check how the snippets look, because headless mode has no renderer.
- The snippets were not tested in the Godot editor, so check them in the exact Godot version you ship.
- The test harness and a README with the run commands are in the download, so you can repeat the check yourself.
- Godot and other product names belong to their respective owners; this book is not affiliated with or endorsed by them.