mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-30 09:47:58 +01:00
Fixes #1007. Added a Loaded event in the Toplevel class.
This commit is contained in:
@@ -432,12 +432,6 @@ namespace Terminal.Gui {
|
||||
return p.X < 0 || p.X > r.Width - 1 || p.Y < 0 || p.Y > r.Height - 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This event is fired once when the application is first loaded. The dimensions of the
|
||||
/// terminal are provided.
|
||||
/// </summary>
|
||||
public static Action<ResizedEventArgs> Loaded;
|
||||
|
||||
/// <summary>
|
||||
/// Building block API: Prepares the provided <see cref="Toplevel"/> for execution.
|
||||
/// </summary>
|
||||
@@ -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 ();
|
||||
|
||||
@@ -49,12 +49,26 @@ namespace Terminal.Gui {
|
||||
public bool Running { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Fired once the Toplevel's <see cref="MainLoop"/> has started it's first iteration.
|
||||
/// Fired once the Toplevel's <see cref="Application.RunState"/> has begin loaded.
|
||||
/// A Loaded event handler is a good place to finalize initialization before calling `<see cref="Application.RunLoop(Application.RunState, bool)"/>.
|
||||
/// </summary>
|
||||
public event Action Loaded;
|
||||
|
||||
/// <summary>
|
||||
/// Fired once the Toplevel's <see cref="MainLoop"/> has started it's first iteration.
|
||||
/// Subscribe to this event to perform tasks when the <see cref="Toplevel"/> has been laid out and focus has been set.
|
||||
/// changes. A Ready event handler is a good place to finalize initialization after calling `<see cref="Application.Run()"/>(topLevel)`.
|
||||
/// changes. A Ready event handler is a good place to finalize initialization after calling `<see cref="Application.Run()"/>(topLevel)`.
|
||||
/// </summary>
|
||||
public event Action Ready;
|
||||
|
||||
/// <summary>
|
||||
/// Called from <see cref="Application.Begin(Toplevel)"/> before the <see cref="Toplevel"/> is redraws for the first time.
|
||||
/// </summary>
|
||||
internal virtual void OnLoaded ()
|
||||
{
|
||||
Loaded?.Invoke ();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called from <see cref="Application.RunLoop"/> after the <see cref="Toplevel"/> has entered it's first iteration of the loop.
|
||||
/// </summary>
|
||||
|
||||
@@ -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:") {
|
||||
|
||||
@@ -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:") {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user