IApplication.cs 25 KB

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