ScrollSliderTests.cs 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010
  1. using System.Diagnostics;
  2. using System.Runtime.InteropServices;
  3. using Microsoft.VisualStudio.TestPlatform.Utilities;
  4. using Xunit.Abstractions;
  5. using static Unix.Terminal.Delegates;
  6. namespace Terminal.Gui.ViewsTests;
  7. public class ScrollSliderTests (ITestOutputHelper output)
  8. {
  9. [Fact]
  10. public void Constructor_Initializes_Correctly ()
  11. {
  12. var scrollSlider = new ScrollSlider ();
  13. Assert.False (scrollSlider.CanFocus);
  14. Assert.Equal (Orientation.Vertical, scrollSlider.Orientation);
  15. Assert.Equal (TextDirection.TopBottom_LeftRight, scrollSlider.TextDirection);
  16. Assert.Equal (Alignment.Center, scrollSlider.TextAlignment);
  17. Assert.Equal (Alignment.Center, scrollSlider.VerticalTextAlignment);
  18. scrollSlider.Layout ();
  19. Assert.Equal (0, scrollSlider.Frame.X);
  20. Assert.Equal (0, scrollSlider.Frame.Y);
  21. Assert.Equal (1, scrollSlider.Size);
  22. Assert.Equal (2048, scrollSlider.VisibleContentSize);
  23. }
  24. [Fact]
  25. public void Add_To_SuperView_Initializes_Correctly ()
  26. {
  27. View super = new View ()
  28. {
  29. Id = "super",
  30. Width = 10,
  31. Height = 10,
  32. CanFocus = true
  33. };
  34. var scrollSlider = new ScrollSlider ();
  35. super.Add (scrollSlider);
  36. Assert.False (scrollSlider.CanFocus);
  37. Assert.Equal (Orientation.Vertical, scrollSlider.Orientation);
  38. Assert.Equal (TextDirection.TopBottom_LeftRight, scrollSlider.TextDirection);
  39. Assert.Equal (Alignment.Center, scrollSlider.TextAlignment);
  40. Assert.Equal (Alignment.Center, scrollSlider.VerticalTextAlignment);
  41. scrollSlider.Layout ();
  42. Assert.Equal (0, scrollSlider.Frame.X);
  43. Assert.Equal (0, scrollSlider.Frame.Y);
  44. Assert.Equal (1, scrollSlider.Size);
  45. Assert.Equal (10, scrollSlider.VisibleContentSize);
  46. }
  47. //[Fact]
  48. //public void OnOrientationChanged_Sets_Size_To_1 ()
  49. //{
  50. // var scrollSlider = new ScrollSlider ();
  51. // scrollSlider.Orientation = Orientation.Horizontal;
  52. // Assert.Equal (1, scrollSlider.Size);
  53. //}
  54. [Fact]
  55. public void OnOrientationChanged_Sets_Position_To_0 ()
  56. {
  57. View super = new View ()
  58. {
  59. Id = "super",
  60. Width = 10,
  61. Height = 10
  62. };
  63. var scrollSlider = new ScrollSlider ()
  64. {
  65. };
  66. super.Add (scrollSlider);
  67. scrollSlider.Layout ();
  68. scrollSlider.Position = 1;
  69. scrollSlider.Orientation = Orientation.Horizontal;
  70. Assert.Equal (0, scrollSlider.Position);
  71. }
  72. [Fact]
  73. public void OnOrientationChanged_Updates_TextDirection_And_TextAlignment ()
  74. {
  75. var scrollSlider = new ScrollSlider ();
  76. scrollSlider.Orientation = Orientation.Horizontal;
  77. Assert.Equal (TextDirection.LeftRight_TopBottom, scrollSlider.TextDirection);
  78. Assert.Equal (Alignment.Center, scrollSlider.TextAlignment);
  79. Assert.Equal (Alignment.Center, scrollSlider.VerticalTextAlignment);
  80. }
  81. [Theory]
  82. [CombinatorialData]
  83. public void Size_Clamps_To_SuperView_Viewport ([CombinatorialRange (-1, 6, 1)] int sliderSize, Orientation orientation)
  84. {
  85. var super = new View
  86. {
  87. Id = "super",
  88. Width = 5,
  89. Height = 5
  90. };
  91. var scrollSlider = new ScrollSlider
  92. {
  93. Orientation = orientation,
  94. };
  95. super.Add (scrollSlider);
  96. scrollSlider.Layout ();
  97. scrollSlider.Size = sliderSize;
  98. scrollSlider.Layout ();
  99. Assert.True (scrollSlider.Size > 0);
  100. Assert.True (scrollSlider.Size <= 5);
  101. }
  102. [Theory]
  103. [CombinatorialData]
  104. public void Size_Clamps_To_VisibleContentSizes ([CombinatorialRange (1, 6, 1)] int dimension, [CombinatorialRange (-1, 6, 1)] int sliderSize, Orientation orientation)
  105. {
  106. var scrollSlider = new ScrollSlider
  107. {
  108. Orientation = orientation,
  109. VisibleContentSize = dimension,
  110. Size = sliderSize,
  111. };
  112. scrollSlider.Layout ();
  113. Assert.True (scrollSlider.Size > 0);
  114. Assert.True (scrollSlider.Size <= dimension);
  115. }
  116. [Theory]
  117. [CombinatorialData]
  118. public void CalculateSize_ScrollBounds_0_Returns_1 ([CombinatorialRange (-1, 5, 1)] int visibleContentSize, [CombinatorialRange (-1, 5, 1)] int scrollableContentSize)
  119. {
  120. // Arrange
  121. // Act
  122. var sliderSize = ScrollSlider.CalculateSize (scrollableContentSize, visibleContentSize, 0);
  123. // Assert
  124. Assert.Equal (1, sliderSize);
  125. }
  126. [Theory]
  127. [CombinatorialData]
  128. public void CalculateSize_ScrollableContentSize_0_Returns_1 ([CombinatorialRange (-1, 5, 1)] int visibleContentSize, [CombinatorialRange (-1, 5, 1)] int sliderBounds)
  129. {
  130. // Arrange
  131. // Act
  132. var sliderSize = ScrollSlider.CalculateSize (0, visibleContentSize, sliderBounds);
  133. // Assert
  134. Assert.Equal (1, sliderSize);
  135. }
  136. //[Theory]
  137. //[CombinatorialData]
  138. //public void CalculateSize_VisibleContentSize_0_Returns_0 ([CombinatorialRange (-1, 5, 1)] int scrollableContentSize, [CombinatorialRange (-1, 5, 1)] int sliderBounds)
  139. //{
  140. // // Arrange
  141. // // Act
  142. // var sliderSize = ScrollSlider.CalculateSize (scrollableContentSize, 0, sliderBounds);
  143. // // Assert
  144. // Assert.Equal (0, sliderSize);
  145. //}
  146. [Theory]
  147. [InlineData (0, 1, 1, 1)]
  148. [InlineData (1, 1, 1, 1)]
  149. [InlineData (1, 2, 1, 1)]
  150. [InlineData (0, 5, 5, 5)]
  151. [InlineData (1, 5, 5, 1)]
  152. [InlineData (2, 5, 5, 2)]
  153. [InlineData (3, 5, 5, 3)]
  154. [InlineData (4, 5, 5, 4)]
  155. [InlineData (5, 5, 5, 5)]
  156. [InlineData (6, 5, 5, 5)]
  157. public void CalculateSize_Calculates_Correctly (int visibleContentSize, int scrollableContentSize, int scrollBounds, int expectedSliderSize)
  158. {
  159. // Arrange
  160. // Act
  161. var sliderSize = ScrollSlider.CalculateSize (scrollableContentSize, visibleContentSize, scrollBounds);
  162. // Assert
  163. Assert.Equal (expectedSliderSize, sliderSize);
  164. }
  165. [Fact]
  166. public void VisibleContentSize_Not_Set_Uses_SuperView ()
  167. {
  168. View super = new ()
  169. {
  170. Id = "super",
  171. Height = 5,
  172. Width = 5,
  173. };
  174. var scrollSlider = new ScrollSlider
  175. {
  176. };
  177. super.Add (scrollSlider);
  178. super.Layout ();
  179. Assert.Equal (5, scrollSlider.VisibleContentSize);
  180. }
  181. [Fact]
  182. public void VisibleContentSize_Set_Overrides_SuperView ()
  183. {
  184. View super = new ()
  185. {
  186. Id = "super",
  187. Height = 5,
  188. Width = 5,
  189. };
  190. var scrollSlider = new ScrollSlider
  191. {
  192. VisibleContentSize = 10,
  193. };
  194. super.Add (scrollSlider);
  195. super.Layout ();
  196. Assert.Equal (10, scrollSlider.VisibleContentSize);
  197. super.Height = 3;
  198. super.Layout ();
  199. Assert.Equal (10, scrollSlider.VisibleContentSize);
  200. super.Height = 7;
  201. super.Layout ();
  202. Assert.Equal (10, scrollSlider.VisibleContentSize);
  203. }
  204. [Theory]
  205. [CombinatorialData]
  206. public void VisibleContentSizes_Clamps_0_To_Dimension ([CombinatorialRange (0, 10, 1)] int dimension, Orientation orientation)
  207. {
  208. var scrollSlider = new ScrollSlider
  209. {
  210. Orientation = orientation,
  211. VisibleContentSize = dimension,
  212. };
  213. Assert.InRange (scrollSlider.VisibleContentSize, 1, 10);
  214. View super = new ()
  215. {
  216. Id = "super",
  217. Height = dimension,
  218. Width = dimension,
  219. };
  220. scrollSlider = new ScrollSlider
  221. {
  222. Orientation = orientation,
  223. };
  224. super.Add (scrollSlider);
  225. super.Layout ();
  226. Assert.InRange (scrollSlider.VisibleContentSize, 1, 10);
  227. scrollSlider.VisibleContentSize = dimension;
  228. Assert.InRange (scrollSlider.VisibleContentSize, 1, 10);
  229. }
  230. [Theory]
  231. //// 0123456789
  232. //// ---------
  233. //// ◄█►
  234. //[InlineData (3, 3, 0, 1, 0)]
  235. //[InlineData (3, 3, 1, 1, 0)]
  236. //[InlineData (3, 3, 2, 1, 0)]
  237. //// 0123456789
  238. //// ---------
  239. //// ◄██►
  240. //[InlineData (4, 4, 0, 2, 0)]
  241. //[InlineData (4, 4, 1, 2, 0)]
  242. //[InlineData (4, 4, 2, 2, 0)]
  243. //[InlineData (4, 4, 3, 2, 0)]
  244. //[InlineData (4, 4, 4, 2, 0)]
  245. // 012345
  246. // ^----
  247. // █░
  248. [InlineData (2, 5, 0, 0)]
  249. // -^---
  250. // █░
  251. [InlineData (2, 5, 1, 0)]
  252. // --^--
  253. // ░█
  254. [InlineData (2, 5, 2, 1)]
  255. // ---^-
  256. // ░█
  257. [InlineData (2, 5, 3, 1)]
  258. // ----^
  259. // ░█
  260. [InlineData (2, 5, 4, 1)]
  261. // 012345
  262. // ^----
  263. // █░░
  264. [InlineData (3, 5, 0, 0)]
  265. // -^---
  266. // ░█░
  267. [InlineData (3, 5, 1, 1)]
  268. // --^--
  269. // ░░█
  270. [InlineData (3, 5, 2, 2)]
  271. // ---^-
  272. // ░░█
  273. [InlineData (3, 5, 3, 2)]
  274. // ----^
  275. // ░░█
  276. [InlineData (3, 5, 4, 2)]
  277. // 0123456789
  278. // ^-----
  279. // █░░
  280. [InlineData (3, 6, 0, 0)]
  281. // -^----
  282. // █░░
  283. [InlineData (3, 6, 1, 1)]
  284. // --^---
  285. // ░█░
  286. [InlineData (3, 6, 2, 1)]
  287. // ---^--
  288. // ░░█
  289. [InlineData (3, 6, 3, 2)]
  290. // ----^-
  291. // ░░█
  292. [InlineData (3, 6, 4, 2)]
  293. // -----^
  294. // ░░█
  295. [InlineData (3, 6, 5, 2)]
  296. // 012345
  297. // ^----
  298. // ███░
  299. [InlineData (4, 5, 0, 0)]
  300. // -^---
  301. // ░███
  302. [InlineData (4, 5, 1, 1)]
  303. // --^--
  304. // ░███
  305. [InlineData (4, 5, 2, 1)]
  306. // ---^-
  307. // ░███
  308. [InlineData (4, 5, 3, 1)]
  309. // ----^
  310. // ░███
  311. [InlineData (4, 5, 4, 1)]
  312. //// 01234
  313. //// ^---------
  314. //// ◄█░░►
  315. //[InlineData (5, 10, 0, 1, 0)]
  316. //// -^--------
  317. //// ◄█░░►
  318. //[InlineData (5, 10, 1, 1, 0)]
  319. //// --^-------
  320. //// ◄█░░►
  321. //[InlineData (5, 10, 2, 1, 0)]
  322. //// ---^------
  323. //// ◄█░░►
  324. //[InlineData (5, 10, 3, 1, 0)]
  325. //// ----^----
  326. //// ◄░█░►
  327. //[InlineData (5, 10, 4, 1, 1)]
  328. //// -----^---
  329. //// ◄░█░►
  330. //[InlineData (5, 10, 5, 1, 1)]
  331. //// ------^--
  332. //// ◄░░█►
  333. //[InlineData (5, 10, 6, 1, 2)]
  334. //// ------^--
  335. //// ◄░░█►
  336. //[InlineData (5, 10, 7, 1, 2)]
  337. //// -------^-
  338. //// ◄░░█►
  339. //[InlineData (5, 10, 8, 1, 2)]
  340. //// --------^
  341. //// ◄░░█►
  342. //[InlineData (5, 10, 9, 1, 2)]
  343. // 0123456789
  344. // ████░░░░
  345. // ^-----------------
  346. // 012345678901234567890123456789
  347. // ░████░░░
  348. // ----^-------------
  349. // 012345678901234567890123456789
  350. // ░░████░░
  351. // --------^---------
  352. // 012345678901234567890123456789
  353. // ░░░████░
  354. // ------------^-----
  355. // 012345678901234567890123456789
  356. // ░░░░████
  357. // ----------------^--
  358. // 0123456789
  359. // ███░░░░░
  360. // ^-----------------
  361. // 012345678901234567890123456789
  362. // ░░███░░░
  363. // --------^---------
  364. // 012345678901234567890123456789
  365. // ░░░███░░
  366. // ------------^-----
  367. // 012345678901234567890123456789
  368. // ░░░░███░
  369. // ----------------^--
  370. // 012345678901234567890123456789
  371. // ░░░░░███
  372. // ----------------^--
  373. [InlineData (8, 18, 0, 0)]
  374. [InlineData (8, 18, 1, 0)]
  375. // 012345678901234567890123456789
  376. // ░███░░░░
  377. // --^---------------
  378. [InlineData (8, 18, 2, 1)]
  379. [InlineData (8, 18, 3, 2)]
  380. [InlineData (8, 18, 4, 2)]
  381. [InlineData (8, 18, 5, 2)]
  382. [InlineData (8, 18, 6, 3)]
  383. [InlineData (8, 18, 7, 4)]
  384. [InlineData (8, 18, 8, 4)]
  385. [InlineData (8, 18, 9, 4)]
  386. // 012345678901234567890123456789
  387. // ░░░░░███
  388. // ----------^--------
  389. [InlineData (8, 18, 10, 5)]
  390. [InlineData (8, 18, 11, 5)]
  391. [InlineData (8, 18, 12, 5)]
  392. [InlineData (8, 18, 13, 5)]
  393. [InlineData (8, 18, 14, 5)]
  394. [InlineData (8, 18, 15, 5)]
  395. [InlineData (8, 18, 16, 5)]
  396. [InlineData (8, 18, 17, 5)]
  397. [InlineData (8, 18, 18, 5)]
  398. [InlineData (8, 18, 19, 5)]
  399. [InlineData (8, 18, 20, 5)]
  400. [InlineData (8, 18, 21, 5)]
  401. [InlineData (8, 18, 22, 5)]
  402. [InlineData (8, 18, 23, 5)]
  403. // ------------------ ^
  404. [InlineData (8, 18, 24, 5)]
  405. [InlineData (8, 18, 25, 5)]
  406. //// 0123456789
  407. //// ◄████░░░░►
  408. //// ^-----------------
  409. //[InlineData (10, 20, 0, 5, 0)]
  410. //[InlineData (10, 20, 1, 5, 0)]
  411. //[InlineData (10, 20, 2, 5, 0)]
  412. //[InlineData (10, 20, 3, 5, 0)]
  413. //[InlineData (10, 20, 4, 5, 1)]
  414. //[InlineData (10, 20, 5, 5, 1)]
  415. //[InlineData (10, 20, 6, 5, 1)]
  416. //[InlineData (10, 20, 7, 5, 2)]
  417. //[InlineData (10, 20, 8, 5, 2)]
  418. //[InlineData (10, 20, 9, 5, 2)]
  419. //[InlineData (10, 20, 10, 5, 3)]
  420. //[InlineData (10, 20, 11, 5, 3)]
  421. //[InlineData (10, 20, 12, 5, 3)]
  422. //[InlineData (10, 20, 13, 5, 3)]
  423. //[InlineData (10, 20, 14, 5, 4)]
  424. //[InlineData (10, 20, 15, 5, 4)]
  425. //[InlineData (10, 20, 16, 5, 4)]
  426. //[InlineData (10, 20, 17, 5, 5)]
  427. //[InlineData (10, 20, 18, 5, 5)]
  428. //[InlineData (10, 20, 19, 5, 5)]
  429. //[InlineData (10, 20, 20, 5, 6)]
  430. //[InlineData (10, 20, 21, 5, 6)]
  431. //[InlineData (10, 20, 22, 5, 6)]
  432. //[InlineData (10, 20, 23, 5, 6)]
  433. //[InlineData (10, 20, 24, 5, 6)]
  434. //[InlineData (10, 20, 25, 5, 6)]
  435. public void CalculatePosition_Calculates_Correctly (int visibleContentSize, int scrollableContentSize, int contentPosition, int expectedSliderPosition)
  436. {
  437. // Arrange
  438. // Act
  439. var sliderPosition = ScrollSlider.CalculatePosition (
  440. scrollableContentSize: scrollableContentSize,
  441. visibleContentSize: visibleContentSize,
  442. contentPosition: contentPosition,
  443. sliderBounds: visibleContentSize,
  444. NavigationDirection.Forward);
  445. // Assert
  446. Assert.Equal (expectedSliderPosition, sliderPosition);
  447. }
  448. [Theory]
  449. [InlineData (8, 18, 0, 0)]
  450. public void CalculateContentPosition_Calculates_Correctly (
  451. int visibleContentSize,
  452. int scrollableContentSize,
  453. int sliderPosition,
  454. int expectedContentPosition
  455. )
  456. {
  457. // Arrange
  458. // Act
  459. var contentPosition = ScrollSlider.CalculateContentPosition (
  460. scrollableContentSize: scrollableContentSize,
  461. visibleContentSize: visibleContentSize,
  462. sliderPosition: sliderPosition,
  463. sliderBounds: visibleContentSize);
  464. // Assert
  465. Assert.Equal (expectedContentPosition, contentPosition);
  466. }
  467. [Theory]
  468. [CombinatorialData]
  469. public void ClampPosition_WithSuperView_Clamps_To_ViewPort_Minus_Size_If_VisibleContentSize_Not_Set ([CombinatorialRange (10, 10, 1)] int dimension, [CombinatorialRange (1, 5, 1)] int sliderSize, [CombinatorialRange (-1, 10, 2)] int sliderPosition, Orientation orientation)
  470. {
  471. View super = new ()
  472. {
  473. Id = "super",
  474. Height = dimension,
  475. Width = dimension,
  476. };
  477. var scrollSlider = new ScrollSlider
  478. {
  479. Orientation = orientation,
  480. Size = sliderSize,
  481. };
  482. super.Add (scrollSlider);
  483. super.Layout ();
  484. Assert.Equal (dimension, scrollSlider.VisibleContentSize);
  485. int clampedPosition = scrollSlider.ClampPosition (sliderPosition);
  486. Assert.InRange (clampedPosition, 0, dimension - sliderSize);
  487. }
  488. [Theory]
  489. [CombinatorialData]
  490. public void ClampPosition_WithSuperView_Clamps_To_VisibleContentSize_Minus_Size ([CombinatorialRange (10, 10, 1)] int dimension, [CombinatorialRange (1, 5, 1)] int sliderSize, [CombinatorialRange (-1, 10, 2)] int sliderPosition, Orientation orientation)
  491. {
  492. View super = new ()
  493. {
  494. Id = "super",
  495. Height = dimension + 2,
  496. Width = dimension + 2,
  497. };
  498. var scrollSlider = new ScrollSlider
  499. {
  500. Orientation = orientation,
  501. VisibleContentSize = dimension,
  502. Size = sliderSize,
  503. };
  504. super.Add (scrollSlider);
  505. super.Layout ();
  506. int clampedPosition = scrollSlider.ClampPosition (sliderPosition);
  507. Assert.InRange (clampedPosition, 0, dimension - sliderSize);
  508. }
  509. [Theory]
  510. [CombinatorialData]
  511. public void ClampPosition_NoSuperView_Clamps_To_VisibleContentSize_Minus_Size ([CombinatorialRange (10, 10, 1)] int dimension, [CombinatorialRange (1, 5, 1)] int sliderSize, [CombinatorialRange (-1, 10, 2)] int sliderPosition, Orientation orientation)
  512. {
  513. var scrollSlider = new ScrollSlider
  514. {
  515. Orientation = orientation,
  516. VisibleContentSize = dimension,
  517. Size = sliderSize,
  518. };
  519. int clampedPosition = scrollSlider.ClampPosition (sliderPosition);
  520. Assert.InRange (clampedPosition, 0, dimension - sliderSize);
  521. }
  522. [Theory]
  523. [CombinatorialData]
  524. public void Position_Clamps_To_VisibleContentSize ([CombinatorialRange (0, 5, 1)] int dimension, [CombinatorialRange (1, 5, 1)] int sliderSize, [CombinatorialRange (-1, 10, 2)] int sliderPosition, Orientation orientation)
  525. {
  526. var scrollSlider = new ScrollSlider
  527. {
  528. Orientation = orientation,
  529. VisibleContentSize = dimension,
  530. Size = sliderSize,
  531. Position = sliderPosition
  532. };
  533. Assert.True (scrollSlider.Position <= 5);
  534. }
  535. [Theory]
  536. [CombinatorialData]
  537. public void Position_Clamps_To_SuperView_Viewport ([CombinatorialRange (0, 5, 1)] int sliderSize, [CombinatorialRange (-2, 10, 2)] int sliderPosition, Orientation orientation)
  538. {
  539. var super = new View
  540. {
  541. Id = "super",
  542. Width = 5,
  543. Height = 5
  544. };
  545. var scrollSlider = new ScrollSlider
  546. {
  547. Orientation = orientation,
  548. };
  549. super.Add (scrollSlider);
  550. scrollSlider.Size = sliderSize;
  551. scrollSlider.Layout ();
  552. scrollSlider.Position = sliderPosition;
  553. Assert.True (scrollSlider.Position <= 5);
  554. }
  555. [Theory]
  556. [CombinatorialData]
  557. public void Position_Clamps_To_VisibleContentSize_With_SuperView ([CombinatorialRange (0, 5, 1)] int dimension, [CombinatorialRange (1, 5, 1)] int sliderSize, [CombinatorialRange (-2, 10, 2)] int sliderPosition, Orientation orientation)
  558. {
  559. var super = new View
  560. {
  561. Id = "super",
  562. Width = 10,
  563. Height = 10
  564. };
  565. var scrollSlider = new ScrollSlider
  566. {
  567. Orientation = orientation,
  568. VisibleContentSize = dimension,
  569. Size = sliderSize,
  570. Position = sliderPosition
  571. };
  572. super.Add (scrollSlider);
  573. scrollSlider.Size = sliderSize;
  574. scrollSlider.Layout ();
  575. scrollSlider.Position = sliderPosition;
  576. Assert.True (scrollSlider.Position <= 5);
  577. }
  578. [Theory]
  579. [SetupFakeDriver]
  580. [InlineData (
  581. 3,
  582. 10,
  583. 1,
  584. 0,
  585. Orientation.Vertical,
  586. @"
  587. ┌───┐
  588. │███│
  589. │ │
  590. │ │
  591. │ │
  592. │ │
  593. │ │
  594. │ │
  595. │ │
  596. │ │
  597. │ │
  598. └───┘")]
  599. [InlineData (
  600. 10,
  601. 1,
  602. 3,
  603. 0,
  604. Orientation.Horizontal,
  605. @"
  606. ┌──────────┐
  607. │███ │
  608. └──────────┘")]
  609. [InlineData (
  610. 3,
  611. 10,
  612. 3,
  613. 0,
  614. Orientation.Vertical,
  615. @"
  616. ┌───┐
  617. │███│
  618. │███│
  619. │███│
  620. │ │
  621. │ │
  622. │ │
  623. │ │
  624. │ │
  625. │ │
  626. │ │
  627. └───┘")]
  628. [InlineData (
  629. 3,
  630. 10,
  631. 5,
  632. 0,
  633. Orientation.Vertical,
  634. @"
  635. ┌───┐
  636. │███│
  637. │███│
  638. │███│
  639. │███│
  640. │███│
  641. │ │
  642. │ │
  643. │ │
  644. │ │
  645. │ │
  646. └───┘")]
  647. [InlineData (
  648. 3,
  649. 10,
  650. 5,
  651. 1,
  652. Orientation.Vertical,
  653. @"
  654. ┌───┐
  655. │ │
  656. │███│
  657. │███│
  658. │███│
  659. │███│
  660. │███│
  661. │ │
  662. │ │
  663. │ │
  664. │ │
  665. └───┘")]
  666. [InlineData (
  667. 3,
  668. 10,
  669. 5,
  670. 4,
  671. Orientation.Vertical,
  672. @"
  673. ┌───┐
  674. │ │
  675. │ │
  676. │ │
  677. │ │
  678. │███│
  679. │███│
  680. │███│
  681. │███│
  682. │███│
  683. │ │
  684. └───┘")]
  685. [InlineData (
  686. 3,
  687. 10,
  688. 5,
  689. 5,
  690. Orientation.Vertical,
  691. @"
  692. ┌───┐
  693. │ │
  694. │ │
  695. │ │
  696. │ │
  697. │ │
  698. │███│
  699. │███│
  700. │███│
  701. │███│
  702. │███│
  703. └───┘")]
  704. [InlineData (
  705. 3,
  706. 10,
  707. 5,
  708. 6,
  709. Orientation.Vertical,
  710. @"
  711. ┌───┐
  712. │ │
  713. │ │
  714. │ │
  715. │ │
  716. │ │
  717. │███│
  718. │███│
  719. │███│
  720. │███│
  721. │███│
  722. └───┘")]
  723. [InlineData (
  724. 3,
  725. 10,
  726. 10,
  727. 0,
  728. Orientation.Vertical,
  729. @"
  730. ┌───┐
  731. │███│
  732. │███│
  733. │███│
  734. │███│
  735. │███│
  736. │███│
  737. │███│
  738. │███│
  739. │███│
  740. │███│
  741. └───┘")]
  742. [InlineData (
  743. 3,
  744. 10,
  745. 10,
  746. 5,
  747. Orientation.Vertical,
  748. @"
  749. ┌───┐
  750. │███│
  751. │███│
  752. │███│
  753. │███│
  754. │███│
  755. │███│
  756. │███│
  757. │███│
  758. │███│
  759. │███│
  760. └───┘")]
  761. [InlineData (
  762. 3,
  763. 10,
  764. 11,
  765. 0,
  766. Orientation.Vertical,
  767. @"
  768. ┌───┐
  769. │███│
  770. │███│
  771. │███│
  772. │███│
  773. │███│
  774. │███│
  775. │███│
  776. │███│
  777. │███│
  778. │███│
  779. └───┘")]
  780. [InlineData (
  781. 10,
  782. 3,
  783. 5,
  784. 0,
  785. Orientation.Horizontal,
  786. @"
  787. ┌──────────┐
  788. │█████ │
  789. │█████ │
  790. │█████ │
  791. └──────────┘")]
  792. [InlineData (
  793. 10,
  794. 3,
  795. 5,
  796. 1,
  797. Orientation.Horizontal,
  798. @"
  799. ┌──────────┐
  800. │ █████ │
  801. │ █████ │
  802. │ █████ │
  803. └──────────┘")]
  804. [InlineData (
  805. 10,
  806. 3,
  807. 5,
  808. 4,
  809. Orientation.Horizontal,
  810. @"
  811. ┌──────────┐
  812. │ █████ │
  813. │ █████ │
  814. │ █████ │
  815. └──────────┘")]
  816. [InlineData (
  817. 10,
  818. 3,
  819. 5,
  820. 5,
  821. Orientation.Horizontal,
  822. @"
  823. ┌──────────┐
  824. │ █████│
  825. │ █████│
  826. │ █████│
  827. └──────────┘")]
  828. [InlineData (
  829. 10,
  830. 3,
  831. 5,
  832. 6,
  833. Orientation.Horizontal,
  834. @"
  835. ┌──────────┐
  836. │ █████│
  837. │ █████│
  838. │ █████│
  839. └──────────┘")]
  840. [InlineData (
  841. 10,
  842. 3,
  843. 10,
  844. 0,
  845. Orientation.Horizontal,
  846. @"
  847. ┌──────────┐
  848. │██████████│
  849. │██████████│
  850. │██████████│
  851. └──────────┘")]
  852. [InlineData (
  853. 10,
  854. 3,
  855. 10,
  856. 5,
  857. Orientation.Horizontal,
  858. @"
  859. ┌──────────┐
  860. │██████████│
  861. │██████████│
  862. │██████████│
  863. └──────────┘")]
  864. [InlineData (
  865. 10,
  866. 3,
  867. 11,
  868. 0,
  869. Orientation.Horizontal,
  870. @"
  871. ┌──────────┐
  872. │██████████│
  873. │██████████│
  874. │██████████│
  875. └──────────┘")]
  876. public void Draws_Correctly (int superViewportWidth, int superViewportHeight, int sliderSize, int position, Orientation orientation, string expected)
  877. {
  878. var super = new Window
  879. {
  880. Id = "super",
  881. Width = superViewportWidth + 2,
  882. Height = superViewportHeight + 2
  883. };
  884. var scrollSlider = new ScrollSlider
  885. {
  886. Orientation = orientation,
  887. Size = sliderSize,
  888. //Position = position,
  889. };
  890. Assert.Equal (sliderSize, scrollSlider.Size);
  891. super.Add (scrollSlider);
  892. scrollSlider.Position = position;
  893. super.Layout ();
  894. super.Draw ();
  895. _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  896. }
  897. }