class_name TableCardGeometry extends RefCounted ## Where things are on a card, in world coordinates, and user resizing. var card: TableCard func _init(p_card: TableCard) -> void: card = p_card func inlet_point() -> Vector2: return Vector2(card.position.x, card.position.y + TableCard.INLET_Y) ## Where card threads leave (CardThreads): the middle of the bottom edge. func outlet_point() -> Vector2: return card.position + Vector2(card.size.x / 2.0, card.size.y) ## Where a pipe leaves this card for an entry: its row, or the "more" row when the ## entry is hidden in a collapsed card. Rows scrolled out of a long list clamp to ## its edge. Returns {} if there's nowhere to anchor. func anchor_for(eid: String) -> Dictionary: if eid == RollTable.OUTLET_ID: return {"pos": outlet_point(), "visible": true} 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 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 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} ## Sets the size the user dragged to (0 = automatic) and lays the card out ## again: cheaply while a scrolling list just changes height, else rebuilt. func set_user_size(w: float, list_h: float) -> void: if card.table.kind == RollTable.KIND_VARIABLE or card.is_collapsed(): list_h = 0.0 var rebuild_needed := (list_h > 0.0) != is_instance_valid(card.list_scroll) or (list_h == 0.0 and card.table.list_height > 0.0) card.table.width = w card.table.list_height = list_h if rebuild_needed: card.rebuild() else: card.custom_minimum_size.x = card.card_width() if is_instance_valid(card.list_scroll) and list_h > 0.0: card.list_scroll.custom_minimum_size.y = list_h card._shrink() card.main.board.geometry_rev += 1