IApplication.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. using System.Collections.Concurrent;
  2. using System.Diagnostics.CodeAnalysis;
  3. namespace Terminal.Gui.App;
  4. /// <summary>
  5. /// Interface for instances that provide backing functionality to static
  6. /// gateway class <see cref="Application"/>.
  7. /// </summary>
  8. public interface IApplication
  9. {
  10. #region Keyboard
  11. /// <summary>
  12. /// Handles keyboard input and key bindings at the Application level.
  13. /// </summary>
  14. /// <remarks>
  15. /// <para>
  16. /// Provides access to keyboard state, key bindings, and keyboard event handling. Set during <see cref="Init"/>.
  17. /// </para>
  18. /// </remarks>
  19. IKeyboard Keyboard { get; set; }
  20. #endregion Keyboard
  21. #region Mouse
  22. /// <summary>
  23. /// Handles mouse event state and processing.
  24. /// </summary>
  25. /// <remarks>
  26. /// <para>
  27. /// Provides access to mouse state, mouse grabbing, and mouse event handling. Set during <see cref="Init"/>.
  28. /// </para>
  29. /// </remarks>
  30. IMouse Mouse { get; set; }
  31. #endregion Mouse
  32. #region Initialization and Shutdown
  33. /// <summary>Initializes a new instance of <see cref="Terminal.Gui"/> Application.</summary>
  34. /// <param name="driverName">
  35. /// The short name (e.g. "dotnet", "windows", "unix", or "fake") of the
  36. /// <see cref="IDriver"/> to use. If not specified the default driver for the platform will be used.
  37. /// </param>
  38. /// <remarks>
  39. /// <para>Call this method once per instance (or after <see cref="Shutdown"/> has been called).</para>
  40. /// <para>
  41. /// This function loads the right <see cref="IDriver"/> for the platform, creates a main loop coordinator,
  42. /// initializes keyboard and mouse handlers, and subscribes to driver events.
  43. /// </para>
  44. /// <para>
  45. /// <see cref="Shutdown"/> must be called when the application is closing (typically after
  46. /// <see cref="Run{T}"/> has returned) to ensure resources are cleaned up and terminal settings restored.
  47. /// </para>
  48. /// <para>
  49. /// The <see cref="Run{T}"/> function combines <see cref="Init(string)"/> and
  50. /// <see cref="Run(Toplevel, Func{Exception, bool})"/> into a single call. An application can use
  51. /// <see cref="Run{T}"/> without explicitly calling <see cref="Init(string)"/>.
  52. /// </para>
  53. /// </remarks>
  54. [RequiresUnreferencedCode ("AOT")]
  55. [RequiresDynamicCode ("AOT")]
  56. public void Init (string? driverName = null);
  57. /// <summary>
  58. /// This event is raised after the <see cref="Init"/> and <see cref="Shutdown"/> methods have been called.
  59. /// </summary>
  60. /// <remarks>
  61. /// Intended to support unit tests that need to know when the application has been initialized.
  62. /// </remarks>
  63. public event EventHandler<EventArgs<bool>>? InitializedChanged;
  64. /// <summary>Gets or sets whether the application has been initialized.</summary>
  65. bool Initialized { get; set; }
  66. /// <summary>Shutdown an application initialized with <see cref="Init"/>.</summary>
  67. /// <remarks>
  68. /// Shutdown must be called for every call to <see cref="Init"/> or
  69. /// <see cref="Application.Run(Toplevel, Func{Exception, bool})"/> to ensure all resources are cleaned
  70. /// up (Disposed) and terminal settings are restored.
  71. /// </remarks>
  72. public void Shutdown ();
  73. /// <summary>
  74. /// Resets the state of this instance.
  75. /// </summary>
  76. /// <param name="ignoreDisposed">If true, ignores disposed state checks during reset.</param>
  77. /// <remarks>
  78. /// <para>
  79. /// Encapsulates all setting of initial state for Application; having this in a function like this ensures we
  80. /// don't make mistakes in guaranteeing that the state of this singleton is deterministic when <see cref="Init"/>
  81. /// starts running and after <see cref="Shutdown"/> returns.
  82. /// </para>
  83. /// <para>
  84. /// IMPORTANT: Ensure all property/fields are reset here. See Init_ResetState_Resets_Properties unit test.
  85. /// </para>
  86. /// </remarks>
  87. public void ResetState (bool ignoreDisposed = false);
  88. #endregion Initialization and Shutdown
  89. #region Begin->Run->Iteration->Stop->End
  90. /// <summary>
  91. /// Building block API: Creates a <see cref="SessionToken"/> and prepares the provided <see cref="Toplevel"/> for
  92. /// execution. Not usually called directly by applications. Use <see cref="Run(Toplevel, Func{Exception, bool})"/>
  93. /// instead.
  94. /// </summary>
  95. /// <returns>
  96. /// The <see cref="SessionToken"/> that needs to be passed to the <see cref="End(SessionToken)"/> method upon
  97. /// completion.
  98. /// </returns>
  99. /// <param name="toplevel">The <see cref="Toplevel"/> to prepare execution for.</param>
  100. /// <remarks>
  101. /// <para>
  102. /// This method prepares the provided <see cref="Toplevel"/> for running. It adds this to the
  103. /// list of <see cref="Toplevel"/>s, lays out the SubViews, focuses the first element, and draws the
  104. /// <see cref="Toplevel"/> on the screen. This is usually followed by starting the main loop, and then the
  105. /// <see cref="End(SessionToken)"/> method upon termination which will undo these changes.
  106. /// </para>
  107. /// <para>
  108. /// Raises the <see cref="SessionBegun"/> event before returning.
  109. /// </para>
  110. /// </remarks>
  111. public SessionToken Begin (Toplevel toplevel);
  112. /// <summary>
  113. /// Runs a new Session creating a <see cref="Toplevel"/> and calling <see cref="Begin(Toplevel)"/>. When the session is
  114. /// stopped, <see cref="End(SessionToken)"/> will be called.
  115. /// </summary>
  116. /// <param name="errorHandler">Handler for any unhandled exceptions (resumes when returns true, rethrows when null).</param>
  117. /// <param name="driverName">
  118. /// The driver name. If not specified the default driver for the platform will be used. Must be
  119. /// <see langword="null"/> if <see cref="Init"/> has already been called.
  120. /// </param>
  121. /// <returns>The created <see cref="Toplevel"/>. The caller is responsible for disposing this object.</returns>
  122. /// <remarks>
  123. /// <para>Calling <see cref="Init"/> first is not needed as this function will initialize the application.</para>
  124. /// <para>
  125. /// <see cref="Shutdown"/> must be called when the application is closing (typically after Run has returned) to
  126. /// ensure resources are cleaned up and terminal settings restored.
  127. /// </para>
  128. /// <para>
  129. /// The caller is responsible for disposing the object returned by this method.
  130. /// </para>
  131. /// </remarks>
  132. [RequiresUnreferencedCode ("AOT")]
  133. [RequiresDynamicCode ("AOT")]
  134. public Toplevel Run (Func<Exception, bool>? errorHandler = null, string? driverName = null);
  135. /// <summary>
  136. /// Runs a new Session creating a <see cref="Toplevel"/>-derived object of type <typeparamref name="TView"/>
  137. /// and calling <see cref="Run(Toplevel, Func{Exception, bool})"/>. When the session is stopped,
  138. /// <see cref="End(SessionToken)"/> will be called.
  139. /// </summary>
  140. /// <typeparam name="TView">The type of <see cref="Toplevel"/> to create and run.</typeparam>
  141. /// <param name="errorHandler">Handler for any unhandled exceptions (resumes when returns true, rethrows when null).</param>
  142. /// <param name="driverName">
  143. /// The driver name. If not specified the default driver for the platform will be used. Must be
  144. /// <see langword="null"/> if <see cref="Init"/> has already been called.
  145. /// </param>
  146. /// <returns>The created <typeparamref name="TView"/> object. The caller is responsible for disposing this object.</returns>
  147. /// <remarks>
  148. /// <para>
  149. /// This method is used to start processing events for the main application, but it is also used to run other
  150. /// modal <see cref="View"/>s such as <see cref="Dialog"/> boxes.
  151. /// </para>
  152. /// <para>
  153. /// To make <see cref="Run(Toplevel, Func{Exception, bool})"/> stop execution, call
  154. /// <see cref="RequestStop()"/> or <see cref="RequestStop(Toplevel)"/>.
  155. /// </para>
  156. /// <para>
  157. /// Calling <see cref="Run(Toplevel, Func{Exception, bool})"/> is equivalent to calling
  158. /// <see cref="Begin(Toplevel)"/>, followed by starting the main loop, and then calling
  159. /// <see cref="End(SessionToken)"/>.
  160. /// </para>
  161. /// <para>
  162. /// When using <see cref="Run{T}"/> or <see cref="Run(Func{Exception, bool}, string)"/>,
  163. /// <see cref="Init"/> will be called automatically.
  164. /// </para>
  165. /// <para>
  166. /// In RELEASE builds: When <paramref name="errorHandler"/> is <see langword="null"/> any exceptions will be
  167. /// rethrown. Otherwise, <paramref name="errorHandler"/> will be called. If <paramref name="errorHandler"/>
  168. /// returns <see langword="true"/> the main loop will resume; otherwise this method will exit.
  169. /// </para>
  170. /// <para>
  171. /// <see cref="Shutdown"/> must be called when the application is closing (typically after Run has returned) to
  172. /// ensure resources are cleaned up and terminal settings restored.
  173. /// </para>
  174. /// <para>
  175. /// In RELEASE builds: When <paramref name="errorHandler"/> is <see langword="null"/> any exceptions will be
  176. /// rethrown. Otherwise, <paramref name="errorHandler"/> will be called. If <paramref name="errorHandler"/>
  177. /// returns <see langword="true"/> the main loop will resume; otherwise this method will exit.
  178. /// </para>
  179. /// <para>
  180. /// The caller is responsible for disposing the object returned by this method.
  181. /// </para>
  182. /// </remarks>
  183. [RequiresUnreferencedCode ("AOT")]
  184. [RequiresDynamicCode ("AOT")]
  185. public TView Run<TView> (Func<Exception, bool>? errorHandler = null, string? driverName = null)
  186. where TView : Toplevel, new ();
  187. /// <summary>
  188. /// Runs a new Session using the provided <see cref="Toplevel"/> view and calling
  189. /// <see cref="Run(Toplevel, Func{Exception, bool})"/>.
  190. /// When the session is stopped, <see cref="End(SessionToken)"/> will be called..
  191. /// </summary>
  192. /// <param name="view">The <see cref="Toplevel"/> to run as a modal.</param>
  193. /// <param name="errorHandler">Handler for any unhandled exceptions (resumes when returns true, rethrows when null).</param>
  194. /// <remarks>
  195. /// <para>
  196. /// This method is used to start processing events for the main application, but it is also used to run other
  197. /// modal <see cref="View"/>s such as <see cref="Dialog"/> boxes.
  198. /// </para>
  199. /// <para>
  200. /// To make <see cref="Run(Toplevel, Func{Exception, bool})"/> stop execution, call
  201. /// <see cref="RequestStop()"/> or <see cref="RequestStop(Toplevel)"/>.
  202. /// </para>
  203. /// <para>
  204. /// Calling <see cref="Run(Toplevel, Func{Exception, bool})"/> is equivalent to calling
  205. /// <see cref="Begin(Toplevel)"/>, followed by starting the main loop, and then calling
  206. /// <see cref="End(SessionToken)"/>.
  207. /// </para>
  208. /// <para>
  209. /// When using <see cref="Run{T}"/> or <see cref="Run(Func{Exception, bool}, string)"/>,
  210. /// <see cref="Init"/> will be called automatically.
  211. /// </para>
  212. /// <para>
  213. /// <see cref="Shutdown"/> must be called when the application is closing (typically after Run has returned) to
  214. /// ensure resources are cleaned up and terminal settings restored.
  215. /// </para>
  216. /// <para>
  217. /// In RELEASE builds: When <paramref name="errorHandler"/> is <see langword="null"/> any exceptions will be
  218. /// rethrown. Otherwise, <paramref name="errorHandler"/> will be called. If <paramref name="errorHandler"/>
  219. /// returns <see langword="true"/> the main loop will resume; otherwise this method will exit.
  220. /// </para>
  221. /// <para>
  222. /// The caller is responsible for disposing the object returned by this method.
  223. /// </para>
  224. /// </remarks>
  225. public void Run (Toplevel view, Func<Exception, bool>? errorHandler = null);
  226. /// <summary>
  227. /// Raises the <see cref="Iteration"/> event.
  228. /// </summary>
  229. /// <remarks>
  230. /// This is called once per main loop iteration, before processing input, timeouts, or rendering.
  231. /// </remarks>
  232. public void RaiseIteration ();
  233. /// <summary>This event is raised on each iteration of the main loop.</summary>
  234. /// <remarks>
  235. /// <para>
  236. /// This event is raised before input processing, timeout callbacks, and rendering occur each iteration.
  237. /// </para>
  238. /// <para>See also <see cref="AddTimeout"/> and <see cref="TimedEvents"/>.</para>
  239. /// </remarks>
  240. public event EventHandler<IterationEventArgs>? Iteration;
  241. /// <summary>Runs <paramref name="action"/> on the main UI loop thread.</summary>
  242. /// <param name="action">The action to be invoked on the main processing thread.</param>
  243. /// <remarks>
  244. /// <para>
  245. /// If called from the main thread, the action is executed immediately. Otherwise, it is queued via
  246. /// <see cref="AddTimeout"/> with <see cref="TimeSpan.Zero"/> and will be executed on the next main loop
  247. /// iteration.
  248. /// </para>
  249. /// </remarks>
  250. void Invoke (Action<IApplication>? action);
  251. /// <summary>Runs <paramref name="action"/> on the main UI loop thread.</summary>
  252. /// <param name="action">The action to be invoked on the main processing thread.</param>
  253. /// <remarks>
  254. /// <para>
  255. /// If called from the main thread, the action is executed immediately. Otherwise, it is queued via
  256. /// <see cref="AddTimeout"/> with <see cref="TimeSpan.Zero"/> and will be executed on the next main loop
  257. /// iteration.
  258. /// </para>
  259. /// </remarks>
  260. void Invoke (Action action);
  261. /// <summary>
  262. /// Building block API: Ends a Session and completes the execution of a <see cref="Toplevel"/> that was started with
  263. /// <see cref="Begin(Toplevel)"/>. Not usually called directly by applications.
  264. /// <see cref="Run(Toplevel, Func{Exception, bool})"/>
  265. /// will automatically call this method when the session is stopped.
  266. /// </summary>
  267. /// <param name="sessionToken">The <see cref="SessionToken"/> returned by the <see cref="Begin(Toplevel)"/> method.</param>
  268. /// <remarks>
  269. /// <para>
  270. /// This method removes the <see cref="Toplevel"/> from the stack, raises the <see cref="SessionEnded"/>
  271. /// event, and disposes the <paramref name="sessionToken"/>.
  272. /// </para>
  273. /// </remarks>
  274. public void End (SessionToken sessionToken);
  275. /// <summary>Requests that the currently running Session stop. The Session will stop after the current iteration completes.</summary>
  276. /// <remarks>
  277. /// <para>This will cause <see cref="Run(Toplevel, Func{Exception, bool})"/> to return.</para>
  278. /// <para>
  279. /// This is equivalent to calling <see cref="RequestStop(Toplevel)"/> with <see cref="TopRunnable"/> as the parameter.
  280. /// </para>
  281. /// </remarks>
  282. void RequestStop ();
  283. /// <summary>Requests that the currently running Session stop. The Session will stop after the current iteration completes.</summary>
  284. /// <param name="top">
  285. /// The <see cref="Toplevel"/> to stop. If <see langword="null"/>, stops the currently running <see cref="TopRunnable"/>.
  286. /// </param>
  287. /// <remarks>
  288. /// <para>This will cause <see cref="Run(Toplevel, Func{Exception, bool})"/> to return.</para>
  289. /// <para>
  290. /// Calling <see cref="RequestStop(Toplevel)"/> is equivalent to setting the <see cref="Toplevel.Running"/>
  291. /// property on the specified <see cref="Toplevel"/> to <see langword="false"/>.
  292. /// </para>
  293. /// </remarks>
  294. void RequestStop (Toplevel? top);
  295. /// <summary>
  296. /// Set to <see langword="true"/> to cause the session to stop running after first iteration.
  297. /// </summary>
  298. /// <remarks>
  299. /// <para>
  300. /// Used primarily for unit testing. When <see langword="true"/>, <see cref="End"/> will be called
  301. /// automatically after the first main loop iteration.
  302. /// </para>
  303. /// </remarks>
  304. bool StopAfterFirstIteration { get; set; }
  305. // TODO: This API is not used anywhere; it can be deleted
  306. /// <summary>
  307. /// Raised when <see cref="Begin(Toplevel)"/> has been called and has created a new <see cref="SessionToken"/>.
  308. /// </summary>
  309. /// <remarks>
  310. /// If <see cref="StopAfterFirstIteration"/> is <see langword="true"/>, callers to <see cref="Begin(Toplevel)"/>
  311. /// must also subscribe to <see cref="SessionEnded"/> and manually dispose of the <see cref="SessionToken"/> token
  312. /// when the application is done.
  313. /// </remarks>
  314. public event EventHandler<SessionTokenEventArgs>? SessionBegun;
  315. // TODO: This API is not used anywhere; it can be deleted
  316. /// <summary>
  317. /// Raised when <see cref="End(SessionToken)"/> was called and the session is stopping. The event args contain a
  318. /// reference to the <see cref="Toplevel"/>
  319. /// that was active during the session. This can be used to ensure the Toplevel is disposed of properly.
  320. /// </summary>
  321. /// <remarks>
  322. /// If <see cref="StopAfterFirstIteration"/> is <see langword="true"/>, callers to <see cref="Begin(Toplevel)"/>
  323. /// must also subscribe to <see cref="SessionEnded"/> and manually dispose of the <see cref="SessionToken"/> token
  324. /// when the application is done.
  325. /// </remarks>
  326. public event EventHandler<ToplevelEventArgs>? SessionEnded;
  327. #endregion Begin->Run->Iteration->Stop->End
  328. #region Toplevel Management
  329. /// <summary>Gets or sets the Toplevel that is on the top of the <see cref="SessionStack"/>.</summary>
  330. /// <remarks>
  331. /// <para>
  332. /// The top runnable in the session stack captures all mouse and keyboard input.
  333. /// This is set by <see cref="Begin(Toplevel)"/> and cleared by <see cref="End(SessionToken)"/>.
  334. /// </para>
  335. /// </remarks>
  336. Toplevel? TopRunnable { get; set; }
  337. /// <summary>Gets the stack of all active Toplevel sessions.</summary>
  338. /// <remarks>
  339. /// <para>
  340. /// Toplevels are added to this stack by <see cref="Begin(Toplevel)"/> and removed by
  341. /// <see cref="End(SessionToken)"/>.
  342. /// </para>
  343. /// </remarks>
  344. ConcurrentStack<Toplevel> SessionStack { get; }
  345. /// <summary>
  346. /// Caches the Toplevel associated with the current Session.
  347. /// </summary>
  348. /// <remarks>
  349. /// Used internally to optimize Toplevel state transitions.
  350. /// </remarks>
  351. Toplevel? CachedSessionTokenToplevel { get; set; }
  352. #endregion Toplevel Management
  353. #region Screen and Driver
  354. /// <summary>Gets or sets the console driver being used.</summary>
  355. /// <remarks>
  356. /// <para>
  357. /// Set by <see cref="Init"/> based on the driver parameter or platform default.
  358. /// </para>
  359. /// </remarks>
  360. IDriver? Driver { get; set; }
  361. /// <summary>
  362. /// Gets or sets whether <see cref="Driver"/> will be forced to output only the 16 colors defined in
  363. /// <see cref="ColorName16"/>. The default is <see langword="false"/>, meaning 24-bit (TrueColor) colors will be
  364. /// output as long as the selected <see cref="IDriver"/> supports TrueColor.
  365. /// </summary>
  366. bool Force16Colors { get; set; }
  367. /// <summary>
  368. /// Forces the use of the specified driver (one of "fake", "dotnet", "windows", or "unix"). If not
  369. /// specified, the driver is selected based on the platform.
  370. /// </summary>
  371. string ForceDriver { get; set; }
  372. /// <summary>
  373. /// Gets or sets the size of the screen. By default, this is the size of the screen as reported by the
  374. /// <see cref="IDriver"/>.
  375. /// </summary>
  376. /// <remarks>
  377. /// <para>
  378. /// If the <see cref="IDriver"/> has not been initialized, this will return a default size of 2048x2048; useful
  379. /// for unit tests.
  380. /// </para>
  381. /// </remarks>
  382. Rectangle Screen { get; set; }
  383. /// <summary>Raised when the terminal's size changed. The new size of the terminal is provided.</summary>
  384. /// <remarks>
  385. /// <para>
  386. /// This event is raised when the driver detects a screen size change. The event provides the new screen
  387. /// rectangle.
  388. /// </para>
  389. /// </remarks>
  390. public event EventHandler<EventArgs<Rectangle>>? ScreenChanged;
  391. /// <summary>
  392. /// Gets or sets whether the screen will be cleared, and all Views redrawn, during the next Application iteration.
  393. /// </summary>
  394. /// <remarks>
  395. /// <para>
  396. /// This is typically set to <see langword="true"/> when a View's <see cref="View.Frame"/> changes and that view
  397. /// has no SuperView (e.g. when <see cref="TopRunnable"/> is moved or resized).
  398. /// </para>
  399. /// <para>
  400. /// Automatically reset to <see langword="false"/> after <see cref="LayoutAndDraw"/> processes it.
  401. /// </para>
  402. /// </remarks>
  403. bool ClearScreenNextIteration { get; set; }
  404. /// <summary>
  405. /// Collection of sixel images to write out to screen when updating.
  406. /// Only add to this collection if you are sure terminal supports sixel format.
  407. /// </summary>
  408. List<SixelToRender> Sixel { get; }
  409. #endregion Screen and Driver
  410. #region Layout and Drawing
  411. /// <summary>
  412. /// Causes any Toplevels that need layout to be laid out, then draws any Toplevels that need display. Only Views
  413. /// that need to be laid out (see <see cref="View.NeedsLayout"/>) will be laid out. Only Views that need to be drawn
  414. /// (see <see cref="View.NeedsDraw"/>) will be drawn.
  415. /// </summary>
  416. /// <param name="forceRedraw">
  417. /// If <see langword="true"/> the entire View hierarchy will be redrawn. The default is <see langword="false"/> and
  418. /// should only be overridden for testing.
  419. /// </param>
  420. /// <remarks>
  421. /// <para>
  422. /// This method is called automatically each main loop iteration when any views need layout or drawing.
  423. /// </para>
  424. /// <para>
  425. /// If <see cref="ClearScreenNextIteration"/> is <see langword="true"/>, the screen will be cleared before
  426. /// drawing and the flag will be reset to <see langword="false"/>.
  427. /// </para>
  428. /// </remarks>
  429. public void LayoutAndDraw (bool forceRedraw = false);
  430. /// <summary>
  431. /// Calls <see cref="View.PositionCursor"/> on the most focused view.
  432. /// </summary>
  433. /// <remarks>
  434. /// <para>Does nothing if there is no most focused view.</para>
  435. /// <para>
  436. /// If the most focused view is not visible within its superview, the cursor will be hidden.
  437. /// </para>
  438. /// </remarks>
  439. /// <returns><see langword="true"/> if a view positioned the cursor and the position is visible.</returns>
  440. public bool PositionCursor ();
  441. #endregion Layout and Drawing
  442. #region Navigation and Popover
  443. /// <summary>Gets or sets the popover manager.</summary>
  444. /// <remarks>
  445. /// <para>
  446. /// Manages application-level popover views. Initialized during <see cref="Init"/>.
  447. /// </para>
  448. /// </remarks>
  449. ApplicationPopover? Popover { get; set; }
  450. /// <summary>Gets or sets the navigation manager.</summary>
  451. /// <remarks>
  452. /// <para>
  453. /// Manages focus navigation and tracking of the most focused view. Initialized during <see cref="Init"/>.
  454. /// </para>
  455. /// </remarks>
  456. ApplicationNavigation? Navigation { get; set; }
  457. #endregion Navigation and Popover
  458. #region Timeouts
  459. /// <summary>Adds a timeout to the application.</summary>
  460. /// <param name="time">The time span to wait before invoking the callback.</param>
  461. /// <param name="callback">
  462. /// The callback to invoke. If it returns <see langword="true"/>, the timeout will be reset and repeat. If it
  463. /// returns <see langword="false"/>, the timeout will stop and be removed.
  464. /// </param>
  465. /// <returns>
  466. /// Call <see cref="RemoveTimeout(object)"/> with the returned value to stop the timeout.
  467. /// </returns>
  468. /// <remarks>
  469. /// <para>
  470. /// When the time specified passes, the callback will be invoked on the main UI thread.
  471. /// </para>
  472. /// <para>
  473. /// <see cref="IApplication.Shutdown"/> calls StopAll on <see cref="TimedEvents"/> to remove all timeouts.
  474. /// </para>
  475. /// </remarks>
  476. object AddTimeout (TimeSpan time, Func<bool> callback);
  477. /// <summary>Removes a previously scheduled timeout.</summary>
  478. /// <param name="token">The token returned by <see cref="AddTimeout"/>.</param>
  479. /// <returns>
  480. /// <see langword="true"/> if the timeout is successfully removed; otherwise, <see langword="false"/>.
  481. /// This method also returns <see langword="false"/> if the timeout is not found.
  482. /// </returns>
  483. bool RemoveTimeout (object token);
  484. /// <summary>
  485. /// Handles recurring events. These are invoked on the main UI thread - allowing for
  486. /// safe updates to <see cref="View"/> instances.
  487. /// </summary>
  488. /// <remarks>
  489. /// <para>
  490. /// Provides low-level access to the timeout management system. Most applications should use
  491. /// <see cref="AddTimeout"/> and <see cref="RemoveTimeout"/> instead.
  492. /// </para>
  493. /// </remarks>
  494. ITimedEvents? TimedEvents { get; }
  495. #endregion Timeouts
  496. /// <summary>
  497. /// Gets a string representation of the Application as rendered by <see cref="Driver"/>.
  498. /// </summary>
  499. /// <returns>A string representation of the Application </returns>
  500. public string ToString ();
  501. }