From 907f232c91adf00d72aafb65bef3735142e4dabb Mon Sep 17 00:00:00 2001 From: MewPurPur Date: Fri, 12 Apr 2024 02:44:46 +0300 Subject: [PATCH] Fix BetterLineEdit text selection bug --- src/ui_elements/BetterLineEdit.gd | 17 ++++++---- src/ui_elements/color_field.gd | 6 +--- src/ui_elements/color_field.tscn | 1 - src/ui_elements/enum_field.gd | 5 +-- src/ui_elements/good_color_picker.gd | 24 +++++--------- src/ui_elements/good_color_picker.tscn | 5 --- src/ui_elements/number_field_with_slider.gd | 4 +-- src/ui_elements/number_field_with_slider.tscn | 1 - src/ui_elements/path_command_editor.gd | 31 ++++++++++--------- src/ui_elements/path_command_editor.tscn | 3 -- src/ui_elements/path_field.gd | 10 ++---- src/ui_elements/path_field.tscn | 4 --- src/ui_elements/setting_shortcut.gd | 9 ------ src/ui_parts/alert_dialog.gd | 4 +-- src/ui_parts/alert_dialog.tscn | 2 -- src/ui_parts/good_file_dialog.gd | 19 +++++------- src/ui_parts/import_warning_dialog.gd | 9 ++---- src/ui_parts/import_warning_dialog.tscn | 2 -- 18 files changed, 53 insertions(+), 103 deletions(-) diff --git a/src/ui_elements/BetterLineEdit.gd b/src/ui_elements/BetterLineEdit.gd index 786a1f7b..2b6feaba 100644 --- a/src/ui_elements/BetterLineEdit.gd +++ b/src/ui_elements/BetterLineEdit.gd @@ -9,7 +9,8 @@ const ContextPopup = preload("res://src/ui_elements/context_popup.tscn") var hovered := false -@export var code_font_tooltip := false ## Use the mono font for the tooltip. +## When turned on, uses the mono font for the tooltip. +@export var code_font_tooltip := false func _init() -> void: context_menu_enabled = false @@ -23,11 +24,15 @@ func _ready() -> void: text_submitted.connect(release_focus.unbind(1)) func _input(event: InputEvent) -> void: - if has_focus() and event is InputEventMouseButton: - if event.is_pressed() and not get_global_rect().has_point(event.position): - release_focus() - text_submitted.emit(text) - elif event.is_released() and first_click and not has_selection(): + if has_focus(): + if event is InputEventMouseButton: + if event.is_pressed() and not get_global_rect().has_point(event.position): + release_focus() + text_submitted.emit(text) + elif event.is_released() and first_click and not has_selection(): + first_click = false + select_all() + elif first_click: first_click = false select_all() diff --git a/src/ui_elements/color_field.gd b/src/ui_elements/color_field.gd index ab78537d..582c621b 100644 --- a/src/ui_elements/color_field.gd +++ b/src/ui_elements/color_field.gd @@ -40,6 +40,7 @@ func _ready() -> void: set_value(attribute.get_value()) attribute.value_changed.connect(set_value) color_edit.tooltip_text = attribute_name + color_button.resized.connect(queue_redraw) func _on_button_pressed() -> void: @@ -86,11 +87,6 @@ func is_valid(text: String) -> bool: return ColorParser.is_valid(ColorParser.add_hash_if_hex(text)) -func _on_button_resized() -> void: - # Not sure why this is needed, but the button doesn't have a correct size at first - # which screws with the drawing logic. - queue_redraw() - func _on_text_changed(new_text: String) -> void: color_edit.add_theme_color_override("font_color", GlobalSettings.get_validity_color(!is_valid(new_text))) diff --git a/src/ui_elements/color_field.tscn b/src/ui_elements/color_field.tscn index 6431d6ea..5f16a301 100644 --- a/src/ui_elements/color_field.tscn +++ b/src/ui_elements/color_field.tscn @@ -32,4 +32,3 @@ theme_type_variation = &"LeftConnectedButtonTransparent" [connection signal="text_submitted" from="LineEdit" to="." method="_on_text_submitted"] [connection signal="gui_input" from="Button" to="." method="_on_button_gui_input"] [connection signal="pressed" from="Button" to="." method="_on_button_pressed"] -[connection signal="resized" from="Button" to="." method="_on_button_resized"] diff --git a/src/ui_elements/enum_field.gd b/src/ui_elements/enum_field.gd index 544900e1..938b32f1 100644 --- a/src/ui_elements/enum_field.gd +++ b/src/ui_elements/enum_field.gd @@ -31,7 +31,7 @@ func _on_button_pressed() -> void: var value_picker := ContextPopup.instantiate() var btn_arr: Array[Button] = [] for enum_constant in attribute.possible_values: - var btn := Utils.create_btn(enum_constant, _on_option_pressed.bind(enum_constant), + var btn := Utils.create_btn(enum_constant, set_value.bind(enum_constant), enum_constant == attribute.get_value()) if enum_constant == attribute.default: btn.add_theme_font_override("font", bold_font) @@ -40,9 +40,6 @@ func _on_button_pressed() -> void: value_picker.setup(btn_arr, false, size.x) Utils.popup_under_rect(value_picker, indicator.get_global_rect(), get_viewport()) -func _on_option_pressed(option: String) -> void: - set_value(option) - func _on_focus_entered() -> void: indicator.remove_theme_color_override("font_color") diff --git a/src/ui_elements/good_color_picker.gd b/src/ui_elements/good_color_picker.gd index f76ea9e4..6c2713f5 100644 --- a/src/ui_elements/good_color_picker.gd +++ b/src/ui_elements/good_color_picker.gd @@ -97,7 +97,14 @@ func setup_color(new_color: String) -> void: update() func _ready() -> void: - alpha_slider.visible = alpha_enabled + # Set up signals. + widgets_arr[0].gui_input.connect(parse_slider_input.bind(0, true)) + for i in [1, 2, 3]: + widgets_arr[i].gui_input.connect(parse_slider_input.bind(i)) + if alpha_enabled: + alpha_slider.visible = alpha_enabled + widgets_arr[4].gui_input.connect(parse_slider_input.bind(4)) + # Set up the rest. RenderingServer.canvas_item_set_parent(color_wheel_surface, color_wheel_drawn.get_canvas_item()) @@ -238,21 +245,6 @@ func parse_slider_input(event: InputEvent, idx: int, is_slider_vertical := false elif Utils.is_event_drag_end(event): end_slider_drag(idx) -func _on_side_slider_gui_input(event: InputEvent) -> void: - parse_slider_input(event, 0, true) - -func _on_slider1_gui_input(event: InputEvent) -> void: - parse_slider_input(event, 1) - -func _on_slider2_gui_input(event: InputEvent) -> void: - parse_slider_input(event, 2) - -func _on_slider3_gui_input(event: InputEvent) -> void: - parse_slider_input(event, 3) - -func _on_slider4_gui_input(event: InputEvent) -> void: - parse_slider_input(event, 4) - func _on_slider1_text_submitted(new_text: String) -> void: var new_color := display_color match slider_mode: diff --git a/src/ui_elements/good_color_picker.tscn b/src/ui_elements/good_color_picker.tscn index 750d8ff7..0b43838d 100644 --- a/src/ui_elements/good_color_picker.tscn +++ b/src/ui_elements/good_color_picker.tscn @@ -312,7 +312,6 @@ script = ExtResource("6_aqyoh") [connection signal="gui_input" from="ShapeContainer/ColorWheel" to="." method="_on_color_wheel_gui_input"] [connection signal="draw" from="ShapeContainer/SideSlider" to="." method="_on_side_slider_draw"] -[connection signal="gui_input" from="ShapeContainer/SideSlider" to="." method="_on_side_slider_gui_input"] [connection signal="pressed" from="ColorContainer/NoneButton" to="." method="_on_none_button_pressed"] [connection signal="draw" from="ColorContainer/ColorsDisplay/StartColorRect" to="." method="_on_start_color_rect_draw"] [connection signal="draw" from="ColorContainer/ColorsDisplay/ColorRect" to="." method="_on_color_rect_draw"] @@ -321,18 +320,14 @@ script = ExtResource("6_aqyoh") [connection signal="pressed" from="SliderContainer/ColorSpaceContainer/RGB" to="." method="_on_rgb_pressed"] [connection signal="pressed" from="SliderContainer/ColorSpaceContainer/HSV" to="." method="_on_hsv_pressed"] [connection signal="draw" from="SliderContainer/HBoxContainer/TracksContainer/Slider1/MarginContainer" to="." method="_on_slider1_draw"] -[connection signal="gui_input" from="SliderContainer/HBoxContainer/TracksContainer/Slider1/MarginContainer" to="." method="_on_slider1_gui_input"] [connection signal="resized" from="SliderContainer/HBoxContainer/TracksContainer/Slider1/MarginContainer/ColorTrack" to="." method="_on_track_resized"] [connection signal="text_submitted" from="SliderContainer/HBoxContainer/TracksContainer/Slider1/IntField" to="." method="_on_slider1_text_submitted"] [connection signal="draw" from="SliderContainer/HBoxContainer/TracksContainer/Slider2/MarginContainer" to="." method="_on_slider2_draw"] -[connection signal="gui_input" from="SliderContainer/HBoxContainer/TracksContainer/Slider2/MarginContainer" to="." method="_on_slider2_gui_input"] [connection signal="resized" from="SliderContainer/HBoxContainer/TracksContainer/Slider2/MarginContainer/ColorTrack" to="." method="_on_track_resized"] [connection signal="text_submitted" from="SliderContainer/HBoxContainer/TracksContainer/Slider2/IntField" to="." method="_on_slider2_text_submitted"] [connection signal="draw" from="SliderContainer/HBoxContainer/TracksContainer/Slider3/MarginContainer" to="." method="_on_slider3_draw"] -[connection signal="gui_input" from="SliderContainer/HBoxContainer/TracksContainer/Slider3/MarginContainer" to="." method="_on_slider3_gui_input"] [connection signal="resized" from="SliderContainer/HBoxContainer/TracksContainer/Slider3/MarginContainer/ColorTrack" to="." method="_on_track_resized"] [connection signal="text_submitted" from="SliderContainer/HBoxContainer/TracksContainer/Slider3/IntField" to="." method="_on_slider3_text_submitted"] [connection signal="draw" from="SliderContainer/HBoxContainer/TracksContainer/Slider4/MarginContainer" to="." method="_on_slider4_draw"] -[connection signal="gui_input" from="SliderContainer/HBoxContainer/TracksContainer/Slider4/MarginContainer" to="." method="_on_slider4_gui_input"] [connection signal="resized" from="SliderContainer/HBoxContainer/TracksContainer/Slider4/MarginContainer/ColorTrack" to="." method="_on_track_resized"] [connection signal="text_submitted" from="SliderContainer/HBoxContainer/TracksContainer/Slider4/IntField" to="." method="_on_slider4_text_submitted"] diff --git a/src/ui_elements/number_field_with_slider.gd b/src/ui_elements/number_field_with_slider.gd index cca2f4f3..37e82d11 100644 --- a/src/ui_elements/number_field_with_slider.gd +++ b/src/ui_elements/number_field_with_slider.gd @@ -54,6 +54,7 @@ func _ready() -> void: set_value(attribute.get_value()) attribute.value_changed.connect(set_value) num_edit.tooltip_text = attribute_name + slider.resized.connect(queue_redraw) # Whyyyyy are their sizes wrong at first... func _on_focus_entered() -> void: num_edit.remove_theme_color_override("font_color") @@ -124,9 +125,6 @@ func _draw() -> void: draw_rect(Rect2(0, 1 + slider_size.y - 4 - fill_height, slider_size.x - 2, fill_height), Color("#def8")) -func _on_slider_resized() -> void: - queue_redraw() # Whyyyyy are their sizes wrong at first... - func _on_slider_gui_input(event: InputEvent) -> void: if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_RIGHT and\ event.is_pressed(): diff --git a/src/ui_elements/number_field_with_slider.tscn b/src/ui_elements/number_field_with_slider.tscn index e42e7ba2..55c6fa50 100644 --- a/src/ui_elements/number_field_with_slider.tscn +++ b/src/ui_elements/number_field_with_slider.tscn @@ -34,4 +34,3 @@ keep_pressed_outside = true [connection signal="text_submitted" from="LineEdit" to="." method="_on_text_submitted"] [connection signal="gui_input" from="Slider" to="." method="_on_slider_gui_input"] [connection signal="mouse_exited" from="Slider" to="." method="_on_slider_mouse_exited"] -[connection signal="resized" from="Slider" to="." method="_on_slider_resized"] diff --git a/src/ui_elements/path_command_editor.gd b/src/ui_elements/path_command_editor.gd index bb7d1d7e..a3f33359 100644 --- a/src/ui_elements/path_command_editor.gd +++ b/src/ui_elements/path_command_editor.gd @@ -37,6 +37,8 @@ func _on_relative_button_pressed() -> void: func _ready() -> void: Indications.selection_changed.connect(determine_selection_state) Indications.hover_changed.connect(determine_selection_state) + mouse_entered.connect(_on_mouse_entered) + mouse_exited.connect(_on_mouse_exited) setup() func setup() -> void: @@ -217,6 +219,21 @@ func _on_mouse_entered() -> void: if not active: activate() +func _on_mouse_exited() -> void: + Indications.remove_hovered(tid, cmd_idx) + + if active: + active = false + for field in fields: + if field.has_focus(): + active = true + # Should switch out the controls for fake outs. This is safe even when + # you've focused a BetterLineEdit, because it pauses the tree. + if not active: + clear_children() + queue_redraw() + + func activate() -> void: active = true # Setup the relative button. @@ -308,20 +325,6 @@ func setup_fields(spacings: Array, names: Array) -> void: for i in fields.size() - 1: fields[i + 1].position.x = fields[i].get_end().x + spacings[i] -func _on_mouse_exited() -> void: - Indications.remove_hovered(tid, cmd_idx) - - if active: - active = false - for field in fields: - if field.has_focus(): - active = true - # Should switch out the controls for fake outs. This is safe even when - # you've focused a BetterLineEdit, because it pauses the tree. - if not active: - clear_children() - queue_redraw() - func clear_children() -> void: fields = [] relative_button = null diff --git a/src/ui_elements/path_command_editor.tscn b/src/ui_elements/path_command_editor.tscn index 32d2f641..67de06af 100644 --- a/src/ui_elements/path_command_editor.tscn +++ b/src/ui_elements/path_command_editor.tscn @@ -111,6 +111,3 @@ absolute_button_pressed = SubResource("StyleBoxFlat_sbcff") relative_button_normal = SubResource("StyleBoxFlat_gs8ph") relative_button_hovered = SubResource("StyleBoxFlat_tyaol") relative_button_pressed = SubResource("StyleBoxFlat_cbymw") - -[connection signal="mouse_entered" from="." to="." method="_on_mouse_entered"] -[connection signal="mouse_exited" from="." to="." method="_on_mouse_exited"] diff --git a/src/ui_elements/path_field.gd b/src/ui_elements/path_field.gd index be0c0f0e..a837e5d2 100644 --- a/src/ui_elements/path_field.gd +++ b/src/ui_elements/path_field.gd @@ -26,17 +26,13 @@ func _ready() -> void: set_value(attribute.get_value()) attribute.value_changed.connect(set_value) line_edit.tooltip_text = attribute_name - - -func _on_line_edit_text_submitted(new_text: String) -> void: - set_value(new_text) + add_move.pressed.connect(attribute.insert_command.bind(0, "M")) + line_edit.text_submitted.connect(set_value) + line_edit.focus_entered.connect(_on_line_edit_focus_entered) func _on_line_edit_focus_entered() -> void: focused.emit() -func _on_add_move_pressed() -> void: - attribute.insert_command(0, "M") - func sync(new_value: String) -> void: line_edit.text = new_value # A plus button for adding a move command if empty. diff --git a/src/ui_elements/path_field.tscn b/src/ui_elements/path_field.tscn index d2644d65..820dfe91 100644 --- a/src/ui_elements/path_field.tscn +++ b/src/ui_elements/path_field.tscn @@ -71,7 +71,3 @@ layout_mode = 2 size_flags_horizontal = 3 mouse_filter = 0 theme_override_constants/separation = 0 - -[connection signal="focus_entered" from="LineEdit" to="." method="_on_line_edit_focus_entered"] -[connection signal="text_submitted" from="LineEdit" to="." method="_on_line_edit_text_submitted"] -[connection signal="pressed" from="AddMove" to="." method="_on_add_move_pressed"] diff --git a/src/ui_elements/setting_shortcut.gd b/src/ui_elements/setting_shortcut.gd index 4d5eb0c6..2fa87c94 100644 --- a/src/ui_elements/setting_shortcut.gd +++ b/src/ui_elements/setting_shortcut.gd @@ -77,15 +77,6 @@ func popup_options(idx: int) -> void: get_viewport()) -func _on_edit_button_1_pressed() -> void: - enter_listening_mode(0) - -func _on_edit_button_2_pressed() -> void: - enter_listening_mode(1) - -func _on_edit_button_3_pressed() -> void: - enter_listening_mode(2) - func enter_listening_mode(idx: int) -> void: listening_idx = idx var btn := shortcut_buttons[idx] diff --git a/src/ui_parts/alert_dialog.gd b/src/ui_parts/alert_dialog.gd index e09813f5..76f58a9e 100644 --- a/src/ui_parts/alert_dialog.gd +++ b/src/ui_parts/alert_dialog.gd @@ -5,12 +5,10 @@ extends PanelContainer @onready var ok_button: Button = %MainContainer/OKButton func _ready() -> void: + ok_button.pressed.connect(queue_free) ok_button.grab_focus() func setup(message: String, title_text := "Alert!", min_width := 180.0) -> void: label.text = tr(message) title.text = tr(title_text) label.custom_minimum_size.x = min_width - -func _on_ok_button_pressed() -> void: - queue_free() diff --git a/src/ui_parts/alert_dialog.tscn b/src/ui_parts/alert_dialog.tscn index 9e08d5f0..56098028 100644 --- a/src/ui_parts/alert_dialog.tscn +++ b/src/ui_parts/alert_dialog.tscn @@ -44,5 +44,3 @@ layout_mode = 2 size_flags_horizontal = 4 mouse_default_cursor_shape = 2 text = "OK" - -[connection signal="pressed" from="MainContainer/OKButton" to="." method="_on_ok_button_pressed"] diff --git a/src/ui_parts/good_file_dialog.gd b/src/ui_parts/good_file_dialog.gd index 4315b68e..6e4d726b 100644 --- a/src/ui_parts/good_file_dialog.gd +++ b/src/ui_parts/good_file_dialog.gd @@ -77,8 +77,15 @@ new_extension: String) -> void: mode = new_mode extension = new_extension + func _ready() -> void: + # Signal connections. + close_button.pressed.connect(queue_free) + file_selected.connect(queue_free.unbind(1)) + special_button.pressed.connect(select_file) + alert_cancel_button.pressed.connect(center_container.hide) file_list.get_v_scroll_bar().value_changed.connect(_setup_file_images.unbind(1)) + # Rest of setup. if mode == FileMode.SELECT: file_container.hide() if mode == FileMode.SAVE: @@ -257,15 +264,6 @@ func _on_search_button_toggled(toggled_on: bool) -> void: set_dir(current_dir) -func _on_close_button_pressed() -> void: - queue_free() - -func _on_file_selected(_path: String) -> void: - queue_free() - -func _on_special_button_pressed() -> void: - select_file() - func _on_file_field_text_submitted(new_text: String) -> void: file_field.remove_theme_color_override("font_color") if new_text.is_valid_filename(): @@ -300,8 +298,5 @@ func _on_file_field_text_changed(new_text: String) -> void: GlobalSettings.get_validity_color(is_invalid_filename)) -func _on_alert_cancel_button_pressed() -> void: - center_container.hide() - func _on_alert_replace_button_pressed() -> void: file_selected.emit(current_dir.path_join(current_file)) diff --git a/src/ui_parts/import_warning_dialog.gd b/src/ui_parts/import_warning_dialog.gd index b122e2e7..75351e07 100644 --- a/src/ui_parts/import_warning_dialog.gd +++ b/src/ui_parts/import_warning_dialog.gd @@ -6,6 +6,7 @@ signal imported @onready var texture_preview: CenterContainer = %TexturePreview @onready var ok_button: Button = %ButtonContainer/OKButton @onready var margin_container: MarginContainer = %MarginContainer +@onready var cancel_button: Button = $VBoxContainer/ButtonContainer/CancelButton var imported_text := "" @@ -36,6 +37,8 @@ func _ready() -> void: GlobalSettings.basic_color_warning) for warning in svg_warnings: warnings_label.text += warning + "\n" + imported.connect(queue_free) + cancel_button.pressed.connect(queue_free) func set_svg(text: String) -> void: @@ -55,11 +58,5 @@ func get_svg_warnings(svg_tag: TagSVG) -> Array[String]: return warnings -func _on_cancel_button_pressed() -> void: - queue_free() - func _on_ok_button_pressed() -> void: imported.emit() - -func _on_imported() -> void: - queue_free() diff --git a/src/ui_parts/import_warning_dialog.tscn b/src/ui_parts/import_warning_dialog.tscn index f8a69754..4d45b33d 100644 --- a/src/ui_parts/import_warning_dialog.tscn +++ b/src/ui_parts/import_warning_dialog.tscn @@ -79,6 +79,4 @@ size_flags_horizontal = 6 mouse_default_cursor_shape = 2 text = "Import" -[connection signal="imported" from="." to="." method="_on_imported"] -[connection signal="pressed" from="VBoxContainer/ButtonContainer/CancelButton" to="." method="_on_cancel_button_pressed"] [connection signal="pressed" from="VBoxContainer/ButtonContainer/OKButton" to="." method="_on_ok_button_pressed"]