View.Drawing.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. #nullable enable
  2. #define HACK_DRAW_OVERLAPPED
  3. using System.ComponentModel;
  4. using System.Diagnostics;
  5. namespace Terminal.Gui;
  6. public partial class View // Drawing APIs
  7. {
  8. /// <summary>
  9. /// Draws the view if it needs to be drawn.
  10. /// </summary>
  11. /// <remarks>
  12. /// <para>
  13. /// The view will only be drawn if it is visible, and has any of <see cref="NeedsDraw"/>,
  14. /// <see cref="SubViewNeedsDraw"/>,
  15. /// or <see cref="NeedsLayout"/> set.
  16. /// </para>
  17. /// <para>
  18. /// // TODO: Add docs for the drawing process.
  19. /// </para>
  20. /// </remarks>
  21. public void Draw ()
  22. {
  23. if (!CanBeVisible (this) || (!NeedsDraw && !SubViewNeedsDraw))
  24. {
  25. return;
  26. }
  27. DoDrawAdornments ();
  28. DoSetAttribute ();
  29. // By default, we clip to the viewport preventing drawing outside the viewport
  30. // We also clip to the content, but if a developer wants to draw outside the viewport, they can do
  31. // so via settings. SetClip honors the ViewportSettings.DisableVisibleContentClipping flag.
  32. Region prevClip = SetClip ();
  33. DoClearViewport (Viewport);
  34. DoDrawText (Viewport);
  35. DoDrawContent (Viewport);
  36. DoDrawSubviews (Viewport);
  37. // Restore the clip before rendering the line canvas and adornment subviews
  38. // because they may draw outside the viewport.
  39. if (Driver is { })
  40. {
  41. Driver.Clip = prevClip;
  42. }
  43. DoRenderLineCanvas ();
  44. DoDrawAdornmentSubViews ();
  45. ClearNeedsDraw ();
  46. // We're done
  47. DoDrawComplete ();
  48. }
  49. #region DrawAdornments
  50. private void DoDrawAdornmentSubViews ()
  51. {
  52. // This causes the Adornment's subviews to be REDRAWN
  53. // TODO: Figure out how to make this more efficient
  54. if (Margin?.Subviews is { })
  55. {
  56. foreach (View subview in Margin.Subviews)
  57. {
  58. subview.SetNeedsDraw ();
  59. }
  60. Margin?.DoDrawSubviews (Margin.Viewport);
  61. }
  62. if (Border?.Subviews is { })
  63. {
  64. foreach (View subview in Border.Subviews)
  65. {
  66. subview.SetNeedsDraw ();
  67. }
  68. Border?.DoDrawSubviews (Border.Viewport);
  69. }
  70. if (Padding?.Subviews is { })
  71. {
  72. foreach (View subview in Padding.Subviews)
  73. {
  74. subview.SetNeedsDraw ();
  75. }
  76. Padding?.DoDrawSubviews (Padding.Viewport);
  77. }
  78. }
  79. private void DoDrawAdornments ()
  80. {
  81. if (OnDrawingAdornments ())
  82. {
  83. return;
  84. }
  85. // TODO: add event.
  86. // Subviews of Adornments count as subviews
  87. if (!NeedsDraw && !SubViewNeedsDraw)
  88. {
  89. return;
  90. }
  91. DrawAdornments ();
  92. }
  93. /// <summary>
  94. /// Causes each of the View's Adornments to be drawn. This includes the <see cref="Margin"/>, <see cref="Border"/>, and <see cref="Padding"/>.
  95. /// </summary>
  96. public void DrawAdornments ()
  97. {
  98. // Each of these renders lines to either this View's LineCanvas
  99. // Those lines will be finally rendered in OnRenderLineCanvas
  100. Margin?.Draw ();
  101. Border?.Draw ();
  102. Padding?.Draw ();
  103. }
  104. /// <summary>
  105. /// Called when the View's Adornments are to be drawn. Prepares <see cref="View.LineCanvas"/>. If
  106. /// <see cref="SuperViewRendersLineCanvas"/> is true, only the
  107. /// <see cref="LineCanvas"/> of this view's subviews will be rendered. If <see cref="SuperViewRendersLineCanvas"/> is
  108. /// false (the default), this method will cause the <see cref="LineCanvas"/> be prepared to be rendered.
  109. /// </summary>
  110. /// <returns><see langword="true"/> to stop further drawing of the Adornments.</returns>
  111. protected virtual bool OnDrawingAdornments () { return false; }
  112. #endregion DrawAdornments
  113. #region SetAttribute
  114. private void DoSetAttribute ()
  115. {
  116. if (OnSettingAttribute ())
  117. {
  118. return;
  119. }
  120. var args = new CancelEventArgs ();
  121. SettingAttribute?.Invoke (this, args);
  122. if (args.Cancel)
  123. {
  124. return;
  125. }
  126. if (!NeedsDraw && !SubViewNeedsDraw)
  127. {
  128. return;
  129. }
  130. SetNormalAttribute ();
  131. }
  132. /// <summary>
  133. /// Called when the normal attribute for the View is to be set. This is called before the View is drawn.
  134. /// </summary>
  135. /// <returns><see langword="true"/> to stop default behavior.</returns>
  136. protected virtual bool OnSettingAttribute () { return false; }
  137. /// <summary>Raised when the normal attribute for the View is to be set. This is raised before the View is drawn.</summary>
  138. /// <returns>
  139. /// Set <see cref="CancelEventArgs.Cancel"/> to <see langword="true"/> to stop default behavior.
  140. /// </returns>
  141. public event EventHandler<CancelEventArgs>? SettingAttribute;
  142. /// <summary>
  143. /// Sets the attribute for the View. This is called before the View is drawn.
  144. /// </summary>
  145. public void SetNormalAttribute ()
  146. {
  147. if (ColorScheme is { })
  148. {
  149. SetAttribute (GetNormalColor ());
  150. }
  151. }
  152. #endregion
  153. #region ClearViewport
  154. private void DoClearViewport (Rectangle viewport)
  155. {
  156. Debug.Assert (viewport == Viewport);
  157. if (OnClearingViewport (Viewport))
  158. {
  159. return;
  160. }
  161. var dev = new DrawEventArgs (Viewport, Rectangle.Empty);
  162. ClearingViewport?.Invoke (this, dev);
  163. if (dev.Cancel)
  164. {
  165. return;
  166. }
  167. if (!NeedsDraw)
  168. {
  169. return;
  170. }
  171. ClearViewport ();
  172. }
  173. /// <summary>
  174. /// Called when the <see cref="Viewport"/> is to be cleared.
  175. /// </summary>
  176. /// <param name="viewport"></param>
  177. /// <returns><see langword="true"/> to stop further clearing.</returns>
  178. protected virtual bool OnClearingViewport (Rectangle viewport) { return false; }
  179. /// <summary>Event invoked when the content area of the View is to be drawn.</summary>
  180. /// <remarks>
  181. /// <para>Will be invoked before any subviews added with <see cref="Add(View)"/> have been drawn.</para>
  182. /// <para>
  183. /// Rect provides the view-relative rectangle describing the currently visible viewport into the
  184. /// <see cref="View"/> .
  185. /// </para>
  186. /// </remarks>
  187. public event EventHandler<DrawEventArgs>? ClearingViewport;
  188. /// <summary>Clears <see cref="Viewport"/> with the normal background.</summary>
  189. /// <remarks>
  190. /// <para>
  191. /// If <see cref="ViewportSettings"/> has <see cref="Gui.ViewportSettings.ClearContentOnly"/> only
  192. /// the portion of the content
  193. /// area that is visible within the <see cref="View.Viewport"/> will be cleared. This is useful for views that have
  194. /// a
  195. /// content area larger than the Viewport (e.g. when <see cref="ViewportSettings.AllowNegativeLocation"/> is
  196. /// enabled) and want
  197. /// the area outside the content to be visually distinct.
  198. /// </para>
  199. /// </remarks>
  200. public void ClearViewport ()
  201. {
  202. if (Driver is null)
  203. {
  204. return;
  205. }
  206. // Get screen-relative coords
  207. Rectangle toClear = ViewportToScreen (Viewport with { Location = new (0, 0) });
  208. if (ViewportSettings.HasFlag (ViewportSettings.ClearContentOnly))
  209. {
  210. Rectangle visibleContent = ViewportToScreen (new Rectangle (new (-Viewport.X, -Viewport.Y), GetContentSize ()));
  211. toClear = Rectangle.Intersect (toClear, visibleContent);
  212. }
  213. Attribute prev = SetAttribute (GetNormalColor ());
  214. Driver.FillRect (toClear);
  215. SetAttribute (prev);
  216. SetNeedsDraw ();
  217. }
  218. #endregion ClearViewport
  219. #region DrawText
  220. private void DoDrawText (Rectangle viewport)
  221. {
  222. Debug.Assert (viewport == Viewport);
  223. if (OnDrawingText (Viewport))
  224. {
  225. return;
  226. }
  227. var dev = new DrawEventArgs (Viewport, Rectangle.Empty);
  228. DrawingText?.Invoke (this, dev);
  229. if (dev.Cancel)
  230. {
  231. return;
  232. }
  233. if (!NeedsDraw)
  234. {
  235. return;
  236. }
  237. DrawText ();
  238. }
  239. /// <summary>
  240. /// Called when the <see cref="Text"/> of the View is to be drawn.
  241. /// </summary>
  242. /// <param name="viewport"></param>
  243. /// <returns><see langword="true"/> to stop further drawing of <see cref="Text"/>.</returns>
  244. protected virtual bool OnDrawingText (Rectangle viewport) { return false; }
  245. /// <summary>Raised when the <see cref="Text"/> of the View is to be drawn.</summary>
  246. /// <returns>
  247. /// Set <see cref="DrawEventArgs.Cancel"/> to <see langword="true"/> to stop further drawing of
  248. /// <see cref="Text"/>.
  249. /// </returns>
  250. public event EventHandler<DrawEventArgs>? DrawingText;
  251. /// <summary>
  252. /// Draws the <see cref="Text"/> of the View using the <see cref="TextFormatter"/>.
  253. /// </summary>
  254. public void DrawText ()
  255. {
  256. if (!string.IsNullOrEmpty (TextFormatter.Text))
  257. {
  258. TextFormatter.NeedsFormat = true;
  259. }
  260. // This should NOT clear
  261. // TODO: If the output is not in the Viewport, do nothing
  262. var drawRect = new Rectangle (ContentToScreen (Point.Empty), GetContentSize ());
  263. TextFormatter?.Draw (
  264. drawRect,
  265. HasFocus ? GetFocusColor () : GetNormalColor (),
  266. HasFocus ? GetHotFocusColor () : GetHotNormalColor (),
  267. Rectangle.Empty
  268. );
  269. // We assume that the text has been drawn over the entire area; ensure that the subviews are redrawn.
  270. SetSubViewNeedsDraw ();
  271. }
  272. #endregion DrawText
  273. #region DrawContent
  274. private void DoDrawContent (Rectangle viewport)
  275. {
  276. Debug.Assert (viewport == Viewport);
  277. if (OnDrawingContent (Viewport))
  278. {
  279. return;
  280. }
  281. var dev = new DrawEventArgs (Viewport, Rectangle.Empty);
  282. DrawingContent?.Invoke (this, dev);
  283. if (dev.Cancel)
  284. { }
  285. // Do nothing.
  286. }
  287. /// <summary>
  288. /// Called when the View's content is to be drawn. The default implementation does nothing.
  289. /// </summary>
  290. /// <remarks>
  291. /// </remarks>
  292. /// <returns><see langword="true"/> to stop further drawing content.</returns>
  293. protected virtual bool OnDrawingContent (Rectangle viewport) { return false; }
  294. /// <summary>Raised when the View's content is to be drawn.</summary>
  295. /// <remarks>
  296. /// <para>Will be invoked before any subviews added with <see cref="Add(View)"/> have been drawn.</para>
  297. /// <para>
  298. /// Rect provides the view-relative rectangle describing the currently visible viewport into the
  299. /// <see cref="View"/> .
  300. /// </para>
  301. /// </remarks>
  302. public event EventHandler<DrawEventArgs>? DrawingContent;
  303. #endregion DrawContent
  304. #region DrawSubviews
  305. private void DoDrawSubviews (Rectangle viewport)
  306. {
  307. Debug.Assert (viewport == Viewport);
  308. if (OnDrawingSubviews (Viewport))
  309. {
  310. return;
  311. }
  312. var dev = new DrawEventArgs (Viewport, Rectangle.Empty);
  313. DrawingSubviews?.Invoke (this, dev);
  314. if (dev.Cancel)
  315. {
  316. return;
  317. }
  318. if (!SubViewNeedsDraw)
  319. {
  320. return;
  321. }
  322. DrawSubviews ();
  323. }
  324. /// <summary>
  325. /// Called when the <see cref="Subviews"/> are to be drawn.
  326. /// </summary>
  327. /// <param name="viewport"></param>
  328. /// <returns><see langword="true"/> to stop further drawing of <see cref="Subviews"/>.</returns>
  329. protected virtual bool OnDrawingSubviews (Rectangle viewport) { return false; }
  330. /// <summary>Raised when the <see cref="Subviews"/> are to be drawn.</summary>
  331. /// <remarks>
  332. /// </remarks>
  333. /// <returns>
  334. /// Set <see cref="DrawEventArgs.Cancel"/> to <see langword="true"/> to stop further drawing of
  335. /// <see cref="Subviews"/>.
  336. /// </returns>
  337. public event EventHandler<DrawEventArgs>? DrawingSubviews;
  338. /// <summary>
  339. /// Draws the <see cref="Subviews"/>.
  340. /// </summary>
  341. public void DrawSubviews ()
  342. {
  343. if (_subviews is null || !SubViewNeedsDraw)
  344. {
  345. return;
  346. }
  347. #if HACK_DRAW_OVERLAPPED
  348. IEnumerable<View> subviewsNeedingDraw = _subviews.Where (view => (view.Visible && (view.NeedsDraw || view.SubViewNeedsDraw))
  349. || view.Arrangement.HasFlag (ViewArrangement.Overlapped));
  350. #else
  351. IEnumerable<View> subviewsNeedingDraw = _subviews.Where (view => (view.Visible && (view.NeedsDraw || view.SubViewNeedsDraw)));
  352. #endif
  353. foreach (View view in subviewsNeedingDraw)
  354. {
  355. #if HACK_DRAW_OVERLAPPED
  356. if (view.Arrangement.HasFlag (ViewArrangement.Overlapped))
  357. {
  358. view.SetNeedsDraw ();
  359. }
  360. #endif
  361. view.Draw ();
  362. }
  363. }
  364. #endregion DrawSubviews
  365. #region DrawLineCanvas
  366. private void DoRenderLineCanvas ()
  367. {
  368. if (OnRenderingLineCanvas ())
  369. {
  370. return;
  371. }
  372. // TODO: Add event
  373. RenderLineCanvas ();
  374. }
  375. /// <summary>
  376. /// Called when the <see cref="View.LineCanvas"/> is to be rendered. See <see cref="RenderLineCanvas"/>.
  377. /// </summary>
  378. /// <returns><see langword="true"/> to stop further drawing of <see cref="LineCanvas"/>.</returns>
  379. protected virtual bool OnRenderingLineCanvas () { return false; }
  380. /// <summary>The canvas that any line drawing that is to be shared by subviews of this view should add lines to.</summary>
  381. /// <remarks><see cref="Border"/> adds border lines to this LineCanvas.</remarks>
  382. public LineCanvas LineCanvas { get; } = new ();
  383. /// <summary>
  384. /// Gets or sets whether this View will use it's SuperView's <see cref="LineCanvas"/> for rendering any
  385. /// lines. If <see langword="true"/> the rendering of any borders drawn by this Frame will be done by its parent's
  386. /// SuperView. If <see langword="false"/> (the default) this View's <see cref="OnDrawingAdornments"/> method will be
  387. /// called to render the borders.
  388. /// </summary>
  389. public virtual bool SuperViewRendersLineCanvas { get; set; } = false;
  390. /// <summary>
  391. /// Causes the contents of <see cref="LineCanvas"/> to be drawn.
  392. /// If <see cref="SuperViewRendersLineCanvas"/> is true, only the
  393. /// <see cref="LineCanvas"/> of this view's subviews will be rendered. If <see cref="SuperViewRendersLineCanvas"/> is
  394. /// false (the default), this method will cause the <see cref="LineCanvas"/> to be rendered.
  395. /// </summary>
  396. public void RenderLineCanvas ()
  397. {
  398. // TODO: This is super confusing and needs to be refactored.
  399. if (Driver is null)
  400. {
  401. return;
  402. }
  403. // If we have a SuperView, it'll render our frames.
  404. if (!SuperViewRendersLineCanvas && LineCanvas.Viewport != Rectangle.Empty)
  405. {
  406. foreach (KeyValuePair<Point, Cell?> p in LineCanvas.GetCellMap ())
  407. {
  408. // Get the entire map
  409. if (p.Value is { })
  410. {
  411. SetAttribute (p.Value.Value.Attribute ?? ColorScheme!.Normal);
  412. Driver.Move (p.Key.X, p.Key.Y);
  413. // TODO: #2616 - Support combining sequences that don't normalize
  414. Driver.AddRune (p.Value.Value.Rune);
  415. }
  416. }
  417. LineCanvas.Clear ();
  418. }
  419. if (Subviews.Any (s => s.SuperViewRendersLineCanvas))
  420. {
  421. foreach (View subview in Subviews.Where (s => s.SuperViewRendersLineCanvas))
  422. {
  423. // Combine the LineCanvas'
  424. LineCanvas.Merge (subview.LineCanvas);
  425. subview.LineCanvas.Clear ();
  426. }
  427. foreach (KeyValuePair<Point, Cell?> p in LineCanvas.GetCellMap ())
  428. {
  429. // Get the entire map
  430. if (p.Value is { })
  431. {
  432. SetAttribute (p.Value.Value.Attribute ?? ColorScheme!.Normal);
  433. Driver.Move (p.Key.X, p.Key.Y);
  434. // TODO: #2616 - Support combining sequences that don't normalize
  435. Driver.AddRune (p.Value.Value.Rune);
  436. }
  437. }
  438. LineCanvas.Clear ();
  439. }
  440. }
  441. #endregion DrawLineCanvas
  442. #region DrawComplete
  443. private void DoDrawComplete ()
  444. {
  445. OnDrawComplete ();
  446. DrawComplete?.Invoke (this, EventArgs.Empty);
  447. // Default implementation does nothing.
  448. }
  449. /// <summary>
  450. /// Called when the View is completed drawing.
  451. /// </summary>
  452. protected virtual void OnDrawComplete () { }
  453. /// <summary>Raised when the View is completed drawing.</summary>
  454. /// <remarks>
  455. /// </remarks>
  456. public event EventHandler<EventArgs>? DrawComplete;
  457. #endregion DrawComplete
  458. #region NeedsDraw
  459. // TODO: Make _needsDrawRect nullable instead of relying on Empty
  460. // TODO: If null, it means ?
  461. // TODO: If Empty, it means no need to redraw
  462. // TODO: If not Empty, it means the region that needs to be redrawn
  463. // The viewport-relative region that needs to be redrawn. Marked internal for unit tests.
  464. internal Rectangle _needsDrawRect = Rectangle.Empty;
  465. /// <summary>Gets or sets whether the view needs to be redrawn.</summary>
  466. /// <remarks>
  467. /// <para>
  468. /// Will be <see langword="true"/> if the <see cref="NeedsLayout"/> property is <see langword="true"/> or if
  469. /// any part of the view's <see cref="Viewport"/> needs to be redrawn.
  470. /// </para>
  471. /// <para>
  472. /// Setting has no effect on <see cref="NeedsLayout"/>.
  473. /// </para>
  474. /// </remarks>
  475. public bool NeedsDraw
  476. {
  477. // TODO: Figure out if we can decouple NeedsDraw from NeedsLayout. This is a temporary fix.
  478. get => _needsDrawRect != Rectangle.Empty || NeedsLayout;
  479. set
  480. {
  481. if (value)
  482. {
  483. SetNeedsDraw ();
  484. }
  485. else
  486. {
  487. ClearNeedsDraw ();
  488. }
  489. }
  490. }
  491. /// <summary>Gets whether any Subviews need to be redrawn.</summary>
  492. public bool SubViewNeedsDraw { get; private set; }
  493. /// <summary>Sets that the <see cref="Viewport"/> of this View needs to be redrawn.</summary>
  494. /// <remarks>
  495. /// If the view has not been initialized (<see cref="IsInitialized"/> is <see langword="false"/>), this method
  496. /// does nothing.
  497. /// </remarks>
  498. public void SetNeedsDraw ()
  499. {
  500. Rectangle viewport = Viewport;
  501. if (_needsDrawRect != Rectangle.Empty && viewport.IsEmpty)
  502. {
  503. // This handles the case where the view has not been initialized yet
  504. return;
  505. }
  506. SetNeedsDraw (viewport);
  507. }
  508. /// <summary>Expands the area of this view needing to be redrawn to include <paramref name="viewPortRelativeRegion"/>.</summary>
  509. /// <remarks>
  510. /// <para>
  511. /// The location of <paramref name="viewPortRelativeRegion"/> is relative to the View's <see cref="Viewport"/>.
  512. /// </para>
  513. /// <para>
  514. /// If the view has not been initialized (<see cref="IsInitialized"/> is <see langword="false"/>), the area to be
  515. /// redrawn will be the <paramref name="viewPortRelativeRegion"/>.
  516. /// </para>
  517. /// </remarks>
  518. /// <param name="viewPortRelativeRegion">The <see cref="Viewport"/>relative region that needs to be redrawn.</param>
  519. public void SetNeedsDraw (Rectangle viewPortRelativeRegion)
  520. {
  521. if (_needsDrawRect.IsEmpty)
  522. {
  523. _needsDrawRect = viewPortRelativeRegion;
  524. }
  525. else
  526. {
  527. int x = Math.Min (Viewport.X, viewPortRelativeRegion.X);
  528. int y = Math.Min (Viewport.Y, viewPortRelativeRegion.Y);
  529. int w = Math.Max (Viewport.Width, viewPortRelativeRegion.Width);
  530. int h = Math.Max (Viewport.Height, viewPortRelativeRegion.Height);
  531. _needsDrawRect = new (x, y, w, h);
  532. }
  533. Margin?.SetNeedsDraw ();
  534. Border?.SetNeedsDraw ();
  535. Padding?.SetNeedsDraw ();
  536. SuperView?.SetSubViewNeedsDraw ();
  537. if (this is Adornment adornment)
  538. {
  539. adornment.Parent?.SetSubViewNeedsDraw ();
  540. }
  541. foreach (View subview in Subviews)
  542. {
  543. if (subview.Frame.IntersectsWith (viewPortRelativeRegion))
  544. {
  545. Rectangle subviewRegion = Rectangle.Intersect (subview.Frame, viewPortRelativeRegion);
  546. subviewRegion.X -= subview.Frame.X;
  547. subviewRegion.Y -= subview.Frame.Y;
  548. subview.SetNeedsDraw (subviewRegion);
  549. }
  550. }
  551. }
  552. /// <summary>Sets <see cref="SubViewNeedsDraw"/> to <see langword="true"/> for this View and all Superviews.</summary>
  553. public void SetSubViewNeedsDraw ()
  554. {
  555. SubViewNeedsDraw = true;
  556. if (this is Adornment adornment)
  557. {
  558. adornment.Parent?.SetSubViewNeedsDraw ();
  559. }
  560. if (SuperView is { SubViewNeedsDraw: false })
  561. {
  562. SuperView.SetSubViewNeedsDraw ();
  563. }
  564. }
  565. /// <summary>Clears <see cref="NeedsDraw"/> and <see cref="SubViewNeedsDraw"/>.</summary>
  566. protected void ClearNeedsDraw ()
  567. {
  568. _needsDrawRect = Rectangle.Empty;
  569. SubViewNeedsDraw = false;
  570. Margin?.ClearNeedsDraw ();
  571. Border?.ClearNeedsDraw ();
  572. Padding?.ClearNeedsDraw ();
  573. foreach (View subview in Subviews)
  574. {
  575. subview.ClearNeedsDraw ();
  576. }
  577. }
  578. #endregion NeedsDraw
  579. }