TableTower/ui/list_view.gd
RobinFiredrake 0ede1d7cd1 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>
2026-11-10 18:50:32 -06:00

89 lines
2.6 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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