57 lines
2 KiB
GDScript
57 lines
2 KiB
GDScript
@tool
|
|
extends SuiBaseClass
|
|
|
|
@export_category("Base Configuration")
|
|
@export_subgroup("Button")
|
|
## Makes the button unable to be interacted with.
|
|
@export var disabled: bool = false
|
|
## Makes the button toggleable.
|
|
@export var toggle_mode: bool = false
|
|
## Forwarded from the internal [Button]. Will be overriden with the internal button's value, any changes to this variable will not be reflected.
|
|
@export var button_pressed: bool = false
|
|
@export_subgroup("RichTextLabel")
|
|
## Enables support for BBCode.
|
|
@export var bbcode_support: bool = true
|
|
## The text you want to display.
|
|
@export_multiline var text: String = "[center]SuiTextButton[/center]"
|
|
## The size your text should have.
|
|
@export var font_size: int = 35
|
|
|
|
## Emitted when the button is pressed.
|
|
signal down
|
|
## Emitted when the button is released.
|
|
signal up
|
|
## Emitted when the button has been pressed.
|
|
signal pressed
|
|
## Emitted when the button has been toggled.
|
|
signal toggled
|
|
|
|
func _ready() -> void:
|
|
super()
|
|
if !in_editor():
|
|
$Button.connect("button_down", func() -> void: emit_signal("down"))
|
|
$Button.connect("button_up", func() -> void: emit_signal("up"))
|
|
$Button.connect("pressed", func() -> void: emit_signal("pressed"))
|
|
$Button.connect("toggled", func(toggled_on: bool) -> void: emit_signal("toggled", toggled_on))
|
|
|
|
func update_element() -> void:
|
|
# Update sizes
|
|
$Button.size = size
|
|
$Text.size = size
|
|
|
|
# Update Button stuff
|
|
$Button.disabled = disabled
|
|
$Button.toggle_mode = toggle_mode
|
|
button_pressed = $Button.button_pressed
|
|
|
|
# Update RichTextLabel stuff
|
|
$Text.bbcode_enabled = bbcode_support
|
|
$Text.text = text
|
|
$Text.add_theme_font_size_override("normal_font_size", font_size)
|
|
$Text.add_theme_font_size_override("bold_font_size", font_size)
|
|
$Text.add_theme_font_size_override("italics_font_size", font_size)
|
|
$Text.add_theme_font_size_override("bold_italics_font_size", font_size)
|
|
$Text.add_theme_font_size_override("mono_font_size", font_size)
|
|
|
|
func update_pressed_state(is_pressed: bool) -> void:
|
|
$Button.button_pressed = is_pressed
|