class_name CardGrip extends Control ## The resize handle in a card's bottom-right corner. Dragging it sets the ## card's width and the height of its results list (RollTable.width, ## list_height; the list then scrolls). Double-click returns to automatic. ## ## The card's container lays it over the whole card, so _has_point limits the ## part that takes the mouse to the corner. It stays the card's last child. const HIT := 18.0 const MIN_WIDTH := 200.0 const MAX_WIDTH := 1200.0 const MIN_LIST := 72.0 var card: TableCard var _from := Vector2.ZERO var _start_w := 0.0 var _start_h := 0.0 var _dragging := false func _init(p_card: TableCard) -> void: card = p_card mouse_default_cursor_shape = CURSOR_FDIAGSIZE tooltip_text = "Drag to resize the card. Double-click for its automatic size." ## Only the corner square, inside the card. (Godot asks about points outside a ## control's box too, so both edges of the square need checking.) func _has_point(p: Vector2) -> bool: return p.x >= size.x - HIT and p.y >= size.y - HIT and p.x <= size.x and p.y <= size.y func _draw() -> void: var c := Color(Style.MUTED, 0.7) for i in 3: var o := 4.0 + i * 4.0 draw_line(Vector2(size.x - o, size.y - 2), Vector2(size.x - 2, size.y - o), c, 1.5, true) func _gui_input(ev: InputEvent) -> void: var mb := ev as InputEventMouseButton if mb and mb.button_index == MOUSE_BUTTON_LEFT: if mb.pressed and mb.double_click: _dragging = false card.set_user_size(0.0, 0.0) card.main.mark_dirty() elif mb.pressed: card.main.undo_redo._begin_edit() _dragging = true _from = card.main.board.world_mouse() _start_w = card.size.x - card.extra_width() _start_h = card.list_area_height() elif _dragging: _dragging = false card.main.mark_dirty() accept_event() return var mm := ev as InputEventMouseMotion if mm and _dragging: var d := card.main.board.world_mouse() - _from card.set_user_size(clampf(_start_w + d.x, MIN_WIDTH, MAX_WIDTH), maxf(MIN_LIST, _start_h + d.y)) accept_event()