IApplication.cs 25 KB

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