Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix BetterLineEdit text selection bug #650

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/ui_elements/BetterLineEdit.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

Expand Down
6 changes: 1 addition & 5 deletions src/ui_elements/color_field.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)))
Expand Down
1 change: 0 additions & 1 deletion src/ui_elements/color_field.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
5 changes: 1 addition & 4 deletions src/ui_elements/enum_field.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand Down
24 changes: 8 additions & 16 deletions src/ui_elements/good_color_picker.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down Expand Up @@ -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:
Expand Down
5 changes: 0 additions & 5 deletions src/ui_elements/good_color_picker.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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"]
4 changes: 1 addition & 3 deletions src/ui_elements/number_field_with_slider.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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():
Expand Down
1 change: 0 additions & 1 deletion src/ui_elements/number_field_with_slider.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
31 changes: 17 additions & 14 deletions src/ui_elements/path_command_editor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions src/ui_elements/path_command_editor.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
10 changes: 3 additions & 7 deletions src/ui_elements/path_field.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 0 additions & 4 deletions src/ui_elements/path_field.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
9 changes: 0 additions & 9 deletions src/ui_elements/setting_shortcut.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 1 addition & 3 deletions src/ui_parts/alert_dialog.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 0 additions & 2 deletions src/ui_parts/alert_dialog.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
19 changes: 7 additions & 12 deletions src/ui_parts/good_file_dialog.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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))
9 changes: 3 additions & 6 deletions src/ui_parts/import_warning_dialog.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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 := ""

Expand Down Expand Up @@ -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:
Expand All @@ -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()
2 changes: 0 additions & 2 deletions src/ui_parts/import_warning_dialog.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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"]