using Terminal.Gui; namespace ReactiveExample { public static class Extensions { public static MemoizedElement StackPanel( this TOwner owner, TNew control) where TOwner : View where TNew : View => new MemoizedElement(owner, control); public static MemoizedElement Append( this MemoizedElement owner, TNew control, int height = 1) where TOwner : View where TOld : View where TNew : View { control.X = Pos.Left(owner.Control); control.Y = Pos.Top(owner.Control) + height; return new MemoizedElement(owner.View, control); } public class MemoizedElement where TOwner : View where TControl : View { public TOwner View { get; } public TControl Control { get; } public MemoizedElement(TOwner owner, TControl control) { View = owner; Control = control; View.Add(control); } } } }