using FairyView;
namespace StandardScene.Utils
{
///
/// FairyView 通用 UI 小工具:浮动居中弹窗,不依赖宿主 SafeUI。
///
public static class FairyUiHelper
{
///
/// 非阻塞二次确认:用户点「确认」后在当前线程执行 。
/// 耗时逻辑请自行 Task.Run。
///
public static void ConfirmThen(string message, System.Action onConfirm)
{
var dlg = CenteredDialog(GUI.DeclarePanel().ShowTitle("确认"), 380, 150);
dlg.Define(pb =>
{
if (pb.Closing())
{
dlg.Exit();
return;
}
pb.Label(message);
pb.Separator();
if (pb.Button("确认", distinct: "fairyui-confirm-ok"))
{
dlg.Exit();
onConfirm?.Invoke();
}
pb.SameLine(8);
if (pb.Button("取消", distinct: "fairyui-confirm-cancel"))
dlg.Exit();
});
}
/// 非阻塞文件选择对话框。
public static void PickOpenFile(string label, string filter, System.Action onPicked)
{
var dlg = CenteredDialog(GUI.DeclarePanel().ShowTitle("选择文件"), 420, 120);
dlg.Define(pb =>
{
if (pb.Closing())
{
dlg.Exit();
return;
}
if (pb.OpenFile(label, filter, out var path))
{
dlg.Exit();
onPicked?.Invoke(path);
}
});
}
/// 非阻塞提示对话框。
public static void Alert(string title, string message)
{
var dlg = CenteredDialog(GUI.DeclarePanel().ShowTitle(title), 380, 150);
dlg.Define(pb =>
{
if (pb.Closing())
{
dlg.Exit();
return;
}
pb.Label(message);
pb.Separator();
if (pb.Button("确定", distinct: "fairyui-alert-ok"))
dlg.Exit();
});
}
///
/// FairyView Table.height 是 Ant Design scroll.y 像素;旧 CycleGUI 同参是可见行数。
///
public static int TableHeightPx(int visibleRows) =>
visibleRows <= 0 ? 0 : visibleRows * 32;
static Panel CenteredDialog(Panel panel, int width, int height) =>
panel
.TopMost(true)
.ForceFloat()
.InitSize(width, height)
.InitPos(true, 0, 0, 0.5f, 0.5f, 0.5f, 0.5f);
}
}