From 926714b020a89f7a2b4db00a23156bce3e54ff9e Mon Sep 17 00:00:00 2001 From: rom Date: Mon, 26 Apr 2021 00:25:07 +0200 Subject: revert buttons --- components/button.gd | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'components') diff --git a/components/button.gd b/components/button.gd index 45a3f4f..734e048 100644 --- a/components/button.gd +++ b/components/button.gd @@ -1,6 +1,6 @@ extends Node2D class_name ButtonTest -export var text = "Hello, Button" setget _text +export var text = "Hello, Button" # Force a fixed width if != -1 export var fixed_width = -1 signal on_click() @@ -30,23 +30,13 @@ const right_nohover = preload("res://textures/components/button/right.png") const right_hover = preload("res://textures/components/button/right_hover.png") const right_press = preload("res://textures/components/button/right_press.png") -onready var label = Label.new() +var label func _ready(): + label = Label.new() + label.text = text label.theme = theme add_child(label) - _text_changed() - -func _text(value): - text = value - if label == null: - return - _text_changed() - -func _text_changed(): - label.text = "" - label.rect_size = Vector2(0,0) - label.text = text label.rect_position = -label.rect_size / 2 var width = label.rect_size.x if fixed_width > 0: @@ -57,8 +47,8 @@ func _text_changed(): hitbox.shape = RectangleShape2D.new() hitbox.shape.extents.y = 32 hitbox.shape.extents.x = right.position.x + right.scale.x * BASE_WIDTH / 2 - update() - label.update() + + func _on_ButtonTest_input_event(viewport, event, shape_idx): if not (event is InputEventMouseButton): -- cgit