public static T CenterVertically <T>(this T child, ConsoleControl parent = null) where T : ConsoleControl { parent = parent ?? child.Parent; parent.SynchronizeForLifetime(nameof(ConsoleControl.Bounds), () => { if (parent.Height == 0 || child.Height == 0) { return; } var gap = parent.Height - child.Height; var y = gap / 2; child.Y = Math.Max(0, y); }, parent); return(child); }
public static T CenterHorizontally <T>(this T child, ConsoleControl parent = null) where T : ConsoleControl { parent = parent ?? child.Parent; Action syncAction = () => { if (parent.Width == 0 || child.Width == 0) { return; } var gap = parent.Width - child.Width; var x = gap / 2; child.X = Math.Max(0, x); }; parent.SynchronizeForLifetime(nameof(ConsoleControl.Bounds), syncAction, parent); child.SynchronizeForLifetime(nameof(ConsoleControl.Bounds), syncAction, parent); syncAction(); return(child); }
public static T CenterVertically <T>(this T child, ConsoleControl parent = null) where T : ConsoleControl { parent = parent ?? child.Parent; parent.SynchronizeForLifetime(nameof(ConsoleControl.Bounds), () => { if (child == ConsoleApp.Current.LayoutRoot) { } if (parent.Height == 0 || child.Height == 0) { return; } var gap = parent.Height - child.Height; var y = gap / 2; child.Y = y; }, parent.LifetimeManager); return(child); }
private void Controls_Added(ConsoleControl obj) { obj.SynchronizeForLifetime(nameof(Bounds), RedoLayout, Controls.GetMembershipLifetime(obj)); }