TableTower/ui/list_view.gd
RobinFiredrake 2fe9317b27 Phone layout and touch gestures
MobileLayout (Android, or --mobile to try it on a desktop): the List fills
the screen with a Spread/List swap; the bar drops the title, hint, zoom,
View, Help and Play/Build (the last three move into ☰); the tray hides its
Earlier column and shortens Roll again; DPI scaling. TouchInput (every
platform): a long press is a right-click, two fingers pan and pinch-zoom.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 18:58:33 -06:00

91 lines
2.7 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 close_button: Button
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)
close_button = Style.bar_button("×")
var close := close_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