using Cthangover.Core.UI.Theming;
using Godot;
namespace Cthangover.Tools.Common
{
///
/// Sidebar section with a clickable uppercase caption (style guide
/// .ct-section-title plus a ▸/▾ marker) that shows or hides its
/// . Editors expand the sections relevant to the selected
/// object and collapse the rest, so a long property panel stays readable
/// without losing access to rarely used fields.
///
public partial class CollapsibleSection : VBoxContainer
{
private readonly Button _header;
private readonly string _title;
/// Container for the section's controls.
public VBoxContainer Body { get; }
/// Whether the body is shown.
public bool Expanded
{
get => Body.Visible;
set
{
Body.Visible = value;
_header.Text = (value ? "▾ " : "▸ ") + _title;
}
}
/// Creates a section titled by .
public CollapsibleSection(string titleKey, bool expanded = true)
{
_title = ToolUi.Tr(titleKey).ToUpperInvariant();
AddThemeConstantOverride("separation", UiTokens.Space2);
_header = new Button
{
Flat = true,
Alignment = HorizontalAlignment.Left,
FocusMode = FocusModeEnum.None,
MouseDefaultCursorShape = CursorShape.PointingHand
};
_header.AddThemeFontSizeOverride("font_size", UiTokens.FontSmall);
_header.AddThemeColorOverride("font_color", UiTokens.Muted);
_header.AddThemeColorOverride("font_hover_color", UiTokens.AccentBright);
_header.AddThemeColorOverride("font_pressed_color", UiTokens.Muted);
_header.AddThemeStyleboxOverride("normal", new StyleBoxEmpty());
_header.AddThemeStyleboxOverride("hover", new StyleBoxEmpty());
_header.AddThemeStyleboxOverride("pressed", new StyleBoxEmpty());
_header.Pressed += () => Expanded = !Expanded;
AddChild(_header);
Body = new VBoxContainer();
Body.AddThemeConstantOverride("separation", UiTokens.Space2);
AddChild(Body);
Expanded = expanded;
}
}
}