ScrollView.cs 22 KB

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