diff --git a/tests/test_card_size.gd b/tests/test_card_size.gd index 2257018..02787eb 100644 --- a/tests/test_card_size.gd +++ b/tests/test_card_size.gd @@ -13,6 +13,7 @@ func _init() -> void: await _test_show_less() await _test_add_scrolls_and_focuses() await _test_wheel_zooms() + await _test_zoomed_in_anchors() finish() @@ -165,3 +166,21 @@ func _button(n: Node, prefix: String) -> Button: if found: return found return null + + +## Zoomed in, a result's dot still sits on its row and shows (the row rect was +## once read at 100% scale, hiding dots low in a scrolling list). +func _test_zoomed_in_anchors() -> void: + var card := main.card_for("road") + card.set_user_size(380.0, 120.0) + main.board.set_zoom(1.5) + await _frames() + var last: String = main.data.get_table("road").entries[-1].id + var row := card.rows[last] as Control + var a := card.anchor_for(last) + var expected := card.position.y + (card.get_global_transform().affine_inverse() * row.get_global_position()).y + row.size.y / 2.0 + var in_list := main.board.world_rect_of(card.list_scroll).intersects(main.board.world_rect_of(row)) + _check(absf(a["pos"].y - expected) < 1.0 or not in_list, "zoomed in, a result's dot sits on its row: %.1f vs %.1f" % [a["pos"].y, expected]) + var scroll_rect := main.board.world_rect_of(card.list_scroll) + _check(is_equal_approx(scroll_rect.size.y, 120.0), "world_rect_of gives the list's size in world units: %.1f" % scroll_rect.size.y) + main.board.set_zoom(1.0) diff --git a/ui/board_view.gd b/ui/board_view.gd index f26c31a..2b1a566 100644 --- a/ui/board_view.gd +++ b/ui/board_view.gd @@ -229,6 +229,12 @@ func fit() -> void: world.position = Vector2(maxf(8.0, (size.x - bounds.size.x * zoom) / 2.0), 8.0) - bounds.position * zoom +## A control's rect in world coordinates. (Control.get_global_rect ignores the +## world's zoom for the size, so it is wrong whenever the board is not at 100%.) +func world_rect_of(control: Control) -> Rect2: + return (world.get_global_transform().affine_inverse() * control.get_global_transform()) * Rect2(Vector2.ZERO, control.size) + + ## The part of the world the board shows right now. func view_rect() -> Rect2: return Rect2(screen_to_world(Vector2.ZERO), size / zoom) diff --git a/ui/group_card.gd b/ui/group_card.gd index 6773834..e1aa8d4 100644 --- a/ui/group_card.gd +++ b/ui/group_card.gd @@ -276,9 +276,7 @@ func inlet_point() -> Vector2: func anchor_for(tid: String, eid: String) -> Vector2: var row: Control = lit_rows.get(Roller.entry_key(tid, eid)) if row != null and row.is_inside_tree(): - var to_world := main.board.world.get_global_transform().affine_inverse() - var r := row.get_global_rect() - return Vector2(position.x + size.x, (to_world * (r.position + Vector2(0, r.size.y / 2.0))).y) + return Vector2(position.x + size.x, main.board.world_rect_of(row).get_center().y) return Vector2(position.x + size.x, position.y + INLET_Y) diff --git a/ui/main_editing.gd b/ui/main_editing.gd index 0648f71..b98986e 100644 --- a/ui/main_editing.gd +++ b/ui/main_editing.gd @@ -29,6 +29,8 @@ const ADD_KINDS := [ ] const MENU_FROM_TEMPLATE := 100 const MENU_GROUP := 101 +## How close (screen pixels) a dragged thread must be to a card's input dot to drop on it. +const LINK_DROP_RADIUS := 10.0 const MENU_SAVE_SELECTION := 102 @@ -286,11 +288,12 @@ func finish_link() -> void: func _card_under_mouse() -> TableCard: if _card_under_mouse_override: return _card_under_mouse_override - var gp := m.get_global_mouse_position() + var mouse := m.board.world.get_local_mouse_position() + var reach := LINK_DROP_RADIUS / m.board.zoom var kids := m.board.cards.get_children() for i in range(kids.size() - 1, -1, -1): var card := kids[i] as TableCard - if card and card.visible and card.get_global_rect().has_point(gp): + if card and card.visible and (m.board.world_rect_of(card).has_point(mouse) or (card.table.kind != RollTable.KIND_VARIABLE and card.inlet_point().distance_to(mouse) <= reach)): return card return null diff --git a/ui/table_card_geometry.gd b/ui/table_card_geometry.gd index 672b0f9..105957c 100644 --- a/ui/table_card_geometry.gd +++ b/ui/table_card_geometry.gd @@ -27,14 +27,13 @@ func anchor_for(eid: String) -> Dictionary: var row: Control = card.rows.get(eid, card.more_row) if row == null or not row.is_inside_tree(): return {} - var to_world := card.main.board.world.get_global_transform().affine_inverse() - var r := row.get_global_rect() - var y := (to_world * (r.position + Vector2(0, r.size.y / 2.0))).y + var board := card.main.board + var y := board.world_rect_of(row).get_center().y var shown := true if card.list_scroll != null and card.rows.has(eid): - var sr := card.list_scroll.get_global_rect() - var top := (to_world * sr.position).y + 14.0 - var bottom := (to_world * sr.end).y - 14.0 + var scroll_rect := board.world_rect_of(card.list_scroll) + var top := scroll_rect.position.y + 14.0 + var bottom := scroll_rect.end.y - 14.0 shown = y >= top - 4.0 and y <= bottom + 4.0 y = clampf(y, top, bottom) return {"pos": Vector2(card.position.x + card.size.x, y), "visible": shown}