Skip to content

Commit e6bde85

Browse files
authored
Android hover fixes (#1798)
1 parent 3071f61 commit e6bde85

6 files changed

Lines changed: 107 additions & 106 deletions

File tree

src/ui_parts/previews.gd

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -223,24 +223,25 @@ func _on_preview_tiles_draw() -> void:
223223

224224

225225
func _on_tiles_gui_input(event: InputEvent) -> void:
226-
if event is InputEventMouseMotion:
227-
set_hovered_to_pos(event.position)
228-
elif event is InputEventMouseButton:
229-
if event.is_pressed():
230-
if event.button_index == MOUSE_BUTTON_LEFT:
231-
_select_tile(hovered_tile_index)
232-
elif event.button_index == MOUSE_BUTTON_RIGHT:
233-
if hovered_tile_index >= 0:
234-
for tile in tiles:
235-
if Rect2(tile.position, tile.size).has_point(event.position):
236-
_show_tile_popup_at_pos(tile, event.global_position)
237-
break
238-
else:
239-
var btn_array: Array[ContextButton] = [
240-
ContextButton.create_custom(Translator.translate("Add preview"), _add_new_tile, preload("res://assets/icons/Plus.svg"))
241-
]
242-
var vp := get_viewport()
243-
HandlerGUI.popup_under_pos(ContextPopup.create(btn_array), vp.get_mouse_position(), vp)
226+
if not event is InputEventMouse:
227+
return
228+
set_hovered_to_pos(event.position)
229+
230+
if event is InputEventMouseButton and event.is_pressed():
231+
if event.button_index == MOUSE_BUTTON_LEFT:
232+
_select_tile(hovered_tile_index)
233+
elif event.button_index == MOUSE_BUTTON_RIGHT:
234+
if hovered_tile_index >= 0:
235+
for tile in tiles:
236+
if Rect2(tile.position, tile.size).has_point(event.position):
237+
_show_tile_popup_at_pos(tile, event.global_position)
238+
break
239+
else:
240+
var btn_array: Array[ContextButton] = [
241+
ContextButton.create_custom(Translator.translate("Add preview"), _add_new_tile, preload("res://assets/icons/Plus.svg"))
242+
]
243+
var vp := get_viewport()
244+
HandlerGUI.popup_under_pos(ContextPopup.create(btn_array), vp.get_mouse_position(), vp)
244245

245246
func _on_tiles_mouse_exited() -> void:
246247
hovered_tile_index = -1

src/ui_parts/tab_bar.gd

Lines changed: 84 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -175,100 +175,101 @@ func _draw() -> void:
175175
x_pos = get_tab_rect(proposed_drop_idx).position.x
176176
draw_line(Vector2(x_pos, 0), Vector2(x_pos, size.y), Configs.savedata.basic_color_valid, 4)
177177

178-
179178
func _gui_input(event: InputEvent) -> void:
180179
super(event)
181180
if not event is InputEventMouse:
182181
return
183182

184183
queue_redraw()
185-
if event is InputEventMouseButton:
186-
if event.is_pressed():
187-
if event.button_index in [MOUSE_BUTTON_WHEEL_UP, MOUSE_BUTTON_WHEEL_LEFT]:
188-
scroll_backwards(event.factor)
189-
if event.button_index in [MOUSE_BUTTON_WHEEL_DOWN, MOUSE_BUTTON_WHEEL_RIGHT]:
190-
scroll_forwards(event.factor)
191-
elif event.button_index in [MOUSE_BUTTON_LEFT, MOUSE_BUTTON_RIGHT]:
192-
var hovered_idx := get_hovered_index()
193-
if hovered_idx != -1:
194-
if hovered_idx == Configs.savedata.get_active_tab_index():
195-
scroll_to_active()
196-
else:
197-
# Give time for deferred callbacks that might change the active SVG. For example, the code editor
198-
# might get unfocused by clicking on a tab, changing the SVG, so this should be deferred.
199-
Configs.savedata.set_active_tab_index.call_deferred(hovered_idx)
200-
if event.button_index == MOUSE_BUTTON_LEFT:
201-
var scroll_backwards_area_rect := get_scroll_backwards_area_rect()
202-
if scroll_backwards_area_rect.has_area() and scroll_backwards_area_rect.has_point(event.position) and not is_scroll_backwards_disabled():
203-
scrolling_backwards = true
204-
set_process(true)
205-
return
206-
207-
var scroll_forwards_area_rect := get_scroll_forwards_area_rect()
208-
if scroll_forwards_area_rect.has_area() and scroll_forwards_area_rect.has_point(event.position) and not is_scroll_forwards_disabled():
209-
scrolling_forwards = true
210-
set_process(true)
211-
return
212-
213-
if hovered_idx == -1 and not get_close_button_rect().has_point(event.position) and event.double_click:
214-
Configs.savedata.add_empty_tab()
184+
if not event is InputEventMouseButton:
185+
return
186+
187+
if event.is_pressed():
188+
if event.button_index in [MOUSE_BUTTON_WHEEL_UP, MOUSE_BUTTON_WHEEL_LEFT]:
189+
scroll_backwards(event.factor)
190+
elif event.button_index in [MOUSE_BUTTON_WHEEL_DOWN, MOUSE_BUTTON_WHEEL_RIGHT]:
191+
scroll_forwards(event.factor)
192+
elif event.button_index in [MOUSE_BUTTON_LEFT, MOUSE_BUTTON_RIGHT]:
193+
var hovered_idx := get_hovered_index()
194+
if hovered_idx != -1:
195+
if hovered_idx == Configs.savedata.get_active_tab_index():
196+
scroll_to_active()
197+
else:
198+
# Give time for deferred callbacks that might change the active SVG. For example, the code editor
199+
# might get unfocused by clicking on a tab, changing the SVG, so this should be deferred.
200+
Configs.savedata.set_active_tab_index.call_deferred(hovered_idx)
201+
if event.button_index == MOUSE_BUTTON_LEFT:
202+
var scroll_backwards_area_rect := get_scroll_backwards_area_rect()
203+
if scroll_backwards_area_rect.has_area() and scroll_backwards_area_rect.has_point(event.position) and not is_scroll_backwards_disabled():
204+
scrolling_backwards = true
205+
set_process(true)
215206
return
216207

217-
var btn_arr: Array[ContextButton] = []
208+
var scroll_forwards_area_rect := get_scroll_forwards_area_rect()
209+
if scroll_forwards_area_rect.has_area() and scroll_forwards_area_rect.has_point(event.position) and not is_scroll_forwards_disabled():
210+
scrolling_forwards = true
211+
set_process(true)
212+
return
218213

219-
if hovered_idx == -1:
220-
if get_add_button_rect().has_point(event.position) or get_scroll_forwards_area_rect().has_point(event.position) or\
221-
get_scroll_backwards_area_rect().has_point(event.position):
222-
return
223-
btn_arr.append(ContextButton.create_from_action("new_tab"))
224-
else:
225-
var new_active_tab := Configs.savedata.get_tab(hovered_idx)
226-
var external_file_missing := not FileAccess.file_exists(new_active_tab.svg_file_path)
227-
var tab_count := Configs.savedata.get_tab_count()
228-
229-
var has_empty_tabs := false
230-
for tab in Configs.savedata.get_tabs():
231-
if tab.is_empty():
232-
has_empty_tabs = true
233-
break
234-
235-
var has_saved_tabs := false
236-
for tab in Configs.savedata.get_tabs():
237-
if tab.is_saved():
238-
has_saved_tabs = true
239-
break
240-
241-
btn_arr.append(ContextButton.create_from_action("close_tab").set_icon_none())
242-
btn_arr.append(ContextButton.create_arrow(Translator.translate("Close multiple"), [
243-
func() -> ContextButton: return ContextButton.create_from_action("close_all_other_tabs", tab_count < 2).set_icon_none(),
244-
func() -> ContextButton: return ContextButton.create_from_action("close_tabs_to_left", hovered_idx == 0).set_icon_none(),
245-
func() -> ContextButton: return ContextButton.create_from_action("close_tabs_to_right", hovered_idx == tab_count - 1).set_icon_none(),
246-
func() -> ContextButton: return ContextButton.create_from_action("close_empty_tabs", not has_empty_tabs).set_icon_none(),
247-
func() -> ContextButton: return ContextButton.create_from_action("close_saved_tabs", not has_saved_tabs).set_icon_none(),
248-
]))
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))
214+
if hovered_idx == -1 and not get_close_button_rect().has_point(event.position) and event.double_click:
215+
Configs.savedata.add_empty_tab()
216+
return
217+
218+
var btn_arr: Array[ContextButton] = []
219+
220+
if hovered_idx == -1:
221+
if get_add_button_rect().has_point(event.position) or get_scroll_forwards_area_rect().has_point(event.position) or\
222+
get_scroll_backwards_area_rect().has_point(event.position):
223+
return
224+
btn_arr.append(ContextButton.create_from_action("new_tab"))
225+
else:
226+
var new_active_tab := Configs.savedata.get_tab(hovered_idx)
227+
var external_file_missing := not FileAccess.file_exists(new_active_tab.svg_file_path)
228+
var tab_count := Configs.savedata.get_tab_count()
254229

255-
var tab_popup := ContextPopup.create(btn_arr, true, -1, PackedInt32Array([2, 5]))
256-
if hovered_idx != -1:
257-
var tab_global_rect := get_tab_rect(hovered_idx)
258-
tab_global_rect.position += get_global_rect().position
259-
HandlerGUI.popup_under_rect(tab_popup, tab_global_rect, get_viewport())
260-
else:
261-
HandlerGUI.popup_under_pos(tab_popup, get_global_mouse_position(), get_viewport())
262-
elif event.button_index == MOUSE_BUTTON_MIDDLE:
263-
if Configs.savedata.tab_mmb_close:
264-
FileUtils.close_tabs(get_hovered_index())
230+
var has_empty_tabs := false
231+
for tab in Configs.savedata.get_tabs():
232+
if tab.is_empty():
233+
has_empty_tabs = true
234+
break
235+
236+
var has_saved_tabs := false
237+
for tab in Configs.savedata.get_tabs():
238+
if tab.is_saved():
239+
has_saved_tabs = true
240+
break
241+
242+
btn_arr.append(ContextButton.create_from_action("close_tab").set_icon_none())
243+
btn_arr.append(ContextButton.create_arrow(Translator.translate("Close multiple"), [
244+
func() -> ContextButton: return ContextButton.create_from_action("close_all_other_tabs", tab_count < 2).set_icon_none(),
245+
func() -> ContextButton: return ContextButton.create_from_action("close_tabs_to_left", hovered_idx == 0).set_icon_none(),
246+
func() -> ContextButton: return ContextButton.create_from_action("close_tabs_to_right", hovered_idx == tab_count - 1).set_icon_none(),
247+
func() -> ContextButton: return ContextButton.create_from_action("close_empty_tabs", not has_empty_tabs).set_icon_none(),
248+
func() -> ContextButton: return ContextButton.create_from_action("close_saved_tabs", not has_saved_tabs).set_icon_none(),
249+
]))
250+
btn_arr.append(ContextButton.create_from_action("save"))
251+
btn_arr.append(ContextButton.create_from_action("save_as").add_custom_text(Translator.translate("Save SVG as…")))
252+
btn_arr.append(ContextButton.create_from_action("reset_svg", FileUtils.compare_svg_to_disk_contents() != FileUtils.FileState.DIFFERENT))
253+
btn_arr.append(ContextButton.create_from_action("open_externally", external_file_missing))
254+
btn_arr.append(ContextButton.create_from_action("open_in_folder", external_file_missing))
255+
256+
var tab_popup := ContextPopup.create(btn_arr, true, -1, PackedInt32Array([2, 5]))
257+
if hovered_idx != -1:
258+
var tab_global_rect := get_tab_rect(hovered_idx)
259+
tab_global_rect.position += get_global_rect().position
260+
HandlerGUI.popup_under_rect(tab_popup, tab_global_rect, get_viewport())
265261
else:
266-
# Refer to a previous comment for why it needs to be deferred.
267-
Configs.savedata.set_active_tab_index.call_deferred(get_hovered_index())
268-
elif event.button_index == MOUSE_BUTTON_LEFT and event.is_released():
269-
scrolling_backwards = false
270-
scrolling_forwards = false
271-
set_process(false)
262+
HandlerGUI.popup_under_pos(tab_popup, get_global_mouse_position(), get_viewport())
263+
elif event.button_index == MOUSE_BUTTON_MIDDLE:
264+
if Configs.savedata.tab_mmb_close:
265+
FileUtils.close_tabs(get_hovered_index())
266+
else:
267+
# Refer to a previous comment for why it needs to be deferred.
268+
Configs.savedata.set_active_tab_index.call_deferred(get_hovered_index())
269+
elif event.button_index == MOUSE_BUTTON_LEFT:
270+
scrolling_backwards = false
271+
scrolling_forwards = false
272+
set_process(false)
272273

273274

274275
# Autoscroll when the dragged tab is hovered beyond the tabs area.

src/ui_widgets/ProceduralControl.gd

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,11 @@ func _gui_input(event: InputEvent) -> void:
159159
if event.button_index == MOUSE_BUTTON_LEFT:
160160
if event.is_pressed():
161161
pressed_button = hovered_button
162-
queue_redraw()
163162
elif event.is_released():
164163
if is_instance_valid(pressed_button) and pressed_button == hovered_button and not pressed_button.disabled:
165164
pressed_button.callable.call()
166165
pressed_button = null
167-
queue_redraw()
166+
queue_redraw()
168167

169168
func _update_hover(mouse_pos: Vector2) -> void:
170169
var new_hover: ButtonData = null

src/ui_widgets/pathdata_field.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,12 @@ func _on_commands_gui_input(event: InputEvent) -> void:
227227
if Rect2(Vector2.ZERO, commands_container.size).has_point(event_pos):
228228
cmd_idx = int(event_pos.y / STRIP_HEIGHT)
229229

230+
set_hovered(cmd_idx)
230231
if event is InputEventMouseMotion and event.button_mask == 0:
231232
if cmd_idx >= 0:
232233
State.set_hovered(element.xid, cmd_idx)
233234
else:
234235
State.remove_hovered(element.xid, cmd_idx)
235-
set_hovered(cmd_idx)
236236
elif event is InputEventMouseButton:
237237
if event.button_index == MOUSE_BUTTON_LEFT:
238238
if event.is_pressed():

src/ui_widgets/points_field.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,12 @@ func _on_points_gui_input(event: InputEvent) -> void:
210210
if Rect2(Vector2.ZERO, points_container.size).has_point(event_pos):
211211
point_idx = int(event_pos.y / STRIP_HEIGHT)
212212

213+
set_hovered(point_idx)
213214
if event is InputEventMouseMotion and event.button_mask == 0:
214215
if point_idx >= 0:
215216
State.set_hovered(element.xid, point_idx)
216217
else:
217218
State.remove_hovered(element.xid, point_idx)
218-
set_hovered(point_idx)
219219
elif event is InputEventMouseButton:
220220
if event.button_index == MOUSE_BUTTON_LEFT:
221221
if event.is_pressed():

src/ui_widgets/viewport_controls.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func _unhandled_input(event: InputEvent) -> void:
2929
execute_panning(event.delta) # Panning with touch.
3030
elif event is InputEventMagnifyGesture:
3131
# Zooming with touch.
32-
canvas.set_zoom(canvas.camera_zoom * event.factor)
32+
canvas.set_zoom(canvas.camera_zoom * event.factor, event.position / canvas.size)
3333
elif event is InputEventMouseButton and event.is_pressed():
3434
# Actions with scrolling.
3535
var move_vec := Vector2.ZERO

0 commit comments

Comments
 (0)