TableTower/ui/inspector_frame.gd

104 lines
4.6 KiB
GDScript3
Raw Permalink Normal View History

class_name InspectorFrame
extends RefCounted
## The inspector's frame: the panel and its scroll area, the thin strip shown
## when it is hidden, the heading at the top of each section (with its hide
## button), and the "Nothing selected" page. Inspector calls these; the
## sections themselves (card, result, thread) live in other helpers.
## Builds the panel's frame into `insp`: the scrolling body and the hidden strip.
static func build(insp: Inspector) -> void:
var panel_box := Style.box(Style.CARD, 0, [0, 0, 0, 0])
panel_box.border_width_left = 1
panel_box.border_color = Color(0, 0, 0, 0.25)
insp.add_theme_stylebox_override("panel", panel_box)
var stack := Control.new()
stack.size_flags_vertical = Control.SIZE_EXPAND_FILL
insp.add_child(stack)
insp._body = VBoxContainer.new()
insp._body.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
insp._body.add_theme_constant_override("separation", 0)
stack.add_child(insp._body)
var tabs_pad := MarginContainer.new()
for side: String in ["margin_left", "margin_right", "margin_top"]:
tabs_pad.add_theme_constant_override(side, 10)
tabs_pad.add_child(SideTabs.make_row(insp.main, SideTabs.INSPECTOR))
insp._body.add_child(tabs_pad)
insp._scroll = ScrollContainer.new()
insp._scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED
insp._scroll.size_flags_vertical = Control.SIZE_EXPAND_FILL
insp._body.add_child(insp._scroll)
var pad := MarginContainer.new()
pad.size_flags_horizontal = Control.SIZE_EXPAND_FILL
for margin_name in ["margin_left", "margin_right"]:
pad.add_theme_constant_override(margin_name, 16)
pad.add_theme_constant_override("margin_top", 14)
pad.add_theme_constant_override("margin_bottom", 18)
insp._scroll.add_child(pad)
insp._content = InspectorKit.vbox(14)
pad.add_child(insp._content)
insp._strip = PanelContainer.new()
insp._strip.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
insp._strip.add_theme_stylebox_override("panel", Style.box(Style.CARD, 0, [2, 8, 2, 8]))
var open := Button.new()
open.text = "«"
open.tooltip_text = "Show the inspector"
open.size_flags_vertical = Control.SIZE_SHRINK_BEGIN
Style.skin_button(open, Style.box(Color(0, 0, 0, 0), 5, [4, 2, 4, 2]), Style.box(Style.HOVER_ROW, 5, [4, 2, 4, 2]),
Style.box(Style.HOVER_ROW, 5, [4, 2, 4, 2]), Style.TRIM_DARK)
open.add_theme_font_size_override("font_size", 18)
open.pressed.connect(func() -> void: insp.set_collapsed(false))
insp._strip.add_child(open)
insp._strip.hide()
stack.add_child(insp._strip)
## The heading of a section: a small kind line, a big title, and the » button
## that hides the inspector. Remembers the title label so it can follow typing.
static func head(insp: Inspector, kind: String, title: String) -> Control:
var row := InspectorKit.hbox(6)
var column := InspectorKit.vbox(2)
column.size_flags_horizontal = Control.SIZE_EXPAND_FILL
column.add_child(InspectorKit.flabel(kind))
var title_label := Style.make_label(title, Style.display(), 22, Style.INK)
insp._title_label = title_label
title_label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
title_label.custom_minimum_size = Vector2(120, 0)
column.add_child(title_label)
row.add_child(column)
var hide_button := Button.new()
hide_button.text = "»"
hide_button.tooltip_text = "Hide the inspector"
hide_button.size_flags_vertical = Control.SIZE_SHRINK_BEGIN
Style.skin_button(hide_button, Style.box(Color(0, 0, 0, 0), 5, [6, 0, 6, 2]), Style.box(Style.HOVER_ROW, 5, [6, 0, 6, 2]),
Style.box(Style.HOVER_ROW, 5, [6, 0, 6, 2]), Style.MUTED, Style.INK)
hide_button.add_theme_font_size_override("font_size", 18)
hide_button.focus_mode = Control.FOCUS_NONE
hide_button.pressed.connect(func() -> void: insp.set_collapsed(true))
row.add_child(hide_button)
return row
## Keeps the heading in step with the name or text being typed.
static func refresh_title(insp: Inspector) -> void:
if not is_instance_valid(insp._title_label):
return
var card := insp.selected_table()
match str(insp.selection.get("kind", "")):
"card":
if card:
insp._title_label.text = Inspector._title_of(card.name, "(no name)")
"result":
var entry := insp.selected_entry()
if entry:
InspectorList.refresh_title(insp, entry)
## The page shown when nothing is selected.
static func show_empty(insp: Inspector) -> void:
insp._content.add_child(head(insp, "Inspector", "Nothing selected"))
insp._content.add_child(InspectorKit.note("Select a card, a result or a thread to edit it.", Style.MUTED, 15))
insp._content.add_child(InspectorKit.note("Click a card's title for the card, a result's text for the result, or a thread on the felt for its options.", Style.MUTED, 13))