TableTower/ui/list_view.gd
RobinFiredrake 16b34c40f6 Card palette: left dock Cards | List, search, click or drag to add
- CardCatalog: one list of card kinds for the palette, right-click New card
  and new-card names; Dice table and Deck are their own items.
- LeftDock holds the palette and List view in the shared dock tab style.
- Play greys the palette under a Switch to Build notice (replaces the
  greyed + Card button); + Card menu removed; Card palette button in Build.
- Templates dropped from the palette land where they are let go.
- Phones: + opens the palette full screen.
- docs/SHEETS.md: the Sheets and unified editor plan.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 14:58:56 -06:00

80 lines
2.5 KiB
GDScript

class_name ListView
extends VBoxContainer
## List view: the spread's cards as a plain list, the List tab of the left dock
## (LeftDock; it fills the window on phones). Groups show as nested rows; rows
## roll, select (Build) and show where their threads go. It has its own search
## and "+ Group". Shown from View ▾, ☰ or right-clicking the spread.
## The old "List view on" setting; LeftDock.restore reads it once.
const SETTING := "list_view"
var m: Main
var tree: ListTree
var _search: LineEdit
var _rev := -1
func setup(p_main: Main) -> void:
m = p_main
add_theme_constant_override("separation", 8)
var head := HBoxContainer.new()
head.add_theme_constant_override("separation", 6)
add_child(head)
_search = LineEdit.new()
_search.placeholder_text = "Search the list"
_search.clear_button_enabled = true
_search.size_flags_horizontal = SIZE_EXPAND_FILL
ModalCard.style_line_edit(_search)
_search.text_changed.connect(func(s: String) -> void:
tree.filter = s.strip_edges().to_lower()
tree.rebuild())
head.add_child(_search)
var group := Style.bar_button("+ Group")
group.tooltip_text = "A new, empty group on the spread. Drag cards onto it."
group.pressed.connect(new_group)
head.add_child(group)
tree = ListTree.new(m)
tree.size_flags_vertical = SIZE_EXPAND_FILL
add_child(tree)
var hint := Style.make_label("Drag to reorder or into a group. Double-click shows the card on the spread.", Style.body(), 12, Style.ON_BG_MUTED)
hint.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
add_child(hint)
func _process(_delta: float) -> void:
if is_visible_in_tree() and m.data and m.edit_rev != _rev:
_rev = m.edit_rev
tree.rebuild()
## Shows or hides the list (the left dock's List tab).
func set_shown(on: bool) -> void:
if on:
m.left_dock.show_tab(LeftDock.LIST)
elif m.left_dock.showing(LeftDock.LIST):
m.left_dock.hide_dock()
func toggle() -> void:
m.left_dock.toggle_tab(LeftDock.LIST)
## True when the list is on screen.
func shown() -> bool:
return m.left_dock.showing(LeftDock.LIST)
## A new, empty group in the middle of the view, or with its top-left corner
## at `at` (world coordinates).
func new_group(at: Vector2 = Vector2.INF) -> void:
m.undo_redo._begin_edit()
var g := m.data.add_group(m.grouping._free_group_name(), [])
if at == Vector2.INF:
var c := m.board.screen_to_world(m.board.size / 2.0)
g.position = (c - g.size / 2.0).round()
else:
g.position = at
m.grouping._groups_changed()
m.mark_dirty()
m.undo_redo._end_edit()
_rev = -1