ScrollView.cs 22 KB

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