2
0

ScrollView.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. //
  2. // ScrollView.cs: ScrollView view.
  3. //
  4. // Authors:
  5. // Miguel de Icaza ([email protected])
  6. //
  7. //
  8. // TODO:
  9. // - focus in scrollview
  10. // - focus handling in scrollview to auto scroll to focused view
  11. // - Raise events
  12. // - Perhaps allow an option to not display the scrollbar arrow indicators?
  13. using System;
  14. using System.Linq;
  15. namespace Terminal.Gui;
  16. /// <summary>
  17. /// Scrollviews are views that present a window into a virtual space where subviews are added. Similar to the iOS UIScrollView.
  18. /// </summary>
  19. /// <remarks>
  20. /// <para>
  21. /// The subviews that are added to this <see cref="Gui.ScrollView"/> are offset by the
  22. /// <see cref="ContentOffset"/> property. The view itself is a window into the
  23. /// space represented by the <see cref="ContentSize"/>.
  24. /// </para>
  25. /// <para>
  26. /// Use the
  27. /// </para>
  28. /// </remarks>
  29. public class ScrollView : View {
  30. // The ContentView is the view that contains the subviews and content that are being scrolled
  31. // The ContentView is the size of the ContentSize and is offset by the ContentOffset
  32. private class ContentView : View {
  33. public ContentView (Rect frame) : base (frame)
  34. {
  35. Id = "ScrollView.ContentView";
  36. CanFocus = true;
  37. }
  38. }
  39. ContentView _contentView;
  40. ScrollBarView _vertical, _horizontal;
  41. /// <summary>
  42. /// Initializes a new instance of the <see cref="Gui.ScrollView"/> class using <see cref="LayoutStyle.Absolute"/> positioning.
  43. /// </summary>
  44. /// <param name="frame"></param>
  45. public ScrollView (Rect frame) : base (frame)
  46. {
  47. SetInitialProperties (frame);
  48. }
  49. /// <summary>
  50. /// Initializes a new instance of the <see cref="Gui.ScrollView"/> class using <see cref="LayoutStyle.Computed"/> positioning.
  51. /// </summary>
  52. public ScrollView () : base ()
  53. {
  54. SetInitialProperties (Rect.Empty);
  55. }
  56. void SetInitialProperties (Rect frame)
  57. {
  58. _contentView = new ContentView (frame);
  59. _vertical = new ScrollBarView (1, 0, isVertical: true) {
  60. X = Pos.AnchorEnd (1),
  61. Y = 0,
  62. Width = 1,
  63. Height = Dim.Fill (_showHorizontalScrollIndicator ? 1 : 0),
  64. Host = this
  65. };
  66. _horizontal = new ScrollBarView (1, 0, isVertical: false) {
  67. X = 0,
  68. Y = Pos.AnchorEnd (1),
  69. Width = Dim.Fill (_showVerticalScrollIndicator ? 1 : 0),
  70. Height = 1,
  71. Host = this
  72. };
  73. _vertical.OtherScrollBarView = _horizontal;
  74. _horizontal.OtherScrollBarView = _vertical;
  75. base.Add (_contentView);
  76. CanFocus = true;
  77. MouseEnter += View_MouseEnter;
  78. MouseLeave += View_MouseLeave;
  79. _contentView.MouseEnter += View_MouseEnter;
  80. _contentView.MouseLeave += View_MouseLeave;
  81. // Things this view knows how to do
  82. AddCommand (Command.ScrollUp, () => ScrollUp (1));
  83. AddCommand (Command.ScrollDown, () => ScrollDown (1));
  84. AddCommand (Command.ScrollLeft, () => ScrollLeft (1));
  85. AddCommand (Command.ScrollRight, () => ScrollRight (1));
  86. AddCommand (Command.PageUp, () => ScrollUp (Bounds.Height));
  87. AddCommand (Command.PageDown, () => ScrollDown (Bounds.Height));
  88. AddCommand (Command.PageLeft, () => ScrollLeft (Bounds.Width));
  89. AddCommand (Command.PageRight, () => ScrollRight (Bounds.Width));
  90. AddCommand (Command.TopHome, () => ScrollUp (_contentSize.Height));
  91. AddCommand (Command.BottomEnd, () => ScrollDown (_contentSize.Height));
  92. AddCommand (Command.LeftHome, () => ScrollLeft (_contentSize.Width));
  93. AddCommand (Command.RightEnd, () => ScrollRight (_contentSize.Width));
  94. // Default keybindings for this view
  95. KeyBindings.Add (KeyCode.CursorUp, Command.ScrollUp);
  96. KeyBindings.Add (KeyCode.CursorDown, Command.ScrollDown);
  97. KeyBindings.Add (KeyCode.CursorLeft, Command.ScrollLeft);
  98. KeyBindings.Add (KeyCode.CursorRight, Command.ScrollRight);
  99. KeyBindings.Add (KeyCode.PageUp, Command.PageUp);
  100. KeyBindings.Add ((KeyCode)'v' | KeyCode.AltMask, Command.PageUp);
  101. KeyBindings.Add (KeyCode.PageDown, Command.PageDown);
  102. KeyBindings.Add (KeyCode.V | KeyCode.CtrlMask, Command.PageDown);
  103. KeyBindings.Add (KeyCode.PageUp | KeyCode.CtrlMask, Command.PageLeft);
  104. KeyBindings.Add (KeyCode.PageDown | KeyCode.CtrlMask, Command.PageRight);
  105. KeyBindings.Add (KeyCode.Home, Command.TopHome);
  106. KeyBindings.Add (KeyCode.End, Command.BottomEnd);
  107. KeyBindings.Add (KeyCode.Home | KeyCode.CtrlMask, Command.LeftHome);
  108. KeyBindings.Add (KeyCode.End | KeyCode.CtrlMask, Command.RightEnd);
  109. Initialized += (s, e) => {
  110. if (!_vertical.IsInitialized) {
  111. _vertical.BeginInit ();
  112. _vertical.EndInit ();
  113. }
  114. if (!_horizontal.IsInitialized) {
  115. _horizontal.BeginInit ();
  116. _horizontal.EndInit ();
  117. }
  118. SetContentOffset (_contentOffset);
  119. _contentView.Frame = new Rect (ContentOffset, ContentSize);
  120. _vertical.ChangedPosition += delegate {
  121. ContentOffset = new Point (ContentOffset.X, _vertical.Position);
  122. };
  123. _horizontal.ChangedPosition += delegate {
  124. ContentOffset = new Point (_horizontal.Position, ContentOffset.Y);
  125. };
  126. };
  127. }
  128. //public override void BeginInit ()
  129. //{
  130. // SetContentOffset (contentOffset);
  131. // base.BeginInit ();
  132. //}
  133. Size _contentSize;
  134. Point _contentOffset;
  135. bool _showHorizontalScrollIndicator;
  136. bool _showVerticalScrollIndicator;
  137. bool _keepContentAlwaysInViewport = true;
  138. bool _autoHideScrollBars = true;
  139. /// <summary>
  140. /// Represents the contents of the data shown inside the scrollview
  141. /// </summary>
  142. /// <value>The size of the content.</value>
  143. public Size ContentSize {
  144. get {
  145. return _contentSize;
  146. }
  147. set {
  148. if (_contentSize != value) {
  149. _contentSize = value;
  150. _contentView.Frame = new Rect (_contentOffset, value);
  151. _vertical.Size = _contentSize.Height;
  152. _horizontal.Size = _contentSize.Width;
  153. SetNeedsDisplay ();
  154. }
  155. }
  156. }
  157. /// <summary>
  158. /// Represents the top left corner coordinate that is displayed by the scrollview
  159. /// </summary>
  160. /// <value>The content offset.</value>
  161. public Point ContentOffset {
  162. get {
  163. return _contentOffset;
  164. }
  165. set {
  166. if (!IsInitialized) {
  167. // We're not initialized so we can't do anything fancy. Just cache value.
  168. _contentOffset = new Point (-Math.Abs (value.X), -Math.Abs (value.Y)); ;
  169. return;
  170. }
  171. SetContentOffset (value);
  172. }
  173. }
  174. private void SetContentOffset (Point offset)
  175. {
  176. var co = new Point (-Math.Abs (offset.X), -Math.Abs (offset.Y));
  177. _contentOffset = co;
  178. _contentView.Frame = new Rect (_contentOffset, _contentSize);
  179. var p = Math.Max (0, -_contentOffset.Y);
  180. if (_vertical.Position != p) {
  181. _vertical.Position = Math.Max (0, -_contentOffset.Y);
  182. }
  183. p = Math.Max (0, -_contentOffset.X);
  184. if (_horizontal.Position != p) {
  185. _horizontal.Position = Math.Max (0, -_contentOffset.X);
  186. }
  187. SetNeedsDisplay ();
  188. }
  189. /// <summary>
  190. /// If true the vertical/horizontal scroll bars won't be showed if it's not needed.
  191. /// </summary>
  192. public bool AutoHideScrollBars {
  193. get => _autoHideScrollBars;
  194. set {
  195. if (_autoHideScrollBars != value) {
  196. _autoHideScrollBars = value;
  197. if (Subviews.Contains (_vertical)) {
  198. _vertical.AutoHideScrollBars = value;
  199. }
  200. if (Subviews.Contains (_horizontal)) {
  201. _horizontal.AutoHideScrollBars = value;
  202. }
  203. SetNeedsDisplay ();
  204. }
  205. }
  206. }
  207. /// <summary>
  208. /// Get or sets if the view-port is kept always visible in the area of this <see cref="ScrollView"/>
  209. /// </summary>
  210. public bool KeepContentAlwaysInViewport {
  211. get { return _keepContentAlwaysInViewport; }
  212. set {
  213. if (_keepContentAlwaysInViewport != value) {
  214. _keepContentAlwaysInViewport = value;
  215. _vertical.OtherScrollBarView.KeepContentAlwaysInViewport = value;
  216. _horizontal.OtherScrollBarView.KeepContentAlwaysInViewport = value;
  217. Point p = default;
  218. if (value && -_contentOffset.X + Bounds.Width > _contentSize.Width) {
  219. p = new Point (_contentSize.Width - Bounds.Width + (_showVerticalScrollIndicator ? 1 : 0), -_contentOffset.Y);
  220. }
  221. if (value && -_contentOffset.Y + Bounds.Height > _contentSize.Height) {
  222. if (p == default) {
  223. p = new Point (-_contentOffset.X, _contentSize.Height - Bounds.Height + (_showHorizontalScrollIndicator ? 1 : 0));
  224. } else {
  225. p.Y = _contentSize.Height - Bounds.Height + (_showHorizontalScrollIndicator ? 1 : 0);
  226. }
  227. }
  228. if (p != default) {
  229. ContentOffset = p;
  230. }
  231. }
  232. }
  233. }
  234. View _contentBottomRightCorner;
  235. /// <summary>
  236. /// Adds the view to the scrollview.
  237. /// </summary>
  238. /// <param name="view">The view to add to the scrollview.</param>
  239. public override void Add (View view)
  240. {
  241. if (view.Id == "contentBottomRightCorner") {
  242. _contentBottomRightCorner = view;
  243. base.Add (view);
  244. } else {
  245. if (!IsOverridden (view, "MouseEvent")) {
  246. view.MouseEnter += View_MouseEnter;
  247. view.MouseLeave += View_MouseLeave;
  248. }
  249. _contentView.Add (view);
  250. }
  251. SetNeedsLayout ();
  252. }
  253. /// <summary>
  254. /// Removes the view from the scrollview.
  255. /// </summary>
  256. /// <param name="view">The view to remove from the scrollview.</param>
  257. public override void Remove (View view)
  258. {
  259. if (view == null) {
  260. return;
  261. }
  262. SetNeedsDisplay ();
  263. var container = view?.SuperView;
  264. if (container == this) {
  265. base.Remove (view);
  266. } else {
  267. container?.Remove (view);
  268. }
  269. if (_contentView.InternalSubviews.Count < 1) {
  270. this.CanFocus = false;
  271. }
  272. }
  273. /// <summary>
  274. /// Removes all widgets from this container.
  275. /// </summary>
  276. public override void RemoveAll ()
  277. {
  278. _contentView.RemoveAll ();
  279. }
  280. void View_MouseLeave (object sender, MouseEventEventArgs e)
  281. {
  282. if (Application.MouseGrabView != null && Application.MouseGrabView != _vertical && Application.MouseGrabView != _horizontal) {
  283. Application.UngrabMouse ();
  284. }
  285. }
  286. void View_MouseEnter (object sender, MouseEventEventArgs e)
  287. {
  288. Application.GrabMouse (this);
  289. }
  290. /// <summary>
  291. /// Gets or sets the visibility for the horizontal scroll indicator.
  292. /// </summary>
  293. /// <value><c>true</c> if show horizontal scroll indicator; otherwise, <c>false</c>.</value>
  294. public bool ShowHorizontalScrollIndicator {
  295. get => _showHorizontalScrollIndicator;
  296. set {
  297. if (value != _showHorizontalScrollIndicator) {
  298. _showHorizontalScrollIndicator = value;
  299. SetNeedsLayout ();
  300. if (value) {
  301. _horizontal.OtherScrollBarView = _vertical;
  302. base.Add (_horizontal);
  303. _horizontal.ShowScrollIndicator = value;
  304. _horizontal.AutoHideScrollBars = _autoHideScrollBars;
  305. _horizontal.OtherScrollBarView.ShowScrollIndicator = value;
  306. _horizontal.MouseEnter += View_MouseEnter;
  307. _horizontal.MouseLeave += View_MouseLeave;
  308. } else {
  309. base.Remove (_horizontal);
  310. _horizontal.OtherScrollBarView = null;
  311. _horizontal.MouseEnter -= View_MouseEnter;
  312. _horizontal.MouseLeave -= View_MouseLeave;
  313. }
  314. }
  315. _vertical.Height = Dim.Fill (_showHorizontalScrollIndicator ? 1 : 0);
  316. }
  317. }
  318. /// <summary>
  319. /// Gets or sets the visibility for the vertical scroll indicator.
  320. /// </summary>
  321. /// <value><c>true</c> if show vertical scroll indicator; otherwise, <c>false</c>.</value>
  322. public bool ShowVerticalScrollIndicator {
  323. get => _showVerticalScrollIndicator;
  324. set {
  325. if (value != _showVerticalScrollIndicator) {
  326. _showVerticalScrollIndicator = value;
  327. SetNeedsLayout ();
  328. if (value) {
  329. _vertical.OtherScrollBarView = _horizontal;
  330. base.Add (_vertical);
  331. _vertical.ShowScrollIndicator = value;
  332. _vertical.AutoHideScrollBars = _autoHideScrollBars;
  333. _vertical.OtherScrollBarView.ShowScrollIndicator = value;
  334. _vertical.MouseEnter += View_MouseEnter;
  335. _vertical.MouseLeave += View_MouseLeave;
  336. } else {
  337. Remove (_vertical);
  338. _vertical.OtherScrollBarView = null;
  339. _vertical.MouseEnter -= View_MouseEnter;
  340. _vertical.MouseLeave -= View_MouseLeave;
  341. }
  342. }
  343. _horizontal.Width = Dim.Fill (_showVerticalScrollIndicator ? 1 : 0);
  344. }
  345. }
  346. /// <inheritdoc/>
  347. public override void OnDrawContent (Rect contentArea)
  348. {
  349. SetViewsNeedsDisplay ();
  350. var savedClip = ClipToBounds ();
  351. // TODO: It's bad practice for views to always clear a view. It negates clipping.
  352. Clear ();
  353. if (!string.IsNullOrEmpty (_contentView.Text) || _contentView.Subviews.Count > 0) {
  354. _contentView.Draw ();
  355. }
  356. DrawScrollBars ();
  357. Driver.Clip = savedClip;
  358. }
  359. private void DrawScrollBars ()
  360. {
  361. if (_autoHideScrollBars) {
  362. ShowHideScrollBars ();
  363. } else {
  364. if (ShowVerticalScrollIndicator) {
  365. _vertical.Draw ();
  366. }
  367. if (ShowHorizontalScrollIndicator) {
  368. _horizontal.Draw ();
  369. }
  370. if (ShowVerticalScrollIndicator && ShowHorizontalScrollIndicator) {
  371. SetContentBottomRightCornerVisibility ();
  372. _contentBottomRightCorner.Draw ();
  373. }
  374. }
  375. }
  376. private void SetContentBottomRightCornerVisibility ()
  377. {
  378. if (_showHorizontalScrollIndicator && _showVerticalScrollIndicator) {
  379. _contentBottomRightCorner.Visible = true;
  380. } else if (_horizontal.IsAdded || _vertical.IsAdded) {
  381. _contentBottomRightCorner.Visible = false;
  382. }
  383. }
  384. void ShowHideScrollBars ()
  385. {
  386. bool v = false, h = false; bool p = false;
  387. if (Bounds.Height == 0 || Bounds.Height > _contentSize.Height) {
  388. if (ShowVerticalScrollIndicator) {
  389. ShowVerticalScrollIndicator = false;
  390. }
  391. v = false;
  392. } else if (Bounds.Height > 0 && Bounds.Height == _contentSize.Height) {
  393. p = true;
  394. } else {
  395. if (!ShowVerticalScrollIndicator) {
  396. ShowVerticalScrollIndicator = true;
  397. }
  398. v = true;
  399. }
  400. if (Bounds.Width == 0 || Bounds.Width > _contentSize.Width) {
  401. if (ShowHorizontalScrollIndicator) {
  402. ShowHorizontalScrollIndicator = false;
  403. }
  404. h = false;
  405. } else if (Bounds.Width > 0 && Bounds.Width == _contentSize.Width && p) {
  406. if (ShowHorizontalScrollIndicator) {
  407. ShowHorizontalScrollIndicator = false;
  408. }
  409. h = false;
  410. if (ShowVerticalScrollIndicator) {
  411. ShowVerticalScrollIndicator = false;
  412. }
  413. v = false;
  414. } else {
  415. if (p) {
  416. if (!ShowVerticalScrollIndicator) {
  417. ShowVerticalScrollIndicator = true;
  418. }
  419. v = true;
  420. }
  421. if (!ShowHorizontalScrollIndicator) {
  422. ShowHorizontalScrollIndicator = true;
  423. }
  424. h = true;
  425. }
  426. var dim = Dim.Fill (h ? 1 : 0);
  427. if (!_vertical.Height.Equals (dim)) {
  428. _vertical.Height = dim;
  429. }
  430. dim = Dim.Fill (v ? 1 : 0);
  431. if (!_horizontal.Width.Equals (dim)) {
  432. _horizontal.Width = dim;
  433. }
  434. if (v) {
  435. _vertical.SetRelativeLayout (Bounds);
  436. _vertical.Draw ();
  437. }
  438. if (h) {
  439. _horizontal.SetRelativeLayout (Bounds);
  440. _horizontal.Draw ();
  441. }
  442. SetContentBottomRightCornerVisibility ();
  443. if (v && h) {
  444. _contentBottomRightCorner.SetRelativeLayout (Bounds);
  445. _contentBottomRightCorner.Draw ();
  446. }
  447. }
  448. void SetViewsNeedsDisplay ()
  449. {
  450. foreach (View view in _contentView.Subviews) {
  451. view.SetNeedsDisplay ();
  452. }
  453. }
  454. ///<inheritdoc/>
  455. public override void PositionCursor ()
  456. {
  457. if (InternalSubviews.Count == 0)
  458. Move (0, 0);
  459. else
  460. base.PositionCursor ();
  461. }
  462. /// <summary>
  463. /// Scrolls the view up.
  464. /// </summary>
  465. /// <returns><c>true</c>, if left was scrolled, <c>false</c> otherwise.</returns>
  466. /// <param name="lines">Number of lines to scroll.</param>
  467. public bool ScrollUp (int lines)
  468. {
  469. if (_contentOffset.Y < 0) {
  470. ContentOffset = new Point (_contentOffset.X, Math.Min (_contentOffset.Y + lines, 0));
  471. return true;
  472. }
  473. return false;
  474. }
  475. /// <summary>
  476. /// Scrolls the view to the left
  477. /// </summary>
  478. /// <returns><c>true</c>, if left was scrolled, <c>false</c> otherwise.</returns>
  479. /// <param name="cols">Number of columns to scroll by.</param>
  480. public bool ScrollLeft (int cols)
  481. {
  482. if (_contentOffset.X < 0) {
  483. ContentOffset = new Point (Math.Min (_contentOffset.X + cols, 0), _contentOffset.Y);
  484. return true;
  485. }
  486. return false;
  487. }
  488. /// <summary>
  489. /// Scrolls the view down.
  490. /// </summary>
  491. /// <returns><c>true</c>, if left was scrolled, <c>false</c> otherwise.</returns>
  492. /// <param name="lines">Number of lines to scroll.</param>
  493. public bool ScrollDown (int lines)
  494. {
  495. if (_vertical.CanScroll (lines, out _, true)) {
  496. ContentOffset = new Point (_contentOffset.X, _contentOffset.Y - lines);
  497. return true;
  498. }
  499. return false;
  500. }
  501. /// <summary>
  502. /// Scrolls the view to the right.
  503. /// </summary>
  504. /// <returns><c>true</c>, if right was scrolled, <c>false</c> otherwise.</returns>
  505. /// <param name="cols">Number of columns to scroll by.</param>
  506. public bool ScrollRight (int cols)
  507. {
  508. if (_horizontal.CanScroll (cols, out _)) {
  509. ContentOffset = new Point (_contentOffset.X - cols, _contentOffset.Y);
  510. return true;
  511. }
  512. return false;
  513. }
  514. ///<inheritdoc/>
  515. public override bool OnKeyDown (Key a)
  516. {
  517. if (base.OnKeyDown (a))
  518. return true;
  519. var result = InvokeKeyBindings (a);
  520. if (result != null)
  521. return (bool)result;
  522. return false;
  523. }
  524. ///<inheritdoc/>
  525. public override bool MouseEvent (MouseEvent me)
  526. {
  527. if (me.Flags != MouseFlags.WheeledDown && me.Flags != MouseFlags.WheeledUp &&
  528. me.Flags != MouseFlags.WheeledRight && me.Flags != MouseFlags.WheeledLeft &&
  529. // me.Flags != MouseFlags.Button1Pressed && me.Flags != MouseFlags.Button1Clicked &&
  530. !me.Flags.HasFlag (MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition)) {
  531. return false;
  532. }
  533. if (me.Flags == MouseFlags.WheeledDown && ShowVerticalScrollIndicator) {
  534. ScrollDown (1);
  535. } else if (me.Flags == MouseFlags.WheeledUp && ShowVerticalScrollIndicator) {
  536. ScrollUp (1);
  537. } else if (me.Flags == MouseFlags.WheeledRight && _showHorizontalScrollIndicator) {
  538. ScrollRight (1);
  539. } else if (me.Flags == MouseFlags.WheeledLeft && ShowVerticalScrollIndicator) {
  540. ScrollLeft (1);
  541. } else if (me.X == _vertical.Frame.X && ShowVerticalScrollIndicator) {
  542. _vertical.MouseEvent (me);
  543. } else if (me.Y == _horizontal.Frame.Y && ShowHorizontalScrollIndicator) {
  544. _horizontal.MouseEvent (me);
  545. } else if (IsOverridden (me.View, "MouseEvent")) {
  546. Application.UngrabMouse ();
  547. }
  548. return true;
  549. }
  550. ///<inheritdoc/>
  551. protected override void Dispose (bool disposing)
  552. {
  553. if (!_showVerticalScrollIndicator) {
  554. // It was not added to SuperView, so it won't get disposed automatically
  555. _vertical?.Dispose ();
  556. }
  557. if (!_showHorizontalScrollIndicator) {
  558. // It was not added to SuperView, so it won't get disposed automatically
  559. _horizontal?.Dispose ();
  560. }
  561. base.Dispose (disposing);
  562. }
  563. ///<inheritdoc/>
  564. public override bool OnEnter (View view)
  565. {
  566. if (Subviews.Count == 0 || !Subviews.Any (subview => subview.CanFocus)) {
  567. Application.Driver?.SetCursorVisibility (CursorVisibility.Invisible);
  568. }
  569. return base.OnEnter (view);
  570. }
  571. }