diff --git a/Terminal.Gui/Core/Application.cs b/Terminal.Gui/Core/Application.cs index 47868627d..0bcf6c7e5 100644 --- a/Terminal.Gui/Core/Application.cs +++ b/Terminal.Gui/Core/Application.cs @@ -432,12 +432,6 @@ namespace Terminal.Gui { return p.X < 0 || p.X > r.Width - 1 || p.Y < 0 || p.Y > r.Height - 1; } - /// - /// This event is fired once when the application is first loaded. The dimensions of the - /// terminal are provided. - /// - public static Action Loaded; - /// /// Building block API: Prepares the provided for execution. /// @@ -472,8 +466,8 @@ namespace Terminal.Gui { if (toplevel.LayoutStyle == LayoutStyle.Computed) toplevel.SetRelativeLayout (new Rect (0, 0, Driver.Cols, Driver.Rows)); toplevel.LayoutSubviews (); - Loaded?.Invoke (new ResizedEventArgs () { Rows = Driver.Rows, Cols = Driver.Cols }); toplevel.WillPresent (); + toplevel.OnLoaded (); Redraw (toplevel); toplevel.PositionCursor (); Driver.Refresh (); diff --git a/Terminal.Gui/Core/Toplevel.cs b/Terminal.Gui/Core/Toplevel.cs index a200852f2..b1183ae6c 100644 --- a/Terminal.Gui/Core/Toplevel.cs +++ b/Terminal.Gui/Core/Toplevel.cs @@ -49,12 +49,26 @@ namespace Terminal.Gui { public bool Running { get; set; } /// - /// Fired once the Toplevel's has started it's first iteration. + /// Fired once the Toplevel's has begin loaded. + /// A Loaded event handler is a good place to finalize initialization before calling `. + /// + public event Action Loaded; + + /// + /// Fired once the Toplevel's has started it's first iteration. /// Subscribe to this event to perform tasks when the has been laid out and focus has been set. - /// changes. A Ready event handler is a good place to finalize initialization after calling `(topLevel)`. + /// changes. A Ready event handler is a good place to finalize initialization after calling `(topLevel)`. /// public event Action Ready; + /// + /// Called from before the is redraws for the first time. + /// + internal virtual void OnLoaded () + { + Loaded?.Invoke (); + } + /// /// Called from after the has entered it's first iteration of the loop. /// diff --git a/UICatalog/Scenarios/Dialogs.cs b/UICatalog/Scenarios/Dialogs.cs index 4da731941..bb63862c4 100644 --- a/UICatalog/Scenarios/Dialogs.cs +++ b/UICatalog/Scenarios/Dialogs.cs @@ -93,7 +93,7 @@ namespace UICatalog { }; frame.Add (numButtonsEdit); - Top.Ready += () => frame.Height = Dim.Height (widthEdit) + Dim.Height (heightEdit) + Dim.Height (titleEdit) + Top.Loaded += () => frame.Height = Dim.Height (widthEdit) + Dim.Height (heightEdit) + Dim.Height (titleEdit) + Dim.Height (numButtonsEdit) + 2; label = new Label ("Button Pressed:") { diff --git a/UICatalog/Scenarios/MessageBoxes.cs b/UICatalog/Scenarios/MessageBoxes.cs index c95eda05e..ae2efca6c 100644 --- a/UICatalog/Scenarios/MessageBoxes.cs +++ b/UICatalog/Scenarios/MessageBoxes.cs @@ -124,7 +124,7 @@ namespace UICatalog { }; frame.Add (styleRadioGroup); - Top.Ready += () => frame.Height = Dim.Height (widthEdit) + Dim.Height (heightEdit) + Dim.Height (titleEdit) + Dim.Height (messageEdit) + Top.Loaded += () => frame.Height = Dim.Height (widthEdit) + Dim.Height (heightEdit) + Dim.Height (titleEdit) + Dim.Height (messageEdit) + Dim.Height (numButtonsEdit) + Dim.Height (styleRadioGroup) + 2; label = new Label ("Button Pressed:") { diff --git a/UICatalog/UICatalog.cs b/UICatalog/UICatalog.cs index 52ae654e5..8c68e99b3 100644 --- a/UICatalog/UICatalog.cs +++ b/UICatalog/UICatalog.cs @@ -100,13 +100,13 @@ namespace UICatalog { scenario.Setup (); scenario.Run (); - static void ReadyHandler () + static void LoadedHandler () { _rightPane.SetFocus (); - _top.Ready -= ReadyHandler; + _top.Loaded -= LoadedHandler; } - _top.Ready += ReadyHandler; + _top.Loaded += LoadedHandler; #if DEBUG_IDISPOSABLE // After the scenario runs, validate all Responder-based instances @@ -258,7 +258,7 @@ namespace UICatalog { _top.Add (_leftPane); _top.Add (_rightPane); _top.Add (_statusBar); - _top.Ready += () => { + _top.Loaded += () => { if (_runningScenario != null) { _runningScenario = null; }