#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
namespace TerminalGuiFluentTesting;
public partial class GuiTestContext
{
///
/// Adds the given to the current top level view
/// and performs layout.
///
///
///
public GuiTestContext Add (View v)
{
WaitIteration ((app) =>
{
Toplevel top = app.Current ?? throw new ("Top was null so could not add view");
top.Add (v);
top.Layout ();
_lastView = v;
});
return this;
}
private View? _lastView;
///
/// The last view added (e.g. with ) or the root/current top.
///
public View LastView => _lastView ?? App?.Current ?? throw new ("Could not determine which view to add to");
private T Find (Func evaluator) where T : View
{
Toplevel? t = App?.Current;
if (t == null)
{
Fail ("App.Current was null when attempting to find view");
}
T? f = FindRecursive (t!, evaluator);
if (f == null)
{
Fail ("Failed to tab to a view which matched the Type and evaluator constraints in any SubViews of top");
}
return f!;
}
private T? FindRecursive (View current, Func evaluator) where T : View
{
foreach (View subview in current.SubViews)
{
if (subview is T match && evaluator (match))
{
return match;
}
// Recursive call
T? result = FindRecursive (subview, evaluator);
if (result != null)
{
return result;
}
}
return null;
}
}