ScrollBarTests.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938
  1. using Xunit.Abstractions;
  2. using static Unix.Terminal.Delegates;
  3. namespace Terminal.Gui.ViewsTests;
  4. public class ScrollBarTests (ITestOutputHelper output)
  5. {
  6. [Fact]
  7. public void Constructor_Defaults ()
  8. {
  9. var scrollBar = new ScrollBar ();
  10. Assert.False (scrollBar.CanFocus);
  11. Assert.Equal (Orientation.Vertical, scrollBar.Orientation);
  12. Assert.Equal (0, scrollBar.ScrollableContentSize);
  13. Assert.Equal (0, scrollBar.VisibleContentSize);
  14. Assert.Equal (0, scrollBar.GetSliderPosition ());
  15. Assert.Equal (0, scrollBar.Position);
  16. Assert.True (scrollBar.AutoHide);
  17. }
  18. #region AutoHide
  19. [Fact]
  20. [AutoInitShutdown]
  21. public void AutoHide_True_Is_Default_CorrectlyHidesAndShows ()
  22. {
  23. var super = new Toplevel ()
  24. {
  25. Id = "super",
  26. Width = 1,
  27. Height = 20
  28. };
  29. var scrollBar = new ScrollBar
  30. {
  31. };
  32. super.Add (scrollBar);
  33. Assert.True (scrollBar.AutoHide);
  34. Assert.True (scrollBar.Visible); // Before Init
  35. RunState rs = Application.Begin (super);
  36. // Should Show
  37. scrollBar.ScrollableContentSize = 21;
  38. Application.RunIteration (ref rs);
  39. Assert.True (scrollBar.Visible);
  40. // Should Hide
  41. scrollBar.ScrollableContentSize = 10;
  42. Assert.False (scrollBar.Visible);
  43. super.Dispose ();
  44. }
  45. [Fact]
  46. [AutoInitShutdown]
  47. public void AutoHide_False_CorrectlyHidesAndShows ()
  48. {
  49. var super = new Toplevel ()
  50. {
  51. Id = "super",
  52. Width = 1,
  53. Height = 20
  54. };
  55. var scrollBar = new ScrollBar
  56. {
  57. ScrollableContentSize = 20,
  58. AutoHide = false
  59. };
  60. super.Add (scrollBar);
  61. Assert.False (scrollBar.AutoHide);
  62. Assert.True (scrollBar.Visible);
  63. RunState rs = Application.Begin (super);
  64. // Should Hide if AutoSize = true, but should not hide if AutoSize = false
  65. scrollBar.ScrollableContentSize = 10;
  66. Assert.True (scrollBar.Visible);
  67. super.Dispose ();
  68. }
  69. [Fact]
  70. [AutoInitShutdown]
  71. public void AutoHide_Change_AutoSize_CorrectlyHidesAndShows ()
  72. {
  73. var super = new Toplevel ()
  74. {
  75. Id = "super",
  76. Width = 1,
  77. Height = 20
  78. };
  79. var scrollBar = new ScrollBar
  80. {
  81. ScrollableContentSize = 20,
  82. };
  83. super.Add (scrollBar);
  84. Assert.True (scrollBar.AutoHide);
  85. Assert.True (scrollBar.Visible); // Before Init
  86. RunState rs = Application.Begin (super);
  87. Assert.False (scrollBar.Visible);
  88. Assert.Equal (1, scrollBar.Frame.Width);
  89. Assert.Equal (20, scrollBar.Frame.Height);
  90. scrollBar.ScrollableContentSize = 10;
  91. Application.RunIteration (ref rs);
  92. Assert.False (scrollBar.Visible);
  93. scrollBar.ScrollableContentSize = 30;
  94. Assert.True (scrollBar.Visible);
  95. scrollBar.AutoHide = false;
  96. Assert.True (scrollBar.Visible);
  97. scrollBar.ScrollableContentSize = 10;
  98. Assert.True (scrollBar.Visible);
  99. super.Dispose ();
  100. }
  101. [Fact]
  102. [AutoInitShutdown]
  103. public void AutoHide_Change_Size_CorrectlyHidesAndShows ()
  104. {
  105. var super = new Toplevel ()
  106. {
  107. Id = "super",
  108. Width = 1,
  109. Height = 20
  110. };
  111. var scrollBar = new ScrollBar
  112. {
  113. ScrollableContentSize = 20,
  114. };
  115. super.Add (scrollBar);
  116. RunState rs = Application.Begin (super);
  117. Assert.Equal (Orientation.Vertical, scrollBar.Orientation);
  118. Assert.Equal (20, scrollBar.VisibleContentSize);
  119. //Assert.True (scrollBar.ShowScrollIndicator);
  120. Assert.False (scrollBar.Visible);
  121. Assert.Equal (1, scrollBar.Frame.Width);
  122. Assert.Equal (20, scrollBar.Frame.Height);
  123. scrollBar.ScrollableContentSize = 10;
  124. Application.RunIteration (ref rs);
  125. //Assert.False (scrollBar.ShowScrollIndicator);
  126. Assert.False (scrollBar.Visible);
  127. scrollBar.ScrollableContentSize = 30;
  128. //Assert.True (scrollBar.ShowScrollIndicator);
  129. Assert.True (scrollBar.Visible);
  130. scrollBar.ScrollableContentSize = 10;
  131. Application.RunIteration (ref rs);
  132. //Assert.False (scrollBar.ShowScrollIndicator);
  133. Assert.False (scrollBar.Visible);
  134. scrollBar.ScrollableContentSize = 21;
  135. //Assert.True (scrollBar.ShowScrollIndicator);
  136. Assert.True (scrollBar.Visible);
  137. scrollBar.AutoHide = false;
  138. //Assert.True (scrollBar.ShowScrollIndicator);
  139. Assert.True (scrollBar.Visible);
  140. scrollBar.ScrollableContentSize = 10;
  141. //Assert.True (scrollBar.ShowScrollIndicator);
  142. Assert.True (scrollBar.Visible);
  143. super.Dispose ();
  144. }
  145. #endregion AutoHide
  146. #region Orientation
  147. [Fact]
  148. public void OnOrientationChanged_Keeps_Size ()
  149. {
  150. var scroll = new ScrollBar ();
  151. scroll.Layout ();
  152. scroll.ScrollableContentSize = 1;
  153. scroll.Orientation = Orientation.Horizontal;
  154. Assert.Equal (1, scroll.ScrollableContentSize);
  155. }
  156. [Fact]
  157. public void OnOrientationChanged_Sets_Position_To_0 ()
  158. {
  159. View super = new View ()
  160. {
  161. Id = "super",
  162. Width = 10,
  163. Height = 10
  164. };
  165. var scrollBar = new ScrollBar ()
  166. {
  167. };
  168. super.Add (scrollBar);
  169. scrollBar.Layout ();
  170. scrollBar.Position = 1;
  171. scrollBar.Orientation = Orientation.Horizontal;
  172. Assert.Equal (0, scrollBar.GetSliderPosition ());
  173. }
  174. #endregion Orientation
  175. #region Size
  176. // TODO: Add tests.
  177. #endregion Size
  178. #region Position
  179. [Fact]
  180. public void Position_Event_Cancelables ()
  181. {
  182. var changingCount = 0;
  183. var changedCount = 0;
  184. var scrollBar = new ScrollBar { };
  185. scrollBar.ScrollableContentSize = 5;
  186. scrollBar.Frame = new Rectangle (0, 0, 1, 4); // Needs to be at least 4 for slider to move
  187. scrollBar.PositionChanging += (s, e) =>
  188. {
  189. if (changingCount == 0)
  190. {
  191. e.Cancel = true;
  192. }
  193. changingCount++;
  194. };
  195. scrollBar.PositionChanged += (s, e) => changedCount++;
  196. scrollBar.Position = 1;
  197. Assert.Equal (0, scrollBar.Position);
  198. Assert.Equal (1, changingCount);
  199. Assert.Equal (0, changedCount);
  200. scrollBar.Position = 1;
  201. Assert.Equal (1, scrollBar.Position);
  202. Assert.Equal (2, changingCount);
  203. Assert.Equal (1, changedCount);
  204. }
  205. #endregion Position
  206. [Fact]
  207. public void ScrollableContentSize_Cannot_Be_Negative ()
  208. {
  209. var scrollBar = new ScrollBar { Height = 10, ScrollableContentSize = -1 };
  210. Assert.Equal (0, scrollBar.ScrollableContentSize);
  211. scrollBar.ScrollableContentSize = -10;
  212. Assert.Equal (0, scrollBar.ScrollableContentSize);
  213. }
  214. [Fact]
  215. public void ScrollableContentSizeChanged_Event ()
  216. {
  217. var count = 0;
  218. var scrollBar = new ScrollBar ();
  219. scrollBar.ScrollableContentSizeChanged += (s, e) => count++;
  220. scrollBar.ScrollableContentSize = 10;
  221. Assert.Equal (10, scrollBar.ScrollableContentSize);
  222. Assert.Equal (1, count);
  223. }
  224. [Theory]
  225. [SetupFakeDriver]
  226. #region Draw
  227. #region Horizontal
  228. #region Super 10 - ScrollBar 8
  229. [InlineData (
  230. 10,
  231. 1,
  232. 10,
  233. -1,
  234. Orientation.Horizontal,
  235. @"
  236. ┌──────────┐
  237. │◄████████►│
  238. └──────────┘")]
  239. [InlineData (
  240. 10,
  241. 1,
  242. 20,
  243. -1,
  244. Orientation.Horizontal,
  245. @"
  246. ┌──────────┐
  247. │◄████░░░░►│
  248. └──────────┘")]
  249. [InlineData (
  250. 10,
  251. 1,
  252. 20,
  253. 0,
  254. Orientation.Horizontal,
  255. @"
  256. ┌──────────┐
  257. │◄████░░░░►│
  258. └──────────┘")]
  259. [InlineData (
  260. 10,
  261. 1,
  262. 20,
  263. 1,
  264. Orientation.Horizontal,
  265. @"
  266. ┌──────────┐
  267. │◄████░░░░►│
  268. └──────────┘")]
  269. [InlineData (
  270. 10,
  271. 1,
  272. 20,
  273. 2,
  274. Orientation.Horizontal,
  275. @"
  276. ┌──────────┐
  277. │◄░████░░░►│
  278. └──────────┘
  279. ")]
  280. [InlineData (
  281. 10,
  282. 1,
  283. 20,
  284. 3,
  285. Orientation.Horizontal,
  286. @"
  287. ┌──────────┐
  288. │◄░████░░░►│
  289. └──────────┘
  290. ")]
  291. [InlineData (
  292. 10,
  293. 1,
  294. 20,
  295. 4,
  296. Orientation.Horizontal,
  297. @"
  298. ┌──────────┐
  299. │◄░░████░░►│
  300. └──────────┘
  301. ")]
  302. [InlineData (
  303. 10,
  304. 1,
  305. 20,
  306. 5,
  307. Orientation.Horizontal,
  308. @"
  309. ┌──────────┐
  310. │◄░░████░░►│
  311. └──────────┘
  312. ")]
  313. [InlineData (
  314. 10,
  315. 1,
  316. 20,
  317. 6,
  318. Orientation.Horizontal,
  319. @"
  320. ┌──────────┐
  321. │◄░░████░░►│
  322. └──────────┘
  323. ")]
  324. [InlineData (
  325. 10,
  326. 1,
  327. 20,
  328. 7,
  329. Orientation.Horizontal,
  330. @"
  331. ┌──────────┐
  332. │◄░░░████░►│
  333. └──────────┘
  334. ")]
  335. [InlineData (
  336. 10,
  337. 1,
  338. 20,
  339. 8,
  340. Orientation.Horizontal,
  341. @"
  342. ┌──────────┐
  343. │◄░░░████░►│
  344. └──────────┘
  345. ")]
  346. [InlineData (
  347. 10,
  348. 1,
  349. 20,
  350. 9,
  351. Orientation.Horizontal,
  352. @"
  353. ┌──────────┐
  354. │◄░░░░████►│
  355. └──────────┘
  356. ")]
  357. [InlineData (
  358. 10,
  359. 1,
  360. 20,
  361. 10,
  362. Orientation.Horizontal,
  363. @"
  364. ┌──────────┐
  365. │◄░░░░████►│
  366. └──────────┘
  367. ")]
  368. [InlineData (
  369. 10,
  370. 1,
  371. 20,
  372. 19,
  373. Orientation.Horizontal,
  374. @"
  375. ┌──────────┐
  376. │◄░░░░████►│
  377. └──────────┘
  378. ")]
  379. [InlineData (
  380. 10,
  381. 1,
  382. 20,
  383. 20,
  384. Orientation.Horizontal,
  385. @"
  386. ┌──────────┐
  387. │◄░░░░████►│
  388. └──────────┘
  389. ")]
  390. #endregion Super 10 - ScrollBar 8
  391. #region Super 12 - ScrollBar 10
  392. [InlineData (
  393. 12,
  394. 1,
  395. 10,
  396. -1,
  397. Orientation.Horizontal,
  398. @"
  399. ┌────────────┐
  400. │◄██████████►│
  401. └────────────┘")]
  402. [InlineData (
  403. 12,
  404. 1,
  405. 20,
  406. -1,
  407. Orientation.Horizontal,
  408. @"
  409. ┌────────────┐
  410. │◄██████░░░░►│
  411. └────────────┘")]
  412. [InlineData (
  413. 12,
  414. 1,
  415. 20,
  416. 0,
  417. Orientation.Horizontal,
  418. @"
  419. ┌────────────┐
  420. │◄██████░░░░►│
  421. └────────────┘")]
  422. [InlineData (
  423. 12,
  424. 1,
  425. 20,
  426. 1,
  427. Orientation.Horizontal,
  428. @"
  429. ┌────────────┐
  430. │◄██████░░░░►│
  431. └────────────┘")]
  432. [InlineData (
  433. 12,
  434. 1,
  435. 20,
  436. 2,
  437. Orientation.Horizontal,
  438. @"
  439. ┌────────────┐
  440. │◄░██████░░░►│
  441. └────────────┘
  442. ")]
  443. [InlineData (
  444. 12,
  445. 1,
  446. 20,
  447. 3,
  448. Orientation.Horizontal,
  449. @"
  450. ┌────────────┐
  451. │◄░░██████░░►│
  452. └────────────┘
  453. ")]
  454. [InlineData (
  455. 12,
  456. 1,
  457. 20,
  458. 4,
  459. Orientation.Horizontal,
  460. @"
  461. ┌────────────┐
  462. │◄░░██████░░►│
  463. └────────────┘
  464. ")]
  465. [InlineData (
  466. 12,
  467. 1,
  468. 20,
  469. 5,
  470. Orientation.Horizontal,
  471. @"
  472. ┌────────────┐
  473. │◄░░██████░░►│
  474. └────────────┘
  475. ")]
  476. [InlineData (
  477. 12,
  478. 1,
  479. 20,
  480. 6,
  481. Orientation.Horizontal,
  482. @"
  483. ┌────────────┐
  484. │◄░░░██████░►│
  485. └────────────┘
  486. ")]
  487. [InlineData (
  488. 12,
  489. 1,
  490. 20,
  491. 7,
  492. Orientation.Horizontal,
  493. @"
  494. ┌────────────┐
  495. │◄░░░░██████►│
  496. └────────────┘
  497. ")]
  498. [InlineData (
  499. 12,
  500. 1,
  501. 20,
  502. 8,
  503. Orientation.Horizontal,
  504. @"
  505. ┌────────────┐
  506. │◄░░░░██████►│
  507. └────────────┘
  508. ")]
  509. [InlineData (
  510. 12,
  511. 1,
  512. 20,
  513. 9,
  514. Orientation.Horizontal,
  515. @"
  516. ┌────────────┐
  517. │◄░░░░██████►│
  518. └────────────┘
  519. ")]
  520. [InlineData (
  521. 12,
  522. 1,
  523. 20,
  524. 10,
  525. Orientation.Horizontal,
  526. @"
  527. ┌────────────┐
  528. │◄░░░░██████►│
  529. └────────────┘
  530. ")]
  531. [InlineData (
  532. 12,
  533. 1,
  534. 20,
  535. 19,
  536. Orientation.Horizontal,
  537. @"
  538. ┌────────────┐
  539. │◄░░░░██████►│
  540. └────────────┘
  541. ")]
  542. [InlineData (
  543. 12,
  544. 1,
  545. 20,
  546. 20,
  547. Orientation.Horizontal,
  548. @"
  549. ┌────────────┐
  550. │◄░░░░██████►│
  551. └────────────┘
  552. ")]
  553. #endregion Super 12 - ScrollBar 10
  554. [InlineData (
  555. 10,
  556. 3,
  557. 20,
  558. 2,
  559. Orientation.Horizontal,
  560. @"
  561. ┌──────────┐
  562. │ ░████░░░ │
  563. │◄░████░░░►│
  564. │ ░████░░░ │
  565. └──────────┘
  566. ")]
  567. #endregion Horizontal
  568. #region Vertical
  569. [InlineData (
  570. 1,
  571. 10,
  572. 10,
  573. -1,
  574. Orientation.Vertical,
  575. @"
  576. ┌─┐
  577. │▲│
  578. │█│
  579. │█│
  580. │█│
  581. │█│
  582. │█│
  583. │█│
  584. │█│
  585. │█│
  586. │▼│
  587. └─┘")]
  588. [InlineData (
  589. 1,
  590. 10,
  591. 10,
  592. 5,
  593. Orientation.Vertical,
  594. @"
  595. ┌─┐
  596. │▲│
  597. │█│
  598. │█│
  599. │█│
  600. │█│
  601. │█│
  602. │█│
  603. │█│
  604. │█│
  605. │▼│
  606. └─┘")]
  607. [InlineData (
  608. 1,
  609. 10,
  610. 20,
  611. 5,
  612. Orientation.Vertical,
  613. @"
  614. ┌─┐
  615. │▲│
  616. │░│
  617. │░│
  618. │█│
  619. │█│
  620. │█│
  621. │█│
  622. │░│
  623. │░│
  624. │▼│
  625. └─┘")]
  626. [InlineData (
  627. 1,
  628. 12,
  629. 20,
  630. 5,
  631. Orientation.Vertical,
  632. @"
  633. ┌─┐
  634. │▲│
  635. │░│
  636. │░│
  637. │█│
  638. │█│
  639. │█│
  640. │█│
  641. │█│
  642. │█│
  643. │░│
  644. │░│
  645. │▼│
  646. └─┘")]
  647. [InlineData (
  648. 3,
  649. 10,
  650. 20,
  651. 2,
  652. Orientation.Vertical,
  653. @"
  654. ┌───┐
  655. │ ▲ │
  656. │░░░│
  657. │███│
  658. │███│
  659. │███│
  660. │███│
  661. │░░░│
  662. │░░░│
  663. │░░░│
  664. │ ▼ │
  665. └───┘
  666. ")]
  667. #endregion Vertical
  668. public void Draws_Correctly_Default_Settings (int width, int height, int contentSize, int contentPosition, Orientation orientation, string expected)
  669. {
  670. var super = new Window
  671. {
  672. Id = "super",
  673. Width = width + 2,
  674. Height = height + 2,
  675. };
  676. var scrollBar = new ScrollBar
  677. {
  678. AutoHide = false,
  679. Orientation = orientation,
  680. };
  681. if (orientation == Orientation.Vertical)
  682. {
  683. super.SetContentSize (new (width, contentSize));
  684. scrollBar.Width = width;
  685. }
  686. else
  687. {
  688. super.SetContentSize (new (contentSize, height));
  689. scrollBar.Height = height;
  690. }
  691. super.Add (scrollBar);
  692. scrollBar.Position = contentPosition;
  693. super.Layout ();
  694. super.Draw ();
  695. _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  696. }
  697. #endregion Draw
  698. #region Mouse
  699. [Theory]
  700. [CombinatorialData]
  701. [AutoInitShutdown]
  702. public void Mouse_Click_DecrementButton_Decrements ([CombinatorialRange (1, 3, 1)] int increment, Orientation orientation)
  703. {
  704. var top = new Toplevel ()
  705. {
  706. Id = "top",
  707. Width = 10,
  708. Height = 10
  709. };
  710. var scrollBar = new ScrollBar
  711. {
  712. Id = "scrollBar",
  713. Orientation = orientation,
  714. ScrollableContentSize = 20,
  715. Increment = increment
  716. };
  717. top.Add (scrollBar);
  718. RunState rs = Application.Begin (top);
  719. // Scroll to end
  720. scrollBar.Position = 19;
  721. Assert.Equal (10, scrollBar.Position);
  722. Application.RunIteration (ref rs);
  723. Assert.Equal (4, scrollBar.GetSliderPosition ());
  724. Assert.Equal (10, scrollBar.Position);
  725. int initialPos = scrollBar.Position;
  726. Point btnPoint = orientation == Orientation.Vertical
  727. ? new (scrollBar.Frame.X, 0)
  728. : new (0, scrollBar.Frame.Y);
  729. Application.RaiseMouseEvent (new ()
  730. {
  731. ScreenPosition = btnPoint,
  732. Flags = MouseFlags.Button1Clicked
  733. });
  734. Application.RaiseMouseEvent (new ()
  735. {
  736. ScreenPosition = new (0, 0),
  737. Flags = MouseFlags.Button1Clicked
  738. });
  739. Application.RunIteration (ref rs);
  740. Assert.Equal (initialPos - increment, scrollBar.Position);
  741. Application.ResetState (true);
  742. }
  743. [Theory]
  744. [CombinatorialData]
  745. [AutoInitShutdown]
  746. public void Mouse_Click_IncrementButton_Increments ([CombinatorialRange (1, 3, 1)] int increment, Orientation orientation)
  747. {
  748. var top = new Toplevel ()
  749. {
  750. Id = "top",
  751. Width = 10,
  752. Height = 10
  753. };
  754. var scrollBar = new ScrollBar
  755. {
  756. Id = "scrollBar",
  757. Orientation = orientation,
  758. ScrollableContentSize = 20,
  759. Increment = increment
  760. };
  761. top.Add (scrollBar);
  762. RunState rs = Application.Begin (top);
  763. // Scroll to top
  764. scrollBar.Position = 0;
  765. Application.RunIteration (ref rs);
  766. Assert.Equal (0, scrollBar.GetSliderPosition ());
  767. Assert.Equal (0, scrollBar.Position);
  768. int initialPos = scrollBar.Position;
  769. Point btnPoint = orientation == Orientation.Vertical
  770. ? new (scrollBar.Frame.X, scrollBar.Frame.Height - 1)
  771. : new (scrollBar.Frame.Width - 1, scrollBar.Frame.Y);
  772. Application.RaiseMouseEvent (new ()
  773. {
  774. ScreenPosition = btnPoint,
  775. Flags = MouseFlags.Button1Clicked
  776. });
  777. Application.RunIteration (ref rs);
  778. Assert.Equal (initialPos + increment, scrollBar.Position);
  779. Application.ResetState (true);
  780. }
  781. #endregion Mouse
  782. [Fact (Skip = "Disabled - Will put this feature in View")]
  783. [AutoInitShutdown]
  784. public void KeepContentInAllViewport_True_False ()
  785. {
  786. var view = new View { Width = Dim.Fill (), Height = Dim.Fill () };
  787. view.Padding.Thickness = new (0, 0, 2, 0);
  788. view.SetContentSize (new (view.Viewport.Width, 30));
  789. var scrollBar = new ScrollBar { Width = 2, Height = Dim.Fill (), ScrollableContentSize = view.GetContentSize ().Height };
  790. scrollBar.SliderPositionChanged += (_, e) => view.Viewport = view.Viewport with { Y = e.CurrentValue };
  791. view.Padding.Add (scrollBar);
  792. var top = new Toplevel ();
  793. top.Add (view);
  794. Application.Begin (top);
  795. Assert.False (scrollBar.KeepContentInAllViewport);
  796. scrollBar.KeepContentInAllViewport = true;
  797. Assert.Equal (80, view.Padding.Viewport.Width);
  798. Assert.Equal (25, view.Padding.Viewport.Height);
  799. Assert.Equal (2, scrollBar.Viewport.Width);
  800. Assert.Equal (25, scrollBar.Viewport.Height);
  801. Assert.Equal (30, scrollBar.ScrollableContentSize);
  802. scrollBar.KeepContentInAllViewport = false;
  803. scrollBar.Position = 50;
  804. Assert.Equal (scrollBar.GetSliderPosition (), scrollBar.ScrollableContentSize - 1);
  805. Assert.Equal (scrollBar.GetSliderPosition (), view.Viewport.Y);
  806. Assert.Equal (29, scrollBar.GetSliderPosition ());
  807. Assert.Equal (29, view.Viewport.Y);
  808. top.Dispose ();
  809. }
  810. }