TableTower/ui/field_palette.gd
RobinFiredrake 2661744b06 Sheets phase B: main menu, Sheets list, sheet editor
- Main menu (Spreads, Sheets, Settings, Quit) on the theme background,
  with recent spreads and sheets; logo or ☰ returns to it.
- Sheets: data model, store, templates, snapshot undo; New sheet dialog
  (blank or a template); editor with folder tabs, snap-grid canvas on the
  spread background, field palette, inspector, Play/Build, status strip.
- Field kinds: Number, Text box (BBCode, live {@name}), Heading.
- PaletteList shared by the card and field palettes; shared top bar brand.
- Keys go to the screen that shows; theme reloads keep the screen.

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

55 lines
1.7 KiB
GDScript

class_name FieldPalette
extends VBoxContainer
## The sheet editor's field palette: every kind of box (SheetKinds) in a
## PaletteList, like the spread's card palette. Click adds a box in the middle
## of the canvas; drag drops it where you let go. Greyed in Play under a
## notice with Switch to Build.
const MESSAGE := "Fields are added in Build mode."
var ed: SheetEditor
var list: PaletteList
var notice: PanelContainer
func setup(p_editor: SheetEditor) -> void:
ed = p_editor
add_theme_constant_override("separation", 8)
notice = BuildModeHint.make_notice(ed.m, func() -> void: ed.set_mode(Main.Mode.BUILD), MESSAGE)
add_child(notice)
list = PaletteList.new()
list.setup("Search fields", "Drag onto the sheet, or click to add", "Add a field", "“number”, “text” or “title”")
list.size_flags_vertical = SIZE_EXPAND_FILL
list.sections_for = _sections
list.can_use = ed.building
list.on_blocked = func() -> void: ed.m.toast(MESSAGE)
list.drop_at = drop_at
add_child(list)
list.rebuild()
func _process(_delta: float) -> void:
notice.visible = ed.doc != null and not ed.building()
func _sections(query: String) -> Array:
var out: Array = []
for group in SheetKinds.groups():
var entries: Array = []
for item: Dictionary in SheetKinds.ITEMS:
if item["group"] == group and PaletteList.matches(item, query):
entries.append([item, _add.bind(str(item["kind"]))])
out.append([group, entries])
return out
func drop_at(on_add: Callable, screen_point: Vector2) -> bool:
var at := ed.canvas.drop_point(screen_point)
if at == Vector2.INF:
return false
list.use(on_add, at)
return true
func _add(at: Vector2, kind: String) -> void:
ed.add_box(kind, at)