Skip to content

Instantly share code, notes, and snippets.

@Shilo
Last active October 5, 2024 10:59
Show Gist options
  • Save Shilo/cdc3edc9256dd20f11cd79091c563e71 to your computer and use it in GitHub Desktop.
Save Shilo/cdc3edc9256dd20f11cd79091c563e71 to your computer and use it in GitHub Desktop.
Godot toggle button for toggle state icon.
@tool
class_name ToggleButton extends Button
@export var icon_toggled: Texture2D
@onready var _icon: Texture2D = icon
func _ready() -> void:
toggle_mode = true
if not theme_type_variation:
theme_type_variation = &"ToggleButton"
func _toggled(toggled_on: bool) -> void:
icon = icon_toggled if toggled_on and icon_toggled else _icon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment