ViewDrawing.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. namespace Terminal.Gui;
  2. public partial class View
  3. {
  4. private ColorScheme _colorScheme;
  5. /// <summary>The color scheme for this view, if it is not defined, it returns the <see cref="SuperView"/>'s color scheme.</summary>
  6. public virtual ColorScheme ColorScheme
  7. {
  8. get
  9. {
  10. if (_colorScheme is null)
  11. {
  12. return SuperView?.ColorScheme;
  13. }
  14. return _colorScheme;
  15. }
  16. set
  17. {
  18. if (_colorScheme != value)
  19. {
  20. _colorScheme = value;
  21. SetNeedsDisplay ();
  22. }
  23. }
  24. }
  25. /// <summary>The canvas that any line drawing that is to be shared by subviews of this view should add lines to.</summary>
  26. /// <remarks><see cref="Border"/> adds border lines to this LineCanvas.</remarks>
  27. public LineCanvas LineCanvas { get; } = new ();
  28. // The view-relative region that needs to be redrawn. Marked internal for unit tests.
  29. internal Rectangle _needsDisplayRect = Rectangle.Empty;
  30. /// <summary>Gets or sets whether the view needs to be redrawn.</summary>
  31. public bool NeedsDisplay
  32. {
  33. get => _needsDisplayRect != Rectangle.Empty;
  34. set
  35. {
  36. if (value)
  37. {
  38. SetNeedsDisplay ();
  39. }
  40. else
  41. {
  42. ClearNeedsDisplay ();
  43. }
  44. }
  45. }
  46. /// <summary>Gets whether any Subviews need to be redrawn.</summary>
  47. public bool SubViewNeedsDisplay { get; private set; }
  48. /// <summary>
  49. /// Gets or sets whether this View will use it's SuperView's <see cref="LineCanvas"/> for rendering any border
  50. /// lines. If <see langword="true"/> the rendering of any borders drawn by this Frame will be done by its parent's
  51. /// SuperView. If <see langword="false"/> (the default) this View's <see cref="OnDrawAdornments"/> method will be
  52. /// called to render the borders.
  53. /// </summary>
  54. public virtual bool SuperViewRendersLineCanvas { get; set; } = false;
  55. /// <summary>Draws the specified character in the specified viewport-relative column and row of the View.</summary>
  56. /// <para>
  57. /// If the provided coordinates are outside the visible content area, this method does nothing.
  58. /// </para>
  59. /// <remarks>
  60. /// The top-left corner of the visible content area is <c>ViewPort.Location</c>.
  61. /// </remarks>
  62. /// <param name="col">Column (viewport-relative).</param>
  63. /// <param name="row">Row (viewport-relative).</param>
  64. /// <param name="rune">The Rune.</param>
  65. public void AddRune (int col, int row, Rune rune)
  66. {
  67. if (row < 0 || col < 0 || row >= Viewport.Height || col >= Viewport.Width)
  68. {
  69. // TODO: Change return type to bool so callers can determine success?
  70. return;
  71. }
  72. Move (col, row);
  73. Driver.AddRune (rune);
  74. }
  75. /// <summary>Clears <see cref="Viewport"/> with the normal background.</summary>
  76. /// <remarks></remarks>
  77. public void Clear () { Clear (Viewport); }
  78. /// <summary>Clears the specified <see cref="Viewport"/>-relative rectangle with the normal background.</summary>
  79. /// <remarks></remarks>
  80. /// <param name="viewport">The Viewport-relative rectangle to clear.</param>
  81. public void Clear (Rectangle viewport)
  82. {
  83. if (Driver is null)
  84. {
  85. return;
  86. }
  87. Attribute prev = Driver.SetAttribute (GetNormalColor ());
  88. // Clamp the region to the bounds of the view
  89. viewport = Rectangle.Intersect (viewport, Viewport);
  90. Driver.FillRect (ViewportToScreen (viewport));
  91. Driver.SetAttribute (prev);
  92. }
  93. /// <summary>Expands the <see cref="ConsoleDriver"/>'s clip region to include <see cref="Viewport"/>.</summary>
  94. /// <returns>
  95. /// The current screen-relative clip region, which can be then re-applied by setting
  96. /// <see cref="ConsoleDriver.Clip"/>.
  97. /// </returns>
  98. /// <remarks>
  99. /// <para>
  100. /// If <see cref="ConsoleDriver.Clip"/> and <see cref="Viewport"/> do not intersect, the clip region will be set to
  101. /// <see cref="Rectangle.Empty"/>.
  102. /// </para>
  103. /// </remarks>
  104. public Rectangle ClipToViewport ()
  105. {
  106. if (Driver is null)
  107. {
  108. return Rectangle.Empty;
  109. }
  110. Rectangle previous = Driver.Clip;
  111. Driver.Clip = Rectangle.Intersect (previous, ViewportToScreen (Viewport));
  112. return previous;
  113. }
  114. /// <summary>
  115. /// Draws the view. Causes the following virtual methods to be called (along with their related events):
  116. /// <see cref="OnDrawContent"/>, <see cref="OnDrawContentComplete"/>.
  117. /// </summary>
  118. /// <remarks>
  119. /// <para>
  120. /// Always use <see cref="Viewport"/> (view-relative) when calling <see cref="OnDrawContent(Rectangle)"/>, NOT
  121. /// <see cref="Frame"/> (superview-relative).
  122. /// </para>
  123. /// <para>
  124. /// Views should set the color that they want to use on entry, as otherwise this will inherit the last color that
  125. /// was set globally on the driver.
  126. /// </para>
  127. /// <para>
  128. /// Overrides of <see cref="OnDrawContent(Rectangle)"/> must ensure they do not set <c>Driver.Clip</c> to a clip
  129. /// region larger than the <ref name="Viewport"/> property, as this will cause the driver to clip the entire
  130. /// region.
  131. /// </para>
  132. /// </remarks>
  133. public void Draw ()
  134. {
  135. if (!CanBeVisible (this))
  136. {
  137. return;
  138. }
  139. OnDrawAdornments ();
  140. Rectangle prevClip = ClipToViewport ();
  141. if (ColorScheme is { })
  142. {
  143. //Driver.SetAttribute (HasFocus ? GetFocusColor () : GetNormalColor ());
  144. Driver?.SetAttribute (GetNormalColor ());
  145. }
  146. // Invoke DrawContentEvent
  147. var dev = new DrawEventArgs (Viewport);
  148. DrawContent?.Invoke (this, dev);
  149. if (!dev.Cancel)
  150. {
  151. OnDrawContent (Viewport);
  152. }
  153. if (Driver is { })
  154. {
  155. Driver.Clip = prevClip;
  156. }
  157. OnRenderLineCanvas ();
  158. // Invoke DrawContentCompleteEvent
  159. OnDrawContentComplete (Viewport);
  160. // BUGBUG: v2 - We should be able to use View.SetClip here and not have to resort to knowing Driver details.
  161. ClearLayoutNeeded ();
  162. ClearNeedsDisplay ();
  163. }
  164. /// <summary>Event invoked when the content area of the View is to be drawn.</summary>
  165. /// <remarks>
  166. /// <para>Will be invoked before any subviews added with <see cref="Add(View)"/> have been drawn.</para>
  167. /// <para>
  168. /// Rect provides the view-relative rectangle describing the currently visible viewport into the
  169. /// <see cref="View"/> .
  170. /// </para>
  171. /// </remarks>
  172. public event EventHandler<DrawEventArgs> DrawContent;
  173. /// <summary>Event invoked when the content area of the View is completed drawing.</summary>
  174. /// <remarks>
  175. /// <para>Will be invoked after any subviews removed with <see cref="Remove(View)"/> have been completed drawing.</para>
  176. /// <para>
  177. /// Rect provides the view-relative rectangle describing the currently visible viewport into the
  178. /// <see cref="View"/> .
  179. /// </para>
  180. /// </remarks>
  181. public event EventHandler<DrawEventArgs> DrawContentComplete;
  182. /// <summary>Utility function to draw strings that contain a hotkey.</summary>
  183. /// <param name="text">String to display, the hotkey specifier before a letter flags the next letter as the hotkey.</param>
  184. /// <param name="hotColor">Hot color.</param>
  185. /// <param name="normalColor">Normal color.</param>
  186. /// <remarks>
  187. /// <para>
  188. /// The hotkey is any character following the hotkey specifier, which is the underscore ('_') character by
  189. /// default.
  190. /// </para>
  191. /// <para>The hotkey specifier can be changed via <see cref="HotKeySpecifier"/></para>
  192. /// </remarks>
  193. public void DrawHotString (string text, Attribute hotColor, Attribute normalColor)
  194. {
  195. Rune hotkeySpec = HotKeySpecifier == (Rune)0xffff ? (Rune)'_' : HotKeySpecifier;
  196. Application.Driver.SetAttribute (normalColor);
  197. foreach (Rune rune in text.EnumerateRunes ())
  198. {
  199. if (rune == new Rune (hotkeySpec.Value))
  200. {
  201. Application.Driver.SetAttribute (hotColor);
  202. continue;
  203. }
  204. Application.Driver.AddRune (rune);
  205. Application.Driver.SetAttribute (normalColor);
  206. }
  207. }
  208. /// <summary>
  209. /// Utility function to draw strings that contains a hotkey using a <see cref="ColorScheme"/> and the "focused"
  210. /// state.
  211. /// </summary>
  212. /// <param name="text">String to display, the underscore before a letter flags the next letter as the hotkey.</param>
  213. /// <param name="focused">
  214. /// If set to <see langword="true"/> this uses the focused colors from the color scheme, otherwise
  215. /// the regular ones.
  216. /// </param>
  217. /// <param name="scheme">The color scheme to use.</param>
  218. public void DrawHotString (string text, bool focused, ColorScheme scheme)
  219. {
  220. if (focused)
  221. {
  222. DrawHotString (text, scheme.HotFocus, scheme.Focus);
  223. }
  224. else
  225. {
  226. DrawHotString (
  227. text,
  228. Enabled ? scheme.HotNormal : scheme.Disabled,
  229. Enabled ? scheme.Normal : scheme.Disabled
  230. );
  231. }
  232. }
  233. /// <summary>Determines the current <see cref="ColorScheme"/> based on the <see cref="Enabled"/> value.</summary>
  234. /// <returns>
  235. /// <see cref="ColorScheme.Focus"/> if <see cref="Enabled"/> is <see langword="true"/> or
  236. /// <see cref="ColorScheme.Disabled"/> if <see cref="Enabled"/> is <see langword="false"/>. If it's
  237. /// overridden can return other values.
  238. /// </returns>
  239. public virtual Attribute GetFocusColor ()
  240. {
  241. ColorScheme cs = ColorScheme;
  242. if (ColorScheme is null)
  243. {
  244. cs = new ();
  245. }
  246. return Enabled ? cs.Focus : cs.Disabled;
  247. }
  248. /// <summary>Determines the current <see cref="ColorScheme"/> based on the <see cref="Enabled"/> value.</summary>
  249. /// <returns>
  250. /// <see cref="Terminal.Gui.ColorScheme.HotNormal"/> if <see cref="Enabled"/> is <see langword="true"/> or
  251. /// <see cref="Terminal.Gui.ColorScheme.Disabled"/> if <see cref="Enabled"/> is <see langword="false"/>. If it's
  252. /// overridden can return other values.
  253. /// </returns>
  254. public virtual Attribute GetHotNormalColor ()
  255. {
  256. ColorScheme cs = ColorScheme;
  257. if (ColorScheme is null)
  258. {
  259. cs = new ();
  260. }
  261. return Enabled ? cs.HotNormal : cs.Disabled;
  262. }
  263. /// <summary>Determines the current <see cref="ColorScheme"/> based on the <see cref="Enabled"/> value.</summary>
  264. /// <returns>
  265. /// <see cref="Terminal.Gui.ColorScheme.Normal"/> if <see cref="Enabled"/> is <see langword="true"/> or
  266. /// <see cref="Terminal.Gui.ColorScheme.Disabled"/> if <see cref="Enabled"/> is <see langword="false"/>. If it's
  267. /// overridden can return other values.
  268. /// </returns>
  269. public virtual Attribute GetNormalColor ()
  270. {
  271. ColorScheme cs = ColorScheme;
  272. if (ColorScheme is null)
  273. {
  274. cs = new ();
  275. }
  276. return Enabled ? cs.Normal : cs.Disabled;
  277. }
  278. /// <summary>Moves the drawing cursor to the specified view-relative column and row in the view.</summary>
  279. /// <remarks>
  280. /// <para>
  281. /// If the provided coordinates are outside the visible content area, this method does nothing.
  282. /// </para>
  283. /// <para>
  284. /// The top-left corner of the visible content area is <c>ViewPort.Location</c>.
  285. /// </para>
  286. /// </remarks>
  287. /// <param name="col">Column (viewport-relative).</param>
  288. /// <param name="row">Row (viewport-relative).</param>
  289. public void Move (int col, int row)
  290. {
  291. if (Driver is null || Driver?.Rows == 0)
  292. {
  293. return;
  294. }
  295. if (col < 0 || row < 0 || col >= Viewport.Size.Width || row >= Viewport.Size.Height)
  296. {
  297. // TODO: Change return type to bool so callers can determine success?
  298. return;
  299. }
  300. Rectangle screen = ViewportToScreen (new (col, row, 0, 0));
  301. Driver?.Move (screen.X, screen.Y);
  302. }
  303. // TODO: Make this cancelable
  304. /// <summary>
  305. /// Prepares <see cref="View.LineCanvas"/>. If <see cref="SuperViewRendersLineCanvas"/> is true, only the
  306. /// <see cref="LineCanvas"/> of this view's subviews will be rendered. If <see cref="SuperViewRendersLineCanvas"/> is
  307. /// false (the default), this method will cause the <see cref="LineCanvas"/> be prepared to be rendered.
  308. /// </summary>
  309. /// <returns></returns>
  310. public virtual bool OnDrawAdornments ()
  311. {
  312. if (!IsInitialized)
  313. {
  314. return false;
  315. }
  316. // Each of these renders lines to either this View's LineCanvas
  317. // Those lines will be finally rendered in OnRenderLineCanvas
  318. Margin?.OnDrawContent (Margin.Viewport);
  319. Border?.OnDrawContent (Border.Viewport);
  320. Padding?.OnDrawContent (Padding.Viewport);
  321. return true;
  322. }
  323. /// <summary>
  324. /// Draws the view's content, including Subviews.
  325. /// </summary>
  326. /// <remarks>
  327. /// <para>
  328. /// The <paramref name="viewport"/> parameter is provided as a convenience; it has the same values as the
  329. /// <see cref="Viewport"/> property.
  330. /// </para>
  331. /// <para>
  332. /// The <see cref="Viewport"/> Location and Size indicate what part of the View's virtual content area, defined
  333. /// by <see cref="ContentSize"/>, is visible and should be drawn. The coordinates taken by <see cref="Move"/> and
  334. /// <see cref="AddRune"/> are relative to <see cref="Viewport"/>, thus if <c>ViewPort.Location.Y</c> is <c>5</c>
  335. /// the 6th row of the content should be drawn using <c>MoveTo (x, 5)</c>.
  336. /// </para>
  337. /// <para>
  338. /// If <see cref="ContentSize"/> is larger than <c>ViewPort.Size</c> drawing code should use <see cref="Viewport"/>
  339. /// to constrain drawing for better performance.
  340. /// </para>
  341. /// <para>
  342. /// The <see cref="Clip"/> may define smaller area than <see cref="Viewport"/>; complex drawing code can be more
  343. /// efficient by using <see cref="Clip"/> to constrain drawing for better performance.
  344. /// </para>
  345. /// <para>
  346. /// Overrides should loop through the subviews and call <see cref="Draw"/>.
  347. /// </para>
  348. /// </remarks>
  349. /// <param name="viewport">
  350. /// The rectangle describing the currently visible viewport into the <see cref="View"/>; has the same value as
  351. /// <see cref="Viewport"/>.
  352. /// </param>
  353. public virtual void OnDrawContent (Rectangle viewport)
  354. {
  355. if (NeedsDisplay)
  356. {
  357. if (SuperView is { })
  358. {
  359. Clear (viewport);
  360. }
  361. if (!string.IsNullOrEmpty (TextFormatter.Text))
  362. {
  363. if (TextFormatter is { })
  364. {
  365. TextFormatter.NeedsFormat = true;
  366. }
  367. }
  368. // This should NOT clear
  369. TextFormatter?.Draw (
  370. ViewportToScreen (viewport),
  371. HasFocus ? GetFocusColor () : GetNormalColor (),
  372. HasFocus ? ColorScheme.HotFocus : GetHotNormalColor (),
  373. Rectangle.Empty
  374. );
  375. SetSubViewNeedsDisplay ();
  376. }
  377. // TODO: Move drawing of subviews to a separate OnDrawSubviews virtual method
  378. // Draw subviews
  379. // TODO: Implement OnDrawSubviews (cancelable);
  380. if (_subviews is { } && SubViewNeedsDisplay)
  381. {
  382. IEnumerable<View> subviewsNeedingDraw = _subviews.Where (
  383. view => view.Visible
  384. && (view.NeedsDisplay || view.SubViewNeedsDisplay || view.LayoutNeeded)
  385. );
  386. foreach (View view in subviewsNeedingDraw)
  387. {
  388. //view.Frame.IntersectsWith (bounds)) {
  389. // && (view.Frame.IntersectsWith (bounds) || bounds.X < 0 || bounds.Y < 0)) {
  390. if (view.LayoutNeeded)
  391. {
  392. view.LayoutSubviews ();
  393. }
  394. // Draw the subview
  395. // Use the view's bounds (view-relative; Location will always be (0,0)
  396. //if (view.Visible && view.Frame.Width > 0 && view.Frame.Height > 0) {
  397. view.Draw ();
  398. //}
  399. }
  400. }
  401. }
  402. /// <summary>
  403. /// Called after <see cref="OnDrawContent"/> to enable overrides.
  404. /// </summary>
  405. /// <param name="viewport">
  406. /// The viewport-relative rectangle describing the currently visible viewport into the
  407. /// <see cref="View"/>
  408. /// </param>
  409. public virtual void OnDrawContentComplete (Rectangle viewport) { DrawContentComplete?.Invoke (this, new (viewport)); }
  410. // TODO: Make this cancelable
  411. /// <summary>
  412. /// Renders <see cref="View.LineCanvas"/>. If <see cref="SuperViewRendersLineCanvas"/> is true, only the
  413. /// <see cref="LineCanvas"/> of this view's subviews will be rendered. If <see cref="SuperViewRendersLineCanvas"/> is
  414. /// false (the default), this method will cause the <see cref="LineCanvas"/> to be rendered.
  415. /// </summary>
  416. /// <returns></returns>
  417. public virtual bool OnRenderLineCanvas ()
  418. {
  419. if (!IsInitialized)
  420. {
  421. return false;
  422. }
  423. // If we have a SuperView, it'll render our frames.
  424. if (!SuperViewRendersLineCanvas && LineCanvas.Viewport != Rectangle.Empty)
  425. {
  426. foreach (KeyValuePair<Point, Cell> p in LineCanvas.GetCellMap ())
  427. {
  428. // Get the entire map
  429. Driver.SetAttribute (p.Value.Attribute ?? ColorScheme.Normal);
  430. Driver.Move (p.Key.X, p.Key.Y);
  431. // TODO: #2616 - Support combining sequences that don't normalize
  432. Driver.AddRune (p.Value.Rune);
  433. }
  434. LineCanvas.Clear ();
  435. }
  436. if (Subviews.Any (s => s.SuperViewRendersLineCanvas))
  437. {
  438. foreach (View subview in Subviews.Where (s => s.SuperViewRendersLineCanvas))
  439. {
  440. // Combine the LineCanvas'
  441. LineCanvas.Merge (subview.LineCanvas);
  442. subview.LineCanvas.Clear ();
  443. }
  444. foreach (KeyValuePair<Point, Cell> p in LineCanvas.GetCellMap ())
  445. {
  446. // Get the entire map
  447. Driver.SetAttribute (p.Value.Attribute ?? ColorScheme.Normal);
  448. Driver.Move (p.Key.X, p.Key.Y);
  449. // TODO: #2616 - Support combining sequences that don't normalize
  450. Driver.AddRune (p.Value.Rune);
  451. }
  452. LineCanvas.Clear ();
  453. }
  454. return true;
  455. }
  456. /// <summary>Sets the area of this view needing to be redrawn to <see cref="Viewport"/>.</summary>
  457. /// <remarks>
  458. /// If the view has not been initialized (<see cref="IsInitialized"/> is <see langword="false"/>), this method
  459. /// does nothing.
  460. /// </remarks>
  461. public void SetNeedsDisplay ()
  462. {
  463. if (IsInitialized)
  464. {
  465. SetNeedsDisplay (Viewport);
  466. }
  467. }
  468. /// <summary>Expands the area of this view needing to be redrawn to include <paramref name="region"/>.</summary>
  469. /// <remarks>
  470. /// <para>
  471. /// The location of <see cref="region"/> are relative to the View's content, bound by <c>Size.Empty</c> and
  472. /// <see cref="ContentSize"/>.
  473. /// </para>
  474. /// <para>
  475. /// If the view has not been initialized (<see cref="IsInitialized"/> is <see langword="false"/>), the area to be
  476. /// redrawn will be the <paramref name="region"/>.
  477. /// </para>
  478. /// </remarks>
  479. /// <param name="region">The content-relative region that needs to be redrawn.</param>
  480. public virtual void SetNeedsDisplay (Rectangle region)
  481. {
  482. if (!IsInitialized)
  483. {
  484. _needsDisplayRect = region;
  485. return;
  486. }
  487. if (_needsDisplayRect.IsEmpty)
  488. {
  489. _needsDisplayRect = region;
  490. }
  491. else
  492. {
  493. int x = Math.Min (_needsDisplayRect.X, region.X);
  494. int y = Math.Min (_needsDisplayRect.Y, region.Y);
  495. int w = Math.Max (_needsDisplayRect.Width, region.Width);
  496. int h = Math.Max (_needsDisplayRect.Height, region.Height);
  497. _needsDisplayRect = new (x, y, w, h);
  498. }
  499. SuperView?.SetSubViewNeedsDisplay ();
  500. Margin?.SetNeedsDisplay ();
  501. Border?.SetNeedsDisplay ();
  502. Padding?.SetNeedsDisplay ();
  503. foreach (View subview in Subviews)
  504. {
  505. if (subview.Frame.IntersectsWith (region))
  506. {
  507. Rectangle subviewRegion = Rectangle.Intersect (subview.Frame, region);
  508. subviewRegion.X -= subview.Frame.X;
  509. subviewRegion.Y -= subview.Frame.Y;
  510. subview.SetNeedsDisplay (subviewRegion);
  511. }
  512. }
  513. }
  514. /// <summary>Sets <see cref="SubViewNeedsDisplay"/> to <see langword="true"/> for this View and all Superviews.</summary>
  515. public void SetSubViewNeedsDisplay ()
  516. {
  517. SubViewNeedsDisplay = true;
  518. if (SuperView is { } && !SuperView.SubViewNeedsDisplay)
  519. {
  520. SuperView.SetSubViewNeedsDisplay ();
  521. }
  522. }
  523. /// <summary>Clears <see cref="NeedsDisplay"/> and <see cref="SubViewNeedsDisplay"/>.</summary>
  524. protected void ClearNeedsDisplay ()
  525. {
  526. _needsDisplayRect = Rectangle.Empty;
  527. SubViewNeedsDisplay = false;
  528. Margin?.ClearNeedsDisplay ();
  529. Border?.ClearNeedsDisplay ();
  530. Padding?.ClearNeedsDisplay ();
  531. foreach (View subview in Subviews)
  532. {
  533. subview.ClearNeedsDisplay();
  534. }
  535. }
  536. }