2022-12-31 23:03:26 +01:00
|
|
|
extends Control
|
|
|
|
|
|
|
|
# This script demonstrates how to alter StyleBoxes at runtime.
|
|
|
|
# Custom theme item properties aren't considered Object properties per se.
|
|
|
|
# This means that you should use `add_stylebox_override("normal", ...)`
|
|
|
|
# instead of `set("custom_styles/normal", ...)`.
|
|
|
|
|
|
|
|
onready var label = $VBoxContainer/Label
|
|
|
|
onready var button = $VBoxContainer/Button
|
|
|
|
onready var button2 = $VBoxContainer/Button2
|
|
|
|
onready var reset_all_button = $VBoxContainer/ResetAllButton
|
|
|
|
# Save the label color so it can be reset.
|
2023-04-06 22:00:13 +02:00
|
|
|
onready var default_label_color = label.get_theme_color("font_color")
|
2022-12-31 23:03:26 +01:00
|
|
|
|
|
|
|
func _ready():
|
|
|
|
# Focus the first button automatically for keyboard/controller-friendly navigation.
|
|
|
|
button.grab_focus()
|
|
|
|
|
|
|
|
|
|
|
|
func _on_button_pressed():
|
|
|
|
# We have to modify the normal, hover and pressed styleboxes all at once
|
|
|
|
# to get a correct appearance when the button is hovered or pressed.
|
|
|
|
# We can't use a single StyleBox for all of them as these have different
|
|
|
|
# background colors.
|
2023-04-06 22:00:13 +02:00
|
|
|
var new_stylebox_normal = button.get_theme_stylebox("normal").duplicate()
|
2022-12-31 23:03:26 +01:00
|
|
|
new_stylebox_normal.border_color = Color(1, 1, 0)
|
2023-04-06 22:00:13 +02:00
|
|
|
var new_stylebox_hover = button.get_theme_stylebox("hover").duplicate()
|
2022-12-31 23:03:26 +01:00
|
|
|
new_stylebox_hover.border_color = Color(1, 1, 0)
|
2023-04-06 22:00:13 +02:00
|
|
|
var new_stylebox_pressed = button.get_theme_stylebox("pressed").duplicate()
|
2022-12-31 23:03:26 +01:00
|
|
|
new_stylebox_pressed.border_color = Color(1, 1, 0)
|
|
|
|
|
2023-04-06 22:00:13 +02:00
|
|
|
button.add_theme_stylebox_override("normal", new_stylebox_normal)
|
|
|
|
button.add_theme_stylebox_override("hover", new_stylebox_hover)
|
|
|
|
button.add_theme_stylebox_override("pressed", new_stylebox_pressed)
|
2022-12-31 23:03:26 +01:00
|
|
|
|
2023-04-06 22:00:13 +02:00
|
|
|
label.add_theme_color_override("font_color", Color(1, 1, 0.5))
|
2022-12-31 23:03:26 +01:00
|
|
|
|
|
|
|
|
|
|
|
func _on_button2_pressed():
|
2023-04-06 22:00:13 +02:00
|
|
|
var new_stylebox_normal = button2.get_theme_stylebox("normal").duplicate()
|
2022-12-31 23:03:26 +01:00
|
|
|
new_stylebox_normal.border_color = Color(0, 1, 0.5)
|
2023-04-06 22:00:13 +02:00
|
|
|
var new_stylebox_hover = button2.get_theme_stylebox("hover").duplicate()
|
2022-12-31 23:03:26 +01:00
|
|
|
new_stylebox_hover.border_color = Color(0, 1, 0.5)
|
2023-04-06 22:00:13 +02:00
|
|
|
var new_stylebox_pressed = button2.get_theme_stylebox("pressed").duplicate()
|
2022-12-31 23:03:26 +01:00
|
|
|
new_stylebox_pressed.border_color = Color(0, 1, 0.5)
|
|
|
|
|
2023-04-06 22:00:13 +02:00
|
|
|
button2.add_theme_stylebox_override("normal", new_stylebox_normal)
|
|
|
|
button2.add_theme_stylebox_override("hover", new_stylebox_hover)
|
|
|
|
button2.add_theme_stylebox_override("pressed", new_stylebox_pressed)
|
2022-12-31 23:03:26 +01:00
|
|
|
|
2023-04-06 22:00:13 +02:00
|
|
|
label.add_theme_color_override("font_color", Color(0.5, 1, 0.75))
|
2022-12-31 23:03:26 +01:00
|
|
|
|
|
|
|
|
|
|
|
func _on_reset_all_button_pressed():
|
|
|
|
# Resetting a theme override is done by setting the property to:
|
|
|
|
# - `null` for fonts, icons, styleboxes, and shaders.
|
|
|
|
# - `0` for constants.
|
|
|
|
# - Colors must be reset manually by adding the previous color value as an override.
|
2023-04-06 22:00:13 +02:00
|
|
|
button.add_theme_stylebox_override("normal", null)
|
|
|
|
button.add_theme_stylebox_override("hover", null)
|
|
|
|
button.add_theme_stylebox_override("pressed", null)
|
2022-12-31 23:03:26 +01:00
|
|
|
|
2023-04-06 22:00:13 +02:00
|
|
|
button2.add_theme_stylebox_override("normal", null)
|
|
|
|
button2.add_theme_stylebox_override("hover", null)
|
|
|
|
button2.add_theme_stylebox_override("pressed", null)
|
2022-12-31 23:03:26 +01:00
|
|
|
|
2023-04-06 22:00:13 +02:00
|
|
|
label.add_theme_color_override("font_color", default_label_color)
|