List view: the spread as a list with folders

A left-docked panel (View ▾ → List view, ☰ or right-click the spread)
lists every card, with groups as folders. Rows show threads in and out
(hover for where they lead) and a Roll cell; click selects in Build,
double-click shows the card on the spread, right-click opens its menu.
Drag to reorder (the spread's own order, saved and undoable), onto a
folder to move in, folder into folder to nest. Own search, + Folder,
resizable edge.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
RobinFiredrake 2026-11-10 18:50:32 -06:00
parent 5d427d3856
commit 0ede1d7cd1
13 changed files with 496 additions and 2 deletions

89
tests/test_list_view.gd Normal file
View file

@ -0,0 +1,89 @@
extends SceneTree
## List view: rows for every card with thread counts and Roll, search, new
## folders, and drag-and-drop moves (reorder, into a folder, folder in folder).
## Run: godot --headless --path . -s res://tests/test_list_view.gd -- --sample
var _failures := 0
var main: Main
func _init() -> void:
if not OS.get_cmdline_user_args().has("--sample"):
print("Run with -- --sample so the test can't touch saved data.")
quit(2)
return
main = load("res://ui/main.tscn").instantiate()
root.add_child(main)
await _frames(5)
await _test_rows()
await _test_moves()
print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures])
quit(1 if _failures else 0)
func _rows(it: TreeItem, out: Array) -> Array:
var c := it.get_first_child()
while c:
out.append(c)
_rows(c, out)
c = c.get_next()
return out
func _find(id: String) -> TreeItem:
for it: TreeItem in _rows(main.list_view.tree.get_root(), []):
if ListTree._meta(it).get("id") == id:
return it
return null
func _test_rows() -> void:
var lv := main.list_view
_check(not lv.visible, "the list starts hidden")
lv.set_shown(true)
await _frames(2)
var rows := _rows(lv.tree.get_root(), [])
_check(rows.size() == main.data.tables.size(), "a row per card (%d)" % rows.size())
var road := _find("road")
_check(road != null and road.get_text(ListTree.COL_THREADS).contains("←1") and road.get_text(ListTree.COL_ROLL) == "Roll", "a row shows its threads and Roll: " + (road.get_text(ListTree.COL_THREADS) if road else ""))
_check(road.get_tooltip_text(ListTree.COL_THREADS).contains("from Wilderness Travel"), "the thread tooltip says where they come from")
lv._search.text = "weapon"
lv._search.text_changed.emit("weapon")
await _frames()
var hits := _rows(lv.tree.get_root(), [])
_check(hits.size() >= 1 and hits.size() < rows.size(), "search narrows the list (%d rows)" % hits.size())
lv._search.text = ""
lv._search.text_changed.emit("")
func _test_moves() -> void:
var lv := main.list_view
var n := main.data.groups.size()
lv.new_folder()
await _frames(2)
_check(main.data.groups.size() == n + 1, "+ Folder adds an empty group")
var g := main.data.groups[main.data.groups.size() - 1]
ListOrder.move(main, {"kind": "card", "id": "towns"}, {"kind": "group", "id": g.id}, 0)
await _frames(2)
_check(main.data.group_of("towns") == g, "dropping a card on a folder moves it in")
var f2 := main.data.add_group("Inner", [])
ListOrder.move(main, {"kind": "group", "id": f2.id}, {"kind": "group", "id": g.id}, 0)
_check(f2.parent == g.id, "a folder dropped on a folder goes inside it")
ListOrder.move(main, {"kind": "group", "id": g.id}, {"kind": "group", "id": f2.id}, 0)
_check(g.parent == "", "a folder can't go inside its own inner folder")
var ids := main.data.tables.map(func(t: RollTable) -> String: return t.id)
ListOrder.move(main, {"kind": "card", "id": ids[3]}, {"kind": "card", "id": ids[0]}, -1)
_check(main.data.tables[0].id == ids[3], "dropping above a card reorders the spread's list")
main.undo_redo.undo()
_check(main.data.tables[0].id == ids[0], "and undo puts it back")
func _frames(n: int = 2) -> void:
for i in n:
await process_frame
func _check(ok: bool, what: String) -> void:
if not ok:
_failures += 1
print("FAIL ", what)

View file

@ -0,0 +1 @@
uid://cm6sju33r5taq

View file

@ -164,6 +164,8 @@ static func background(m: Main, at: Vector2) -> Array:
list.append({"text": "Shuffle all decks", "do": m.local_state.reshuffle_all, "disabled": not has_decks(m),
"tip": "Put every Deck-mode card's results back"})
list.append({"text": "Fit spread", "do": m.board.fit})
list.append({"text": "Hide the list" if m.list_view.visible else "List view", "do": m.list_view.toggle,
"tip": "The cards as a list with folders"})
list.append({"sep": ""})
list.append({"text": "Theme…", "do": func() -> void: m.add_child(ThemeDialog.new(m))})
return list

75
ui/list_order.gd Normal file
View file

@ -0,0 +1,75 @@
class_name ListOrder
extends RefCounted
## List view's drag and drop, applied to the spread: reorders cards
## (TowerBoard.tables) and groups (.groups), and moves them in or out of
## groups. A card that joins a group also moves on the spread, to just under
## the group's frame, so the frame doesn't stretch across the spread.
## `what` and `onto` are {kind: "card"|"group", id}; `onto` is {} for empty
## space (the end of the list). `section`: -1 above, 0 onto, 1 below.
static func move(m: Main, what: Dictionary, onto: Dictionary, section: int) -> void:
m.undo_redo._begin_edit()
var into := "" # the group it ends up in
if onto.is_empty():
into = ""
elif section == 0 and onto["kind"] == "group":
into = str(onto["id"])
elif onto["kind"] == "group":
into = m.data.get_group(onto["id"]).parent
else:
var g := m.data.group_of(str(onto["id"]))
into = g.id if g else ""
var ok := _move_card(m, str(what["id"]), into) if what["kind"] == "card" else m.data.set_group_parent(str(what["id"]), into)
if not ok:
m.toast("A group can't go inside itself")
m.undo_redo._end_edit()
return
if section != 0 and not onto.is_empty() and onto["kind"] == what["kind"]:
_reorder(m, what, onto, section)
m.grouping._groups_changed()
m.mark_dirty()
m.undo_redo._end_edit()
static func _move_card(m: Main, tid: String, into: String) -> bool:
var old := m.data.group_of(tid)
if (old.id if old else "") == into:
return true
if into == "":
m.data.remove_from_group(tid)
if old and old.parent != "":
m.data.add_to_group(tid, old.parent)
return true
var g := m.data.get_group(into)
m.data.add_to_group(tid, into)
# Under the frame's last card, so the frame grows a little, not across the spread.
var t := m.data.get_table(tid)
var bottom := g.position.y + TableGroup.TITLE_H
for other in m.data.tables_in(into):
if other != tid:
var c := m.card_for(other)
var ot := m.data.get_table(other)
bottom = maxf(bottom, ot.position.y + (c.size.y if c else 160.0))
t.position = Vector2(g.position.x + TableGroup.PAD, bottom + 24.0).round()
var card := m.card_for(tid)
if card:
card.position = t.position
return true
static func _reorder(m: Main, what: Dictionary, onto: Dictionary, section: int) -> void:
var list: Array = m.data.tables if what["kind"] == "card" else m.data.groups
var from := -1
var to := -1
for i in list.size():
if list[i].id == what["id"]:
from = i
if list[i].id == onto["id"]:
to = i
if from < 0 or to < 0:
return
var item: Variant = list[from]
list.remove_at(from)
if from < to:
to -= 1
list.insert(to + (1 if section > 0 else 0), item)

1
ui/list_order.gd.uid Normal file
View file

@ -0,0 +1 @@
uid://b8yjlsjq537e0

208
ui/list_tree.gd Normal file
View file

@ -0,0 +1,208 @@
class_name ListTree
extends Tree
## List view's tree: groups as folders (nested), cards as rows with their
## threads and a Roll cell. Drag a row to reorder it or drop it on a folder to
## move it in; the order is the spread's own (TowerBoard.tables and .groups).
const COL_NAME := 0
const COL_THREADS := 1
const COL_ROLL := 2
var m: Main
var filter := ""
func _init(p_main: Main) -> void:
m = p_main
columns = 3
hide_root = true
column_titles_visible = false
select_mode = Tree.SELECT_ROW
allow_reselect = true
set_column_expand(COL_NAME, true)
set_column_expand(COL_THREADS, false)
set_column_custom_minimum_width(COL_THREADS, 64)
set_column_expand(COL_ROLL, false)
set_column_custom_minimum_width(COL_ROLL, 54)
add_theme_font_override("font", Style.body())
add_theme_font_size_override("font_size", 15)
add_theme_color_override("font_color", Style.INK)
add_theme_color_override("font_selected_color", Style.INK)
add_theme_constant_override("v_separation", 6)
add_theme_stylebox_override("panel", Style.box(Style.CARD, 0, [4, 4, 4, 4]))
add_theme_stylebox_override("selected", Style.box(Style.LIT, 4))
add_theme_stylebox_override("selected_focus", Style.box(Style.LIT, 4))
add_theme_stylebox_override("focus", StyleBoxEmpty.new())
item_mouse_selected.connect(_on_click)
item_activated.connect(_on_activated)
item_collapsed.connect(_on_folder_toggled)
## Rebuilds every row from the spread, keeping the open folders and selection.
func rebuild() -> void:
var sel := _meta(get_selected())
clear()
var root := create_item()
_fill(root, "")
if not sel.is_empty():
_select_meta(root, sel)
func _fill(parent: TreeItem, gid: String) -> void:
for g in m.data.groups:
if g.parent == gid:
var it := create_item(parent)
it.set_text(COL_NAME, Formatter.strip_tags(g.name))
it.set_custom_font(COL_NAME, Style.body_bold())
it.set_custom_color(COL_NAME, Style.TRIM_DARK)
it.set_metadata(COL_NAME, {"kind": "group", "id": g.id})
it.set_tooltip_text(COL_NAME, "Folder (a group on the spread): %s" % MainSelection.describe_counts(m.data.tables_in(g.id).size(), m.data.groups_in(g.id).size() - 1))
_fill(it, g.id)
it.collapsed = g.collapsed and filter == ""
if filter != "" and it.get_first_child() == null:
it.free()
var members := {}
var g0 := m.data.get_group(gid)
if g0:
for tid in g0.members:
members[tid] = true
for t in m.data.tables:
if (gid == "" and m.data.group_of(t.id) == null) or members.has(t.id):
if filter != "" and not _matches(t):
continue
_card_row(parent, t)
func _card_row(parent: TreeItem, t: RollTable) -> void:
var it := create_item(parent)
it.set_text(COL_NAME, Formatter.strip_tags(t.name))
it.set_tooltip_text(COL_NAME, Describe.kind_label(t))
if t.color != "":
it.set_custom_color(COL_NAME, Color(t.color).darkened(0.2))
it.set_metadata(COL_NAME, {"kind": "card", "id": t.id})
var ins := _threads_in(t.id)
var outs := _threads_out(t)
var counts := PackedStringArray()
if not ins.is_empty():
counts.append("←%d" % ins.size())
if not outs.is_empty():
counts.append("→%d" % outs.size())
it.set_text(COL_THREADS, " ".join(counts))
it.set_custom_color(COL_THREADS, Style.MUTED)
var tip := PackedStringArray()
if not ins.is_empty():
tip.append("Threads in:\n " + "\n ".join(ins))
if not outs.is_empty():
tip.append("Threads out:\n " + "\n ".join(outs))
it.set_tooltip_text(COL_THREADS, "\n".join(tip) if not tip.is_empty() else "No threads")
if t.kind != RollTable.KIND_VARIABLE:
it.set_text(COL_ROLL, "Roll")
it.set_custom_color(COL_ROLL, Style.TRIM_DARK)
it.set_custom_font(COL_ROLL, Style.body_bold())
it.set_tooltip_text(COL_ROLL, "Roll %s" % Formatter.strip_tags(t.name))
func _threads_in(tid: String) -> PackedStringArray:
var out := PackedStringArray()
for src in m.data.tables:
for e in src.entries:
if e.pipes.has(tid):
out.append("from %s · %s" % [Formatter.strip_tags(src.name), Formatter.strip_tags(e.text).left(40)])
return out
func _threads_out(t: RollTable) -> PackedStringArray:
var out := PackedStringArray()
for e in t.entries:
for to in e.pipes:
var target := m.data.get_table(to)
out.append("%s → %s" % [Formatter.strip_tags(e.text).left(40), Formatter.strip_tags(target.name) if target else to])
return out
func _matches(t: RollTable) -> bool:
if Formatter.strip_tags(t.name).to_lower().contains(filter):
return true
for e in t.entries:
if Formatter.strip_tags(e.text).to_lower().contains(filter):
return true
return false
# ---------- Clicks ----------
func _on_click(at: Vector2, button: int) -> void:
var meta := _meta(get_selected())
if meta.is_empty():
return
if button == MOUSE_BUTTON_RIGHT:
var list := Actions.card(m, m.data.get_table(meta["id"])) if meta["kind"] == "card" else Actions.group(m, m.data.get_group(meta["id"]))
Actions.popup_at(m, list, get_screen_transform() * at)
return
if meta["kind"] == "card":
if get_column_at_position(at) == COL_ROLL:
m.rolling.start_roll(str(meta["id"]))
elif m.mode == Main.Mode.BUILD:
m.select_card(str(meta["id"]))
## Double-click or Enter: show the card on the spread.
func _on_activated() -> void:
var meta := _meta(get_selected())
if meta.get("kind") == "card":
m.focus_table(str(meta["id"]))
## Opening or closing a folder opens or closes its group on the spread too.
func _on_folder_toggled(it: TreeItem) -> void:
var meta := _meta(it)
if meta.get("kind") == "group" and filter == "":
var g := m.data.get_group(meta["id"])
if g and g.collapsed != it.collapsed:
m.grouping.set_group_collapsed(g.id, it.collapsed)
static func _meta(it: TreeItem) -> Dictionary:
if it == null:
return {}
var v: Variant = it.get_metadata(COL_NAME)
return v if v is Dictionary else {}
func _select_meta(it: TreeItem, want: Dictionary) -> bool:
var c := it.get_first_child()
while c:
if _meta(c) == want:
c.select(COL_NAME)
return true
if _select_meta(c, want):
return true
c = c.get_next()
return false
# ---------- Drag and drop ----------
func _get_drag_data(at: Vector2) -> Variant:
var it := get_item_at_position(at)
var meta := _meta(it)
if meta.is_empty() or filter != "":
return null
var l := Label.new()
l.text = it.get_text(COL_NAME)
set_drag_preview(l)
drop_mode_flags = DROP_MODE_ON_ITEM | DROP_MODE_INBETWEEN
return {"list_item": meta}
func _can_drop_data(at: Vector2, data: Variant) -> bool:
if not (data is Dictionary and (data as Dictionary).has("list_item")):
return false
var target := _meta(get_item_at_position(at))
return target.is_empty() or target != data["list_item"]
func _drop_data(at: Vector2, data: Variant) -> void:
drop_mode_flags = DROP_MODE_DISABLED
var it := get_item_at_position(at)
ListOrder.move(m, data["list_item"], _meta(it), get_drop_section_at_position(at))

1
ui/list_tree.gd.uid Normal file
View file

@ -0,0 +1 @@
uid://cmijso0hnx5ro

89
ui/list_view.gd Normal file
View file

@ -0,0 +1,89 @@
class_name ListView
extends PanelContainer
## List view: the spread's cards as a plain list, docked on the left (or
## filling the window on phones). Groups are folders; rows roll, select
## (Build) and show where their threads go. It has its own search and
## "+ Folder". Shown from View ▾, ☰ or right-clicking the spread.
const WIDTH := 320.0
const MIN_WIDTH := 220.0
const SETTING := "list_view"
var m: Main
var tree: ListTree
var splitter: PanelSplitter
var _search: LineEdit
var _rev := -1
func setup(p_main: Main) -> void:
m = p_main
add_theme_stylebox_override("panel", Style.panel_box([10, 10, 10, 10]))
var col := VBoxContainer.new()
col.add_theme_constant_override("separation", 8)
add_child(col)
var head := HBoxContainer.new()
head.add_theme_constant_override("separation", 6)
col.add_child(head)
var title := Style.make_label("List", Style.display(), 20, Style.ON_BG)
title.size_flags_horizontal = SIZE_EXPAND_FILL
head.add_child(title)
var folder := Style.bar_button("+ Folder")
folder.tooltip_text = "A new folder (a group on the spread). Drag cards onto it."
folder.pressed.connect(new_folder)
head.add_child(folder)
var close := Style.bar_button("×")
close.tooltip_text = "Close the list"
close.pressed.connect(func() -> void: set_shown(false))
head.add_child(close)
_search = LineEdit.new()
_search.placeholder_text = "Search the list"
_search.clear_button_enabled = true
ModalCard.style_line_edit(_search)
_search.text_changed.connect(func(s: String) -> void:
tree.filter = s.strip_edges().to_lower()
tree.rebuild())
col.add_child(_search)
tree = ListTree.new(m)
tree.size_flags_vertical = SIZE_EXPAND_FILL
col.add_child(tree)
var hint := Style.make_label("Drag to reorder or into a folder. Double-click shows the card on the spread.", Style.body(), 12, Style.ON_BG_MUTED)
hint.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
col.add_child(hint)
func _process(_delta: float) -> void:
if visible and m.data and m.edit_rev != _rev:
_rev = m.edit_rev
tree.rebuild()
func set_width(px: float) -> void:
custom_minimum_size.x = px
## Shows or hides the list and remembers it.
func set_shown(on: bool) -> void:
visible = on
if splitter:
splitter.visible = on
_rev = -1
if m.state:
m.state.set_setting(SETTING, on)
m.state.save()
func toggle() -> void:
set_shown(not visible)
## A new, empty folder: a group in the middle of the view.
func new_folder() -> void:
m.undo_redo._begin_edit()
var g := m.data.add_group(m.grouping._free_group_name(), [])
var c := m.board.screen_to_world(m.board.size / 2.0)
g.position = (c - g.size / 2.0).round()
m.grouping._groups_changed()
m.mark_dirty()
m.undo_redo._end_edit()
_rev = -1

1
ui/list_view.gd.uid Normal file
View file

@ -0,0 +1 @@
uid://ck7y8oftg8nd3

View file

@ -43,6 +43,8 @@ var inspector: Inspector
var selection: Dictionary = {}
## Groups in the Build selection (MainSelection).
var selecting: MainSelection
## The List view panel (left dock).
var list_view: ListView
var _save_timer: Timer
var _saving_enabled := true
@ -168,6 +170,18 @@ func _build_ui() -> void:
middle.add_theme_constant_override("separation", 0)
middle.size_flags_vertical = SIZE_EXPAND_FILL
root.add_child(middle)
list_view = ListView.new()
list_view.setup(self)
var lside := PanelSplitter.new(self, false, "list_width", ListView.WIDTH, ListView.MIN_WIDTH)
lside.before = true
lside.size_changed.connect(list_view.set_width)
list_view.splitter = lside
list_view.set_width(lside.size_px)
middle.add_child(list_view)
middle.add_child(lside)
var list_on := state != null and bool(state.get_setting(ListView.SETTING, false))
list_view.visible = list_on
lside.visible = list_on
board = BoardView.new()
board.setup(self)
board.size_flags_horizontal = SIZE_EXPAND_FILL

View file

@ -384,12 +384,15 @@ func _perf_frames(n: int, pan: Vector2) -> String:
# --minimap / --no-minimap show or hide the overview
# --pack Build ▸ Arrange ▸ Pack collapsed groups
# --perf print load and frame timings, then quit
# --list show List view
func _run_nav_cli(args: PackedStringArray) -> void:
if args.has("--minimap"):
m.nav.set_minimap_visible(true)
if args.has("--no-minimap"):
m.nav.set_minimap_visible(false)
if args.has("--list"):
m.list_view.set_shown(true)
if args.has("--pack"):
await m.nav.pack_collapsed_groups()
var f := _arg_value(args, "--focus")

View file

@ -14,6 +14,9 @@ const GRIP := 36.0
var main: Main
## True for a handle dragged up and down (it sizes a panel's height).
var vertical := true
## The panel sits before the handle (the List on the left): moving away from it
## grows it.
var before := false
var setting := ""
var size_px := 0.0
var default_px := 0.0
@ -95,8 +98,9 @@ func _gui_input(ev: InputEvent) -> void:
accept_event()
queue_redraw()
elif ev is InputEventMouseMotion and _dragging:
# The panel sits after the handle, so moving toward the board grows it.
set_size_px(_start - (_axis((ev as InputEventMouseMotion).global_position) - _from))
# Moving toward the board grows the panel.
var moved := _axis((ev as InputEventMouseMotion).global_position) - _from
set_size_px(_start + moved if before else _start - moved)
accept_event()

View file

@ -10,6 +10,7 @@ const ID_COLLAPSE := 2
const ID_STRIPES := 3
const ID_MINIMAP := 4
const ID_THEME := 5
const ID_LIST := 6
var m: Main
@ -30,6 +31,8 @@ func setup(p_main: Main) -> void:
pm.add_separator("Show")
pm.add_check_item("Striped rows", ID_STRIPES)
pm.add_check_item("Minimap (M)", ID_MINIMAP)
pm.add_check_item("List view", ID_LIST)
pm.set_item_tooltip(pm.get_item_index(ID_LIST), "The cards as a list with folders, beside the spread")
pm.add_separator()
pm.add_item("Theme…", ID_THEME)
pm.set_item_tooltip(pm.get_item_index(ID_THEME), "Colours, background, fonts and logo; save your own theme")
@ -45,6 +48,7 @@ func sync() -> void:
pm.set_item_text(pm.get_item_index(ID_COLLAPSE), collapse_label())
pm.set_item_checked(pm.get_item_index(ID_STRIPES), m.local_state.striped_rows())
pm.set_item_checked(pm.get_item_index(ID_MINIMAP), m.board.minimap.visible)
pm.set_item_checked(pm.get_item_index(ID_LIST), m.list_view.visible)
func collapse_label() -> String:
@ -63,5 +67,7 @@ func activate(id: int) -> void:
m.local_state.set_striped_rows(not m.local_state.striped_rows())
ID_MINIMAP:
m.nav.set_minimap_visible(not m.board.minimap.visible, true)
ID_LIST:
m.list_view.toggle()
ID_THEME:
m.add_child(ThemeDialog.new(m))