Fix dots and drops when zoomed: read control rects in world space; 10px drop reach on input dots

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
tachyonwolf 2026-11-21 08:48:35 -06:00
parent 1735ed09fd
commit 5c69acbba0
5 changed files with 36 additions and 11 deletions

View file

@ -13,6 +13,7 @@ func _init() -> void:
await _test_show_less() await _test_show_less()
await _test_add_scrolls_and_focuses() await _test_add_scrolls_and_focuses()
await _test_wheel_zooms() await _test_wheel_zooms()
await _test_zoomed_in_anchors()
finish() finish()
@ -165,3 +166,21 @@ func _button(n: Node, prefix: String) -> Button:
if found: if found:
return found return found
return null 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)

View file

@ -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 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. ## The part of the world the board shows right now.
func view_rect() -> Rect2: func view_rect() -> Rect2:
return Rect2(screen_to_world(Vector2.ZERO), size / zoom) return Rect2(screen_to_world(Vector2.ZERO), size / zoom)

View file

@ -276,9 +276,7 @@ func inlet_point() -> Vector2:
func anchor_for(tid: String, eid: String) -> Vector2: func anchor_for(tid: String, eid: String) -> Vector2:
var row: Control = lit_rows.get(Roller.entry_key(tid, eid)) var row: Control = lit_rows.get(Roller.entry_key(tid, eid))
if row != null and row.is_inside_tree(): if row != null and row.is_inside_tree():
var to_world := main.board.world.get_global_transform().affine_inverse() return Vector2(position.x + size.x, main.board.world_rect_of(row).get_center().y)
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, position.y + INLET_Y) return Vector2(position.x + size.x, position.y + INLET_Y)

View file

@ -29,6 +29,8 @@ const ADD_KINDS := [
] ]
const MENU_FROM_TEMPLATE := 100 const MENU_FROM_TEMPLATE := 100
const MENU_GROUP := 101 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 const MENU_SAVE_SELECTION := 102
@ -286,11 +288,12 @@ func finish_link() -> void:
func _card_under_mouse() -> TableCard: func _card_under_mouse() -> TableCard:
if _card_under_mouse_override: if _card_under_mouse_override:
return _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() var kids := m.board.cards.get_children()
for i in range(kids.size() - 1, -1, -1): for i in range(kids.size() - 1, -1, -1):
var card := kids[i] as TableCard 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 card
return null return null

View file

@ -27,14 +27,13 @@ func anchor_for(eid: String) -> Dictionary:
var row: Control = card.rows.get(eid, card.more_row) var row: Control = card.rows.get(eid, card.more_row)
if row == null or not row.is_inside_tree(): if row == null or not row.is_inside_tree():
return {} return {}
var to_world := card.main.board.world.get_global_transform().affine_inverse() var board := card.main.board
var r := row.get_global_rect() var y := board.world_rect_of(row).get_center().y
var y := (to_world * (r.position + Vector2(0, r.size.y / 2.0))).y
var shown := true var shown := true
if card.list_scroll != null and card.rows.has(eid): if card.list_scroll != null and card.rows.has(eid):
var sr := card.list_scroll.get_global_rect() var scroll_rect := board.world_rect_of(card.list_scroll)
var top := (to_world * sr.position).y + 14.0 var top := scroll_rect.position.y + 14.0
var bottom := (to_world * sr.end).y - 14.0 var bottom := scroll_rect.end.y - 14.0
shown = y >= top - 4.0 and y <= bottom + 4.0 shown = y >= top - 4.0 and y <= bottom + 4.0
y = clampf(y, top, bottom) y = clampf(y, top, bottom)
return {"pos": Vector2(card.position.x + card.size.x, y), "visible": shown} return {"pos": Vector2(card.position.x + card.size.x, y), "visible": shown}