Skip to content

Commit 56deebd

Browse files
authored
Fix pathdata and points editor focus nav, other improvements (#1784)
1 parent cc2ae5b commit 56deebd

11 files changed

Lines changed: 278 additions & 167 deletions

File tree

assets/icons/Visuals.svg

Lines changed: 1 addition & 1 deletion
Loading

src/autoload/HandlerGUI.gd

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,20 +215,20 @@ func _remove_control(overlay_ref: ColorRect = null) -> void:
215215
return
216216

217217
overlay_ref = menu_stack.pop_at(matching_idx)
218+
overlay_ref.tree_exited.connect(menus_or_popups_cleared.emit)
218219
# If a visible control gets removed, unhide the previous one.
219220
if overlay_ref.visible and matching_idx >= 1:
220221
menu_stack[matching_idx - 1].show()
221222
if is_instance_valid(overlay_ref):
222223
overlay_ref.queue_free()
223-
menus_or_popups_cleared.emit()
224224
throw_mouse_motion_event()
225225

226226
## Frees all nodes in the menu_stack, emptying it.
227227
func remove_all_menus() -> void:
228228
if not menu_stack.is_empty():
229+
menu_stack[0].tree_exited.connect(menus_or_popups_cleared.emit)
229230
while not menu_stack.is_empty():
230231
menu_stack.pop_back().queue_free()
231-
menus_or_popups_cleared.emit()
232232
throw_mouse_motion_event()
233233

234234

@@ -294,16 +294,16 @@ func remove_popup(overlay_ref: Control = null) -> void:
294294
return
295295

296296
overlay_ref = popup_stack.pop_at(matching_idx)
297+
overlay_ref.tree_exited.connect(menus_or_popups_cleared.emit)
297298
if is_instance_valid(overlay_ref):
298299
overlay_ref.queue_free()
299-
menus_or_popups_cleared.emit()
300300
throw_mouse_motion_event()
301301

302302
func remove_all_popups() -> void:
303303
if not popup_stack.is_empty():
304+
popup_stack[0].tree_exited.connect(menus_or_popups_cleared.emit)
304305
while not popup_stack.is_empty():
305306
popup_stack.pop_back().queue_free()
306-
menus_or_popups_cleared.emit()
307307
throw_mouse_motion_event()
308308

309309

@@ -445,6 +445,10 @@ func _input(event: InputEvent) -> void:
445445
get_viewport().set_input_as_handled()
446446
if not focus_owner.has_focus(true):
447447
focus_owner.grab_focus()
448+
if focus_owner.has_user_signal("visible_focus_changed"):
449+
focus_owner.emit_signal("visible_focus_changed")
450+
elif focus_owner.has_signal("visible_focus_changed"):
451+
focus_owner.visible_focus_changed.emit()
448452
else:
449453
gather_focus(focus_owner, false).grab_focus()
450454
elif ShortcutUtils.is_action_pressed(event, "ui_accept", true):
@@ -552,7 +556,7 @@ func _gather_focus_internal(control: Control, is_next: bool) -> Control:
552556

553557

554558
func is_node_on_top_menu_or_popup(node: Node) -> bool:
555-
return ((menu_stack.is_empty() and popup_stack.is_empty()) or (popup_stack.is_empty() and\
559+
return is_instance_valid(node) and ((menu_stack.is_empty() and popup_stack.is_empty()) or (popup_stack.is_empty() and\
556560
menu_stack[-1].is_ancestor_of(node)) or (not popup_stack.is_empty() and not is_instance_valid(popup_submenu) and\
557561
popup_stack[-1].is_ancestor_of(node)) or (is_instance_valid(popup_submenu) and popup_submenu.is_ancestor_of(node)))
558562

src/data_classes/DB.gd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ const _ELEMENT_ICONS: Dictionary[String, Texture2D] = {
1515
"rect": preload("res://assets/icons/element/rect.svg"),
1616
"path": preload("res://assets/icons/element/path.svg"),
1717
"line": preload("res://assets/icons/element/line.svg"),
18-
"polygon": preload("res://assets/icons/element/polygon.svg"),
19-
"polyline": preload("res://assets/icons/element/polyline.svg"),
18+
"polygon": preload("res://assets/icons/element/polygon.svg"),
19+
"polyline": preload("res://assets/icons/element/polyline.svg"),
2020
"svg": preload("res://assets/icons/element/svg.svg"),
2121
"g": preload("res://assets/icons/element/g.svg"),
2222
"linearGradient": preload("res://assets/icons/element/linearGradient.svg"),

src/shaders/slider_visuals.gdshader

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ void fragment() {
4848
vec2 dir = normalize(base_color.rgb * 2.0 - 1.0).xy;
4949
float len = length(dir);
5050
if (len > 0.00001) {
51-
dir /= len;
51+
dir /= len;
5252
} else {
53-
dir = vec2(0.0);
53+
dir = vec2(0.0);
5454
}
5555
vec2 xy = dir * offset;
5656
COLOR = vec4(vec3(xy, sqrt(max(0.0, 1.0 - dot(xy, xy)))) * 0.5 + 0.5, 1.0);

src/ui_parts/tab_bar.gd

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ func _gui_input(event: InputEvent) -> void:
223223
btn_arr.append(ContextButton.create_from_action("new_tab"))
224224
else:
225225
var new_active_tab := Configs.savedata.get_tab(hovered_idx)
226-
var file_absent := not FileAccess.file_exists(new_active_tab.svg_file_path)
226+
var external_file_missing := not FileAccess.file_exists(new_active_tab.svg_file_path)
227227
var tab_count := Configs.savedata.get_tab_count()
228228

229229
var has_empty_tabs := false
@@ -246,10 +246,13 @@ func _gui_input(event: InputEvent) -> void:
246246
func() -> ContextButton: return ContextButton.create_from_action("close_empty_tabs", not has_empty_tabs).set_icon_none(),
247247
func() -> ContextButton: return ContextButton.create_from_action("close_saved_tabs", not has_saved_tabs).set_icon_none(),
248248
]))
249-
btn_arr.append(ContextButton.create_from_action("open_externally", file_absent))
250-
btn_arr.append(ContextButton.create_from_action("open_in_folder", file_absent))
249+
btn_arr.append(ContextButton.create_from_action("save"))
250+
btn_arr.append(ContextButton.create_from_action("save_as").add_custom_text(Translator.translate("Save SVG as…")))
251+
btn_arr.append(ContextButton.create_from_action("reset_svg", FileUtils.compare_svg_to_disk_contents() != FileUtils.FileState.DIFFERENT))
252+
btn_arr.append(ContextButton.create_from_action("open_externally", external_file_missing))
253+
btn_arr.append(ContextButton.create_from_action("open_in_folder", external_file_missing))
251254

252-
var tab_popup := ContextPopup.create(btn_arr, true, -1, PackedInt32Array([6]))
255+
var tab_popup := ContextPopup.create(btn_arr, true, -1, PackedInt32Array([2, 5]))
253256
if hovered_idx != -1:
254257
var tab_global_rect := get_tab_rect(hovered_idx)
255258
tab_global_rect.position += get_global_rect().position

src/ui_widgets/BetterLineEdit.gd

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ var ci := get_canvas_item()
66

77
## Emitted when Esc is pressed to cancel the current text change.
88
signal text_change_canceled
9+
@warning_ignore("unused_signal")
10+
signal visible_focus_changed
911

1012
## When turned on, uses the mono font for the tooltip.
1113
@export var mono_font_tooltip := false
@@ -57,7 +59,6 @@ func _on_base_class_editing_toggled(toggled_on: bool) -> void:
5759
if get_global_rect().has_point(get_viewport().get_mouse_position()) and Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT):
5860
first_click = true
5961
text_before_edit = text
60-
grab_focus()
6162
if not first_click:
6263
select_all()
6364
else:
@@ -156,7 +157,9 @@ func _gui_input(event: InputEvent) -> void:
156157
if event is InputEventMouseMotion and event.button_mask == 0:
157158
queue_redraw()
158159
elif event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_RIGHT and event.is_pressed():
159-
grab_focus()
160+
if not has_focus(true):
161+
grab_focus()
162+
visible_focus_changed.emit()
160163
var btn_arr: Array[ContextButton] = []
161164
var separator_arr := PackedInt32Array()
162165

@@ -189,6 +192,10 @@ func _gui_input(event: InputEvent) -> void:
189192
# Wow, no way to find out the column of a given click? Okay...
190193
# TODO Make it so LineEdit caret automatically moves to the clicked position to finish the right-click logic.
191194
elif event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.is_pressed():
192-
grab_focus(not has_focus())
195+
if has_focus():
196+
grab_focus()
197+
visible_focus_changed.emit()
198+
else:
199+
grab_focus(true)
193200
if not editable:
194201
editing_toggled.emit(true)

src/ui_widgets/BetterTextEdit.gd

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ func _line_number_draw_callback(line: int, _gutter: int, region: Rect2) -> void:
6262
# Center vertically, align to the left of the gutter.
6363
var text_pos := Vector2(-5, region.get_center().y + font.get_ascent(font_size) - font.get_string_size(
6464
line_number_text, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size).y / 2)
65-
draw_string(font, text_pos, line_number_text, HORIZONTAL_ALIGNMENT_RIGHT, _line_gutter_needed_space, font_size, ThemeUtils.dimmer_text_color)
65+
draw_string(font, text_pos, line_number_text, HORIZONTAL_ALIGNMENT_RIGHT, _line_gutter_needed_space, font_size,
66+
ThemeUtils.dim_text_color if (get_caret_line() == line and has_focus()) else ThemeUtils.subtle_text_color)
6667

6768

6869
func _exit_tree() -> void:
@@ -201,42 +202,55 @@ func _gui_input(event: InputEvent) -> void:
201202

202203
if event is InputEventMouseMotion and event.button_mask == 0:
203204
queue_redraw()
204-
elif event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_RIGHT and event.is_pressed():
205-
grab_focus()
206-
var btn_arr: Array[ContextButton] = []
207-
var separator_arr := PackedInt32Array()
208-
209-
var is_text_empty := text.is_empty()
210-
211-
if editable:
212-
var text_to_evaluate := get_selected_text() if has_selection() else text
213-
var selection_evaluation := NumstringParser.evaluate(text_to_evaluate)
214-
if not is_nan(selection_evaluation) and Utils.num_simple(selection_evaluation, Utils.MAX_NUMERIC_PRECISION) != text_to_evaluate:
215-
btn_arr.append(ContextButton.create_from_action("evaluate"))
205+
elif event is InputEventMouseButton and event.is_pressed():
206+
if get_gutter_count() == 1 and event.position.x < get_gutter_width(0):
207+
if event.button_index in [MOUSE_BUTTON_LEFT, MOUSE_BUTTON_MIDDLE, MOUSE_BUTTON_RIGHT]:
208+
grab_focus()
209+
var click_line := get_line_column_at_pos(event.position).y
210+
if event.alt_pressed:
211+
add_caret(click_line, 0)
212+
else:
213+
remove_secondary_carets()
214+
deselect()
215+
set_caret_line(click_line)
216+
set_caret_column(0)
217+
accept_event()
218+
if event.button_index == MOUSE_BUTTON_RIGHT:
219+
grab_focus()
220+
var btn_arr: Array[ContextButton] = []
221+
var separator_arr := PackedInt32Array()
216222

217-
if not btn_arr.is_empty():
218-
separator_arr.append(btn_arr.size())
223+
var is_text_empty := text.is_empty()
219224

220-
btn_arr.append(ContextButton.create_from_action("ui_undo", not has_undo()))
221-
btn_arr.append(ContextButton.create_from_action("ui_redo", not has_redo()))
222-
if DisplayServer.has_feature(DisplayServer.FEATURE_CLIPBOARD):
223-
separator_arr.append(btn_arr.size())
224-
btn_arr.append(ContextButton.create_from_action("ui_cut", is_text_empty))
225+
if editable:
226+
var text_to_evaluate := get_selected_text() if has_selection() else text
227+
var selection_evaluation := NumstringParser.evaluate(text_to_evaluate)
228+
if not is_nan(selection_evaluation) and Utils.num_simple(selection_evaluation, Utils.MAX_NUMERIC_PRECISION) != text_to_evaluate:
229+
btn_arr.append(ContextButton.create_from_action("evaluate"))
230+
231+
if not btn_arr.is_empty():
232+
separator_arr.append(btn_arr.size())
233+
234+
btn_arr.append(ContextButton.create_from_action("ui_undo", not has_undo()))
235+
btn_arr.append(ContextButton.create_from_action("ui_redo", not has_redo()))
236+
if DisplayServer.has_feature(DisplayServer.FEATURE_CLIPBOARD):
237+
separator_arr.append(btn_arr.size())
238+
btn_arr.append(ContextButton.create_from_action("ui_cut", is_text_empty))
239+
btn_arr.append(ContextButton.create_from_action("ui_copy", is_text_empty))
240+
btn_arr.append(ContextButton.create_from_action("ui_paste", not Utils.has_clipboard_web_safe()))
241+
btn_arr.append(ContextButton.create_from_action("select_all", is_text_empty))
242+
else:
225243
btn_arr.append(ContextButton.create_from_action("ui_copy", is_text_empty))
226-
btn_arr.append(ContextButton.create_from_action("ui_paste", not Utils.has_clipboard_web_safe()))
227244
btn_arr.append(ContextButton.create_from_action("select_all", is_text_empty))
228-
else:
229-
btn_arr.append(ContextButton.create_from_action("ui_copy", is_text_empty))
230-
btn_arr.append(ContextButton.create_from_action("select_all", is_text_empty))
231-
232-
var vp := get_viewport()
233-
HandlerGUI.popup_under_pos(ContextPopup.create(btn_arr, true, -1, separator_arr), vp.get_mouse_position(), vp)
234-
accept_event()
235-
var click_pos := get_line_column_at_pos(event.position)
236-
if get_selection_at_line_column(click_pos.y, click_pos.x) == -1:
237-
deselect()
238-
set_caret_line(click_pos.y, false)
239-
set_caret_column(click_pos.x, false)
245+
246+
var vp := get_viewport()
247+
HandlerGUI.popup_under_pos(ContextPopup.create(btn_arr, true, -1, separator_arr), vp.get_mouse_position(), vp)
248+
accept_event()
249+
var click_pos := get_line_column_at_pos(event.position)
250+
if get_selection_at_line_column(click_pos.y, click_pos.x) == -1:
251+
deselect()
252+
set_caret_line(click_pos.y, false)
253+
set_caret_column(click_pos.x, false)
240254
else:
241255
# Set these inputs as handled, so the default UndoRedo doesn't eat them.
242256
if ShortcutUtils.is_action_pressed(event, "ui_undo"):

src/ui_widgets/good_color_picker.tscn

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,8 @@ shader_parameter/inverted = false
5151
shader_parameter/interpolation = 0
5252

5353
[node name="GoodColorPicker" type="MarginContainer" unique_id=2024296627]
54-
offset_top = 347.0
55-
offset_right = 200.0
56-
offset_bottom = 347.0
54+
offset_right = 212.0
55+
offset_bottom = 353.0
5756
theme_override_constants/margin_left = 6
5857
theme_override_constants/margin_top = 6
5958
theme_override_constants/margin_right = 6

src/ui_widgets/handles_manager.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ func _draw() -> void:
331331
for i in range(270, 360):
332332
var d := i * TAU/360
333333
points[i - 268] = Vector2(x + rect_width - rx, y + ry) + Vector2(cos(d) * rx, sin(d) * ry)
334-
points[92] = Vector2(x + rect_width, y + rect_height - ry)
334+
points[92] = Vector2(x + rect_width, y + rect_height - ry)
335335
for i in range(0, 90):
336336
var d := i * TAU/360
337337
points[i + 93] = Vector2(x + rect_width - rx, y + rect_height - ry) + Vector2(cos(d) * rx, sin(d) * ry)

0 commit comments

Comments
 (0)