using Godot;
using Cthangover.Core.UI;
namespace Cthangover.Mods.Interface.Base.Lists
{
///
/// Lightweight alternative to Widget for mod-authored controls. Has a simpler
/// lifecycle — just Construct() on first access and Destruct() on tree exit —
/// without the visibility interception and Show/Hide pipeline that Widget
/// carries. Use when the heavy Widget state machine would be overkill or
/// when the control's visibility is managed by Godot's native system.
///
public abstract partial class ModWidget : Control, IUiLazyConstruct
{
private bool _constructed;
/// Idempotent construction gate: calls exactly once, on the first invocation. Thread-safe for repeated external calls.
public void EnsureConstructed()
{
if (_constructed)
return;
_constructed = true;
Construct();
}
/// Runs once when the constructed control leaves the tree.
public override void _ExitTree()
{
if (_constructed)
Destruct();
}
protected abstract void Construct();
protected virtual void Destruct() { }
}
}