GetViewsAtLocationTests.cs 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223
  1. #nullable enable
  2. namespace ViewBaseTests.Layout;
  3. [Trait ("Category", "Layout")]
  4. public class GetViewsAtLocationTests
  5. {
  6. private class TestView : View
  7. {
  8. public TestView (int x, int y, int w, int h, bool visible = true)
  9. {
  10. X = x;
  11. Y = y;
  12. Width = w;
  13. Height = h;
  14. base.Visible = visible;
  15. }
  16. }
  17. [Fact]
  18. public void ReturnsEmpty_WhenRootIsNull ()
  19. {
  20. List<View?> result = View.GetViewsAtLocation (null, new (0, 0));
  21. Assert.Empty (result);
  22. }
  23. [Fact]
  24. public void ReturnsEmpty_WhenRootIsNotVisible ()
  25. {
  26. TestView root = new (0, 0, 10, 10, false);
  27. List<View?> result = View.GetViewsAtLocation (root, new (5, 5));
  28. Assert.Empty (result);
  29. }
  30. [Fact]
  31. public void ReturnsEmpty_WhenPointOutsideRoot ()
  32. {
  33. TestView root = new (0, 0, 10, 10);
  34. List<View?> result = View.GetViewsAtLocation (root, new (20, 20));
  35. Assert.Empty (result);
  36. }
  37. [Fact]
  38. public void ReturnsEmpty_WhenPointOutsideRoot_AndSubview ()
  39. {
  40. TestView root = new (0, 0, 10, 10);
  41. TestView sub = new (5, 5, 2, 2);
  42. root.Add (sub);
  43. List<View?> result = View.GetViewsAtLocation (root, new (20, 20));
  44. Assert.Empty (result);
  45. }
  46. [Fact]
  47. public void ReturnsRoot_WhenPointInsideRoot_NoSubviews ()
  48. {
  49. TestView root = new (0, 0, 10, 10);
  50. List<View?> result = View.GetViewsAtLocation (root, new (5, 5));
  51. Assert.Single (result);
  52. Assert.Equal (root, result [0]);
  53. }
  54. [Fact]
  55. public void ReturnsRoot_And_Subview_WhenPointInsideRootMargin ()
  56. {
  57. TestView root = new (0, 0, 10, 10);
  58. root.Margin!.Thickness = new (1);
  59. TestView sub = new (2, 2, 5, 5);
  60. root.Add (sub);
  61. List<View?> result = View.GetViewsAtLocation (root, new (3, 3));
  62. Assert.Equal (2, result.Count);
  63. Assert.Equal (root, result [0]);
  64. Assert.Equal (sub, result [1]);
  65. }
  66. [Fact]
  67. public void ReturnsRoot_And_Subview_Border_WhenPointInsideRootMargin ()
  68. {
  69. TestView root = new (0, 0, 10, 10);
  70. root.Margin!.Thickness = new (1);
  71. TestView sub = new (2, 2, 5, 5);
  72. sub.BorderStyle = LineStyle.Dotted;
  73. root.Add (sub);
  74. List<View?> result = View.GetViewsAtLocation (root, new (3, 3));
  75. Assert.Equal (3, result.Count);
  76. Assert.Equal (root, result [0]);
  77. Assert.Equal (sub, result [1]);
  78. Assert.Equal (sub.Border, result [2]);
  79. }
  80. [Fact]
  81. public void ReturnsRoot_And_Margin_WhenPointInside_With_Margin ()
  82. {
  83. TestView root = new (0, 0, 10, 10);
  84. root.Margin!.Thickness = new (1);
  85. List<View?> result = View.GetViewsAtLocation (root, new (0, 0));
  86. Assert.Equal (2, result.Count);
  87. Assert.Equal (root, result [0]);
  88. Assert.Equal (root.Margin, result [1]);
  89. }
  90. [Fact]
  91. public void ReturnsRoot_WhenPointOutsideSubview_With_Margin ()
  92. {
  93. TestView root = new (0, 0, 10, 10);
  94. root.Margin!.Thickness = new (1);
  95. TestView sub = new (2, 2, 5, 5);
  96. root.Add (sub);
  97. List<View?> result = View.GetViewsAtLocation (root, new (2, 2));
  98. Assert.Single (result);
  99. Assert.Equal (root, result [0]);
  100. result = View.GetViewsAtLocation (root, new (0, 0));
  101. Assert.Equal (2, result.Count);
  102. Assert.Equal (root, result [0]);
  103. Assert.Equal (root.Margin, result [1]);
  104. result = View.GetViewsAtLocation (root, new (1, 1));
  105. Assert.Single (result);
  106. Assert.Equal (root, result [0]);
  107. result = View.GetViewsAtLocation (root, new (8, 8));
  108. Assert.Single (result);
  109. Assert.Equal (root, result [0]);
  110. }
  111. [Fact]
  112. public void ReturnsRoot_And_Border_WhenPointInside_With_Border ()
  113. {
  114. TestView root = new (0, 0, 10, 10);
  115. root.Border!.Thickness = new (1);
  116. List<View?> result = View.GetViewsAtLocation (root, new (0, 0));
  117. Assert.Equal (2, result.Count);
  118. Assert.Equal (root, result [0]);
  119. Assert.Equal (root.Border, result [1]);
  120. }
  121. [Fact]
  122. public void ReturnsRoot_WhenPointOutsideSubview_With_Border ()
  123. {
  124. TestView root = new (0, 0, 10, 10);
  125. root.Border!.Thickness = new (1);
  126. TestView sub = new (2, 2, 5, 5);
  127. root.Add (sub);
  128. List<View?> result = View.GetViewsAtLocation (root, new (2, 2));
  129. Assert.Single (result);
  130. Assert.Equal (root, result [0]);
  131. result = View.GetViewsAtLocation (root, new (0, 0));
  132. Assert.Equal (2, result.Count);
  133. Assert.Equal (root, result [0]);
  134. Assert.Equal (root.Border, result [1]);
  135. result = View.GetViewsAtLocation (root, new (1, 1));
  136. Assert.Single (result);
  137. Assert.Equal (root, result [0]);
  138. result = View.GetViewsAtLocation (root, new (8, 8));
  139. Assert.Single (result);
  140. Assert.Equal (root, result [0]);
  141. }
  142. [Fact]
  143. public void ReturnsRoot_And_Border_WhenPointInsideRootBorder ()
  144. {
  145. TestView root = new (0, 0, 10, 10);
  146. root.Border!.Thickness = new (1);
  147. List<View?> result = View.GetViewsAtLocation (root, new (0, 0));
  148. Assert.Equal (2, result.Count);
  149. Assert.Equal (root, result [0]);
  150. Assert.Equal (root.Border, result [1]);
  151. }
  152. [Fact]
  153. public void ReturnsRoot_And_Padding_WhenPointInsideRootPadding ()
  154. {
  155. TestView root = new (0, 0, 10, 10);
  156. root.Padding!.Thickness = new (1);
  157. List<View?> result = View.GetViewsAtLocation (root, new (0, 0));
  158. Assert.Equal (2, result.Count);
  159. Assert.Equal (root, result [0]);
  160. Assert.Equal (root.Padding, result [1]);
  161. }
  162. [Fact]
  163. public void ReturnsRootAndSubview_WhenPointInsideSubview ()
  164. {
  165. TestView root = new (0, 0, 10, 10);
  166. TestView sub = new (2, 2, 5, 5);
  167. root.Add (sub);
  168. List<View?> result = View.GetViewsAtLocation (root, new (3, 3));
  169. Assert.Equal (2, result.Count);
  170. Assert.Equal (root, result [0]);
  171. Assert.Equal (sub, result [1]);
  172. }
  173. [Fact]
  174. public void ReturnsRootAndSubviewAndMargin_WhenPointInsideSubviewMargin ()
  175. {
  176. TestView root = new (0, 0, 10, 10);
  177. TestView sub = new (2, 2, 5, 5);
  178. sub.Margin!.Thickness = new (1);
  179. root.Add (sub);
  180. List<View?> result = View.GetViewsAtLocation (root, new (6, 6));
  181. Assert.Equal (3, result.Count);
  182. Assert.Equal (root, result [0]);
  183. Assert.Equal (sub, result [1]);
  184. Assert.Equal (sub.Margin, result [2]);
  185. }
  186. [Fact]
  187. public void ReturnsRootAndSubviewAndBorder_WhenPointInsideSubviewBorder ()
  188. {
  189. TestView root = new (0, 0, 10, 10);
  190. TestView sub = new (2, 2, 5, 5);
  191. sub.Border!.Thickness = new (1);
  192. root.Add (sub);
  193. List<View?> result = View.GetViewsAtLocation (root, new (2, 2));
  194. Assert.Equal (3, result.Count);
  195. Assert.Equal (root, result [0]);
  196. Assert.Equal (sub, result [1]);
  197. Assert.Equal (sub.Border, result [2]);
  198. }
  199. [Fact]
  200. public void ReturnsRootAndSubviewAndSubviewAndBorder_WhenPointInsideSubviewBorder ()
  201. {
  202. TestView root = new (2, 2, 10, 10);
  203. TestView sub = new (2, 2, 5, 5);
  204. sub.Border!.Thickness = new (1);
  205. root.Add (sub);
  206. List<View?> result = View.GetViewsAtLocation (root, new (4, 4));
  207. Assert.Equal (3, result.Count);
  208. Assert.Equal (root, result [0]);
  209. Assert.Equal (sub, result [1]);
  210. Assert.Equal (sub.Border, result [2]);
  211. }
  212. [Fact]
  213. public void ReturnsRootAndSubviewAndBorder_WhenPointInsideSubviewPadding ()
  214. {
  215. TestView root = new (0, 0, 10, 10);
  216. TestView sub = new (2, 2, 5, 5);
  217. sub.Padding!.Thickness = new (1);
  218. root.Add (sub);
  219. List<View?> result = View.GetViewsAtLocation (root, new (2, 2));
  220. Assert.Equal (3, result.Count);
  221. Assert.Equal (root, result [0]);
  222. Assert.Equal (sub, result [1]);
  223. Assert.Equal (sub.Padding, result [2]);
  224. }
  225. [Fact]
  226. public void ReturnsRootAndSubviewAndMarginAndShadowView_WhenPointInsideSubviewMargin ()
  227. {
  228. TestView root = new (0, 0, 10, 10);
  229. TestView sub = new (2, 2, 5, 5);
  230. sub.ShadowStyle = ShadowStyle.Opaque;
  231. root.Add (sub);
  232. root.Layout ();
  233. List<View?> result = View.GetViewsAtLocation (root, new (6, 6));
  234. Assert.Equal (5, result.Count);
  235. Assert.Equal (root, result [0]);
  236. Assert.Equal (sub, result [1]);
  237. Assert.Equal (sub.Margin, result [2]);
  238. Assert.Equal (sub.Margin!.SubViews.ElementAt (0), result [3]);
  239. Assert.Equal (sub.Margin!.SubViews.ElementAt (1), result [4]);
  240. }
  241. [Fact]
  242. public void ReturnsRootAndSubviewAndBorderAndButton_WhenPointInsideSubviewBorder ()
  243. {
  244. TestView root = new (0, 0, 10, 10);
  245. TestView sub = new (2, 2, 5, 5);
  246. sub.Border!.Thickness = new (1);
  247. var closeButton = new Button
  248. {
  249. NoDecorations = true,
  250. NoPadding = true,
  251. Title = "X",
  252. Width = 1,
  253. Height = 1,
  254. X = Pos.AnchorEnd (),
  255. Y = 0,
  256. ShadowStyle = ShadowStyle.None
  257. };
  258. sub.Border!.Add (closeButton);
  259. root.Add (sub);
  260. root.Layout ();
  261. List<View?> result = View.GetViewsAtLocation (root, new (6, 2));
  262. Assert.Equal (4, result.Count);
  263. Assert.Equal (root, result [0]);
  264. Assert.Equal (sub, result [1]);
  265. Assert.Equal (sub.Border, result [2]);
  266. Assert.Equal (closeButton, result [3]);
  267. }
  268. [Fact]
  269. public void ReturnsDeepestSubview_WhenNested ()
  270. {
  271. TestView root = new (0, 0, 20, 20);
  272. var sub1 = new TestView (2, 2, 16, 16);
  273. var sub2 = new TestView (3, 3, 10, 10);
  274. var sub3 = new TestView (1, 1, 5, 5);
  275. root.Add (sub1);
  276. sub1.Add (sub2);
  277. sub2.Add (sub3);
  278. // Point inside all
  279. List<View?> result = View.GetViewsAtLocation (root, new (7, 7));
  280. Assert.Equal (4, result.Count);
  281. Assert.Equal (root, result [0]);
  282. Assert.Equal (sub1, result [1]);
  283. Assert.Equal (sub2, result [2]);
  284. Assert.Equal (sub3, result [3]);
  285. }
  286. [Fact]
  287. public void ReturnsTopmostSubview_WhenOverlapping ()
  288. {
  289. TestView root = new (0, 0, 10, 10);
  290. var sub1 = new TestView (2, 2, 6, 6);
  291. var sub2 = new TestView (4, 4, 6, 6);
  292. root.Add (sub1);
  293. root.Add (sub2); // sub2 is on top
  294. List<View?> result = View.GetViewsAtLocation (root, new (5, 5));
  295. Assert.Equal (3, result.Count);
  296. Assert.Equal (root, result [0]);
  297. Assert.Equal (sub1, result [1]);
  298. Assert.Equal (sub2, result [2]);
  299. }
  300. [Fact]
  301. public void ReturnsTopmostSubview_WhenNotOverlapping ()
  302. {
  303. TestView root = new (0, 0, 10, 10); // under 5,5,
  304. var sub1 = new TestView (10, 10, 6, 6); // not under location 5,5
  305. var sub2 = new TestView (4, 4, 6, 6); // under 5,5,
  306. root.Add (sub1);
  307. root.Add (sub2); // sub2 is on top
  308. List<View?> result = View.GetViewsAtLocation (root, new (5, 5));
  309. Assert.Equal (2, result.Count);
  310. Assert.Equal (root, result [0]);
  311. Assert.Equal (sub2, result [1]);
  312. }
  313. [Fact]
  314. public void SkipsInvisibleSubviews ()
  315. {
  316. TestView root = new (0, 0, 10, 10);
  317. var sub1 = new TestView (2, 2, 6, 6, false);
  318. var sub2 = new TestView (4, 4, 6, 6);
  319. root.Add (sub1);
  320. root.Add (sub2);
  321. List<View?> result = View.GetViewsAtLocation (root, new (5, 5));
  322. Assert.Equal (2, result.Count);
  323. Assert.Equal (root, result [0]);
  324. Assert.Equal (sub2, result [1]);
  325. }
  326. [Fact]
  327. public void ReturnsRoot_WhenPointOnEdge ()
  328. {
  329. TestView root = new (0, 0, 10, 10);
  330. List<View?> result = View.GetViewsAtLocation (root, new (0, 0));
  331. Assert.Single (result);
  332. Assert.Equal (root, result [0]);
  333. }
  334. [Fact]
  335. public void ReturnsRoot_WhenPointOnBottomRightCorner ()
  336. {
  337. TestView root = new (0, 0, 10, 10);
  338. List<View?> result = View.GetViewsAtLocation (root, new (9, 9));
  339. Assert.Single (result);
  340. Assert.Equal (root, result [0]);
  341. }
  342. [Fact]
  343. public void ReturnsEmpty_WhenAllSubviewsInvisible ()
  344. {
  345. TestView root = new (0, 0, 10, 10);
  346. var sub1 = new TestView (2, 2, 6, 6, false);
  347. root.Add (sub1);
  348. List<View?> result = View.GetViewsAtLocation (root, new (3, 3));
  349. Assert.Single (result);
  350. Assert.Equal (root, result [0]);
  351. }
  352. [Theory]
  353. [InlineData (0, 0, 0, 0, 0, -1, -1, new string [] { })]
  354. [InlineData (0, 0, 0, 0, 0, 0, 0, new [] { "Top" })]
  355. [InlineData (0, 0, 0, 0, 0, 1, 1, new [] { "Top" })]
  356. [InlineData (0, 0, 0, 0, 0, 4, 4, new [] { "Top" })]
  357. [InlineData (0, 0, 0, 0, 0, 9, 9, new [] { "Top" })]
  358. [InlineData (0, 0, 0, 0, 0, 10, 10, new string [] { })]
  359. [InlineData (1, 1, 0, 0, 0, -1, -1, new string [] { })]
  360. [InlineData (1, 1, 0, 0, 0, 0, 0, new string [] { })]
  361. [InlineData (1, 1, 0, 0, 0, 1, 1, new [] { "Top" })]
  362. [InlineData (1, 1, 0, 0, 0, 4, 4, new [] { "Top" })]
  363. [InlineData (1, 1, 0, 0, 0, 9, 9, new [] { "Top" })]
  364. [InlineData (1, 1, 0, 0, 0, 10, 10, new [] { "Top" })]
  365. [InlineData (0, 0, 1, 0, 0, -1, -1, new string [] { })]
  366. [InlineData (0, 0, 1, 0, 0, 0, 0, new string [] { })] //margin is ViewportSettings.TransparentToMouse
  367. [InlineData (0, 0, 1, 0, 0, 1, 1, new [] { "Top" })]
  368. [InlineData (0, 0, 1, 0, 0, 4, 4, new [] { "Top" })]
  369. [InlineData (0, 0, 1, 0, 0, 9, 9, new string [] { })] //margin is ViewportSettings.TransparentToMouse
  370. [InlineData (0, 0, 1, 0, 0, 10, 10, new string [] { })]
  371. [InlineData (0, 0, 1, 1, 0, -1, -1, new string [] { })]
  372. [InlineData (0, 0, 1, 1, 0, 0, 0, new string [] { })] //margin is ViewportSettings.TransparentToMouse
  373. [InlineData (0, 0, 1, 1, 0, 1, 1, new [] { "Top", "Border" })]
  374. [InlineData (0, 0, 1, 1, 0, 4, 4, new [] { "Top" })]
  375. [InlineData (0, 0, 1, 1, 0, 9, 9, new string [] { })] //margin is ViewportSettings.TransparentToMouse
  376. [InlineData (0, 0, 1, 1, 0, 10, 10, new string [] { })]
  377. [InlineData (0, 0, 1, 1, 1, -1, -1, new string [] { })]
  378. [InlineData (0, 0, 1, 1, 1, 0, 0, new string [] { })] //margin is ViewportSettings.TransparentToMouse
  379. [InlineData (0, 0, 1, 1, 1, 1, 1, new [] { "Top", "Border" })]
  380. [InlineData (0, 0, 1, 1, 1, 2, 2, new [] { "Top", "Padding" })]
  381. [InlineData (0, 0, 1, 1, 1, 4, 4, new [] { "Top" })]
  382. [InlineData (0, 0, 1, 1, 1, 9, 9, new string [] { })] //margin is ViewportSettings.TransparentToMouse
  383. [InlineData (0, 0, 1, 1, 1, 10, 10, new string [] { })]
  384. [InlineData (1, 1, 1, 0, 0, -1, -1, new string [] { })]
  385. [InlineData (1, 1, 1, 0, 0, 0, 0, new string [] { })]
  386. [InlineData (1, 1, 1, 0, 0, 1, 1, new string [] { })] //margin is ViewportSettings.TransparentToMouse
  387. [InlineData (1, 1, 1, 0, 0, 4, 4, new [] { "Top" })]
  388. [InlineData (1, 1, 1, 0, 0, 9, 9, new [] { "Top" })]
  389. [InlineData (1, 1, 1, 0, 0, 10, 10, new string [] { })] //margin is ViewportSettings.TransparentToMouse
  390. [InlineData (1, 1, 1, 1, 0, -1, -1, new string [] { })]
  391. [InlineData (1, 1, 1, 1, 0, 0, 0, new string [] { })]
  392. [InlineData (1, 1, 1, 1, 0, 1, 1, new string [] { })] //margin is ViewportSettings.TransparentToMouse
  393. [InlineData (1, 1, 1, 1, 0, 4, 4, new [] { "Top" })]
  394. [InlineData (1, 1, 1, 1, 0, 9, 9, new [] { "Top", "Border" })]
  395. [InlineData (1, 1, 1, 1, 0, 10, 10, new string [] { })] //margin is ViewportSettings.TransparentToMouse
  396. [InlineData (1, 1, 1, 1, 1, -1, -1, new string [] { })]
  397. [InlineData (1, 1, 1, 1, 1, 0, 0, new string [] { })]
  398. [InlineData (1, 1, 1, 1, 1, 1, 1, new string [] { })] //margin is ViewportSettings.TransparentToMouse
  399. [InlineData (1, 1, 1, 1, 1, 2, 2, new [] { "Top", "Border" })]
  400. [InlineData (1, 1, 1, 1, 1, 3, 3, new [] { "Top", "Padding" })]
  401. [InlineData (1, 1, 1, 1, 1, 4, 4, new [] { "Top" })]
  402. [InlineData (1, 1, 1, 1, 1, 8, 8, new [] { "Top", "Padding" })]
  403. [InlineData (1, 1, 1, 1, 1, 9, 9, new [] { "Top", "Border" })]
  404. [InlineData (1, 1, 1, 1, 1, 10, 10, new string [] { })] //margin is ViewportSettings.TransparentToMouse
  405. public void Top_Adornments_Returns_Correct_View (
  406. int frameX,
  407. int frameY,
  408. int marginThickness,
  409. int borderThickness,
  410. int paddingThickness,
  411. int testX,
  412. int testY,
  413. string [] expectedViewsFound
  414. )
  415. {
  416. // Arrange
  417. Runnable<bool>? runnable = new ()
  418. {
  419. Id = "Top",
  420. Frame = new (frameX, frameY, 10, 10)
  421. };
  422. IApplication? app = Application.Create ();
  423. app.Begin (runnable);
  424. runnable.Margin!.Thickness = new (marginThickness);
  425. runnable.Margin!.Id = "Margin";
  426. runnable.Border!.Thickness = new (borderThickness);
  427. runnable.Border!.Id = "Border";
  428. runnable.Padding!.Thickness = new (paddingThickness);
  429. runnable.Padding.Id = "Padding";
  430. var location = new Point (testX, testY);
  431. // Act
  432. List<View?> viewsUnderMouse = runnable.GetViewsUnderLocation (location, ViewportSettingsFlags.TransparentMouse);
  433. // Assert
  434. if (expectedViewsFound.Length == 0)
  435. {
  436. Assert.Empty (viewsUnderMouse);
  437. }
  438. else
  439. {
  440. string [] foundIds = viewsUnderMouse.Select (v => v!.Id).ToArray ();
  441. Assert.Equal (expectedViewsFound, foundIds);
  442. }
  443. }
  444. [Theory]
  445. [InlineData (0, 0)]
  446. [InlineData (1, 1)]
  447. [InlineData (2, 2)]
  448. public void Returns_Top_If_No_SubViews (int testX, int testY)
  449. {
  450. // Arrange
  451. Runnable<bool>? runnable = new ()
  452. {
  453. Frame = new (0, 0, 10, 10)
  454. };
  455. IApplication? app = Application.Create ();
  456. app.Begin (runnable);
  457. var location = new Point (testX, testY);
  458. // Act
  459. List<View?> viewsUnderMouse = runnable.GetViewsUnderLocation (location, ViewportSettingsFlags.TransparentMouse);
  460. // Assert
  461. Assert.Contains (viewsUnderMouse, v => v == runnable);
  462. runnable.Dispose ();
  463. }
  464. // Test that GetViewsUnderLocation returns the correct view if the start view has no subviews
  465. [Theory]
  466. [InlineData (0, 0)]
  467. [InlineData (1, 1)]
  468. [InlineData (2, 2)]
  469. public void Returns_Start_If_No_SubViews (int testX, int testY)
  470. {
  471. Runnable<bool>? runnable = new ()
  472. {
  473. Width = 10, Height = 10
  474. };
  475. IApplication? app = Application.Create ();
  476. app.Begin (runnable);
  477. Assert.Same (runnable, runnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ());
  478. runnable.Dispose ();
  479. }
  480. // Test that GetViewsUnderLocation returns the correct view if the start view has subviews
  481. [Theory]
  482. [InlineData (0, 0, false)]
  483. [InlineData (1, 1, false)]
  484. [InlineData (9, 9, false)]
  485. [InlineData (10, 10, false)]
  486. [InlineData (6, 7, false)]
  487. [InlineData (1, 2, true)]
  488. [InlineData (5, 6, true)]
  489. public void Returns_Correct_If_SubViews (int testX, int testY, bool expectedSubViewFound)
  490. {
  491. Runnable<bool>? runnable = new ()
  492. {
  493. Width = 10, Height = 10
  494. };
  495. IApplication? app = Application.Create ();
  496. app.Begin (runnable);
  497. var subview = new View
  498. {
  499. X = 1, Y = 2,
  500. Width = 5, Height = 5
  501. };
  502. runnable.Add (subview);
  503. View? found = runnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ();
  504. Assert.Equal (expectedSubViewFound, found == subview);
  505. runnable.Dispose ();
  506. }
  507. [Theory]
  508. [InlineData (0, 0, false)]
  509. [InlineData (1, 1, false)]
  510. [InlineData (9, 9, false)]
  511. [InlineData (10, 10, false)]
  512. [InlineData (6, 7, false)]
  513. [InlineData (1, 2, false)]
  514. [InlineData (5, 6, false)]
  515. public void Returns_Null_If_SubView_NotVisible (int testX, int testY, bool expectedSubViewFound)
  516. {
  517. Runnable<bool>? runnable = new ()
  518. {
  519. Width = 10, Height = 10
  520. };
  521. var subview = new View
  522. {
  523. X = 1, Y = 2,
  524. Width = 5, Height = 5,
  525. Visible = false
  526. };
  527. runnable.Add (subview);
  528. View? found = runnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ();
  529. Assert.Equal (expectedSubViewFound, found == subview);
  530. runnable.Dispose ();
  531. }
  532. [Theory]
  533. [InlineData (0, 0, false)]
  534. [InlineData (1, 1, false)]
  535. [InlineData (9, 9, false)]
  536. [InlineData (10, 10, false)]
  537. [InlineData (6, 7, false)]
  538. [InlineData (1, 2, false)]
  539. [InlineData (5, 6, false)]
  540. public void Returns_Null_If_Not_Visible_And_SubView_Visible (int testX, int testY, bool expectedSubViewFound)
  541. {
  542. Runnable<bool>? runnable = new ()
  543. {
  544. Width = 10, Height = 10,
  545. Visible = false
  546. };
  547. var subview = new View
  548. {
  549. X = 1, Y = 2,
  550. Width = 5, Height = 5
  551. };
  552. runnable.Add (subview);
  553. subview.Visible = true;
  554. Assert.True (subview.Visible);
  555. Assert.False (runnable.Visible);
  556. View? found = runnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ();
  557. Assert.Equal (expectedSubViewFound, found == subview);
  558. runnable.Dispose ();
  559. }
  560. // Test that GetViewsUnderLocation works if the start view has positive Adornments
  561. [Theory]
  562. [InlineData (0, 0, false)]
  563. [InlineData (1, 1, false)]
  564. [InlineData (9, 9, false)]
  565. [InlineData (10, 10, false)]
  566. [InlineData (7, 8, false)]
  567. [InlineData (1, 2, false)]
  568. [InlineData (2, 3, true)]
  569. [InlineData (5, 6, true)]
  570. [InlineData (6, 7, true)]
  571. public void Returns_Correct_If_Start_Has_Adornments (int testX, int testY, bool expectedSubViewFound)
  572. {
  573. Runnable<bool>? runnable = new ()
  574. {
  575. Width = 10, Height = 10
  576. };
  577. IApplication? app = Application.Create ();
  578. app.Begin (runnable);
  579. runnable.Margin!.Thickness = new (1);
  580. var subview = new View
  581. {
  582. X = 1, Y = 2,
  583. Width = 5, Height = 5
  584. };
  585. runnable.Add (subview);
  586. View? found = runnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ();
  587. Assert.Equal (expectedSubViewFound, found == subview);
  588. runnable.Dispose ();
  589. }
  590. // Test that GetViewsUnderLocation works if the start view has offset Viewport location
  591. [Theory]
  592. [InlineData (1, 0, 0, true)]
  593. [InlineData (1, 1, 1, true)]
  594. [InlineData (1, 2, 2, false)]
  595. [InlineData (-1, 3, 3, true)]
  596. [InlineData (-1, 2, 2, true)]
  597. [InlineData (-1, 1, 1, false)]
  598. [InlineData (-1, 0, 0, false)]
  599. public void Returns_Correct_If_Start_Has_Offset_Viewport (int offset, int testX, int testY, bool expectedSubViewFound)
  600. {
  601. Runnable<bool>? runnable = new ()
  602. {
  603. Width = 10, Height = 10,
  604. ViewportSettings = ViewportSettingsFlags.AllowNegativeLocation
  605. };
  606. IApplication? app = Application.Create ();
  607. app.Begin (runnable);
  608. runnable.Viewport = new (offset, offset, 10, 10);
  609. var subview = new View
  610. {
  611. X = 1, Y = 1,
  612. Width = 2, Height = 2
  613. };
  614. runnable.Add (subview);
  615. View? found = runnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ();
  616. Assert.Equal (expectedSubViewFound, found == subview);
  617. runnable.Dispose ();
  618. }
  619. [Theory]
  620. [InlineData (9, 9, true)]
  621. [InlineData (0, 0, false)]
  622. [InlineData (1, 1, false)]
  623. [InlineData (10, 10, false)]
  624. [InlineData (7, 8, false)]
  625. [InlineData (1, 2, false)]
  626. [InlineData (2, 3, false)]
  627. [InlineData (5, 6, false)]
  628. [InlineData (6, 7, false)]
  629. public void Returns_Correct_If_Start_Has_Adornment_WithSubView (int testX, int testY, bool expectedSubViewFound)
  630. {
  631. Runnable<bool>? runnable = new ()
  632. {
  633. Width = 10, Height = 10
  634. };
  635. IApplication? app = Application.Create ();
  636. app.Begin (runnable);
  637. runnable.Padding!.Thickness = new (1);
  638. var subview = new View
  639. {
  640. X = Pos.AnchorEnd (1), Y = Pos.AnchorEnd (1),
  641. Width = 1, Height = 1
  642. };
  643. runnable.Padding.Add (subview);
  644. View? found = runnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ();
  645. Assert.Equal (expectedSubViewFound, found == subview);
  646. runnable.Dispose ();
  647. }
  648. [Theory]
  649. [InlineData (0, 0, new string [] { })]
  650. [InlineData (9, 9, new string [] { })]
  651. [InlineData (1, 1, new [] { "Top", "Border" })]
  652. [InlineData (8, 8, new [] { "Top", "Border" })]
  653. [InlineData (2, 2, new [] { "Top", "Padding" })]
  654. [InlineData (7, 7, new [] { "Top", "Padding" })]
  655. [InlineData (5, 5, new [] { "Top" })]
  656. public void Returns_Adornment_If_Start_Has_Adornments (int testX, int testY, string [] expectedViewsFound)
  657. {
  658. IApplication? app = Application.Create ();
  659. Runnable<bool>? runnable = new ()
  660. {
  661. Id = "Top",
  662. Width = 10, Height = 10
  663. };
  664. app.Begin (runnable);
  665. runnable.Margin!.Thickness = new (1);
  666. runnable.Margin!.Id = "Margin";
  667. runnable.Border!.Thickness = new (1);
  668. runnable.Border!.Id = "Border";
  669. runnable.Padding!.Thickness = new (1);
  670. runnable.Padding.Id = "Padding";
  671. var subview = new View
  672. {
  673. Id = "SubView",
  674. X = 1, Y = 1,
  675. Width = 1, Height = 1
  676. };
  677. runnable.Add (subview);
  678. List<View?> viewsUnderMouse = runnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse);
  679. string [] foundIds = viewsUnderMouse.Select (v => v!.Id).ToArray ();
  680. Assert.Equal (expectedViewsFound, foundIds);
  681. runnable.Dispose ();
  682. }
  683. // Test that GetViewsUnderLocation works if the subview has positive Adornments
  684. [Theory]
  685. [InlineData (0, 0, new [] { "Top" })]
  686. [InlineData (1, 1, new [] { "Top" })]
  687. [InlineData (9, 9, new [] { "Top" })]
  688. [InlineData (10, 10, new string [] { })]
  689. [InlineData (7, 8, new [] { "Top" })]
  690. [InlineData (6, 7, new [] { "Top" })]
  691. [InlineData (1, 2, new [] { "Top", "subview", "border" })]
  692. [InlineData (5, 6, new [] { "Top", "subview", "border" })]
  693. [InlineData (2, 3, new [] { "Top", "subview" })]
  694. public void Returns_Correct_If_SubView_Has_Adornments (int testX, int testY, string [] expectedViewsFound)
  695. {
  696. Runnable<bool>? runnable = new ()
  697. {
  698. Id = "Top",
  699. Width = 10, Height = 10
  700. };
  701. IApplication? app = Application.Create ();
  702. app.Begin (runnable);
  703. var subview = new View
  704. {
  705. Id = "subview",
  706. X = 1, Y = 2,
  707. Width = 5, Height = 5
  708. };
  709. subview.Border!.Thickness = new (1);
  710. subview.Border!.Id = "border";
  711. runnable.Add (subview);
  712. List<View?> viewsUnderMouse = runnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse);
  713. string [] foundIds = viewsUnderMouse.Select (v => v!.Id).ToArray ();
  714. Assert.Equal (expectedViewsFound, foundIds);
  715. runnable.Dispose ();
  716. }
  717. // Test that GetViewsUnderLocation works if the subview has positive Adornments
  718. [Theory]
  719. [InlineData (0, 0, new [] { "Top" })]
  720. [InlineData (1, 1, new [] { "Top" })]
  721. [InlineData (9, 9, new [] { "Top" })]
  722. [InlineData (10, 10, new string [] { })]
  723. [InlineData (7, 8, new [] { "Top" })]
  724. [InlineData (6, 7, new [] { "Top" })]
  725. [InlineData (1, 2, new [] { "Top" })]
  726. [InlineData (5, 6, new [] { "Top" })]
  727. [InlineData (2, 3, new [] { "Top", "subview" })]
  728. public void Returns_Correct_If_SubView_Has_Adornments_With_TransparentMouse (int testX, int testY, string [] expectedViewsFound)
  729. {
  730. Runnable<bool>? runnable = new ()
  731. {
  732. Id = "Top",
  733. Width = 10, Height = 10
  734. };
  735. IApplication? app = Application.Create ();
  736. app.Begin (runnable);
  737. var subview = new View
  738. {
  739. Id = "subview",
  740. X = 1, Y = 2,
  741. Width = 5, Height = 5
  742. };
  743. subview.Border!.Thickness = new (1);
  744. subview.Border!.ViewportSettings = ViewportSettingsFlags.TransparentMouse;
  745. subview.Border!.Id = "border";
  746. runnable.Add (subview);
  747. List<View?> viewsUnderMouse = runnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse);
  748. string [] foundIds = viewsUnderMouse.Select (v => v!.Id).ToArray ();
  749. Assert.Equal (expectedViewsFound, foundIds);
  750. runnable.Dispose ();
  751. }
  752. [Theory]
  753. [InlineData (0, 0, false)]
  754. [InlineData (1, 1, false)]
  755. [InlineData (9, 9, false)]
  756. [InlineData (10, 10, false)]
  757. [InlineData (7, 8, false)]
  758. [InlineData (6, 7, false)]
  759. [InlineData (1, 2, false)]
  760. [InlineData (5, 6, false)]
  761. [InlineData (6, 5, false)]
  762. [InlineData (5, 5, true)]
  763. public void Returns_Correct_If_SubView_Has_Adornment_WithSubView (int testX, int testY, bool expectedSubViewFound)
  764. {
  765. Runnable<bool>? runnable = new ()
  766. {
  767. Width = 10, Height = 10
  768. };
  769. IApplication? app = Application.Create ();
  770. app.Begin (runnable);
  771. // A subview with + Padding
  772. var subview = new View
  773. {
  774. X = 1, Y = 1,
  775. Width = 5, Height = 5
  776. };
  777. subview.Padding!.Thickness = new (1);
  778. // This subview will be at the bottom-right-corner of subview
  779. // So screen-relative location will be X + Width - 1 = 5
  780. var paddingSubView = new View
  781. {
  782. X = Pos.AnchorEnd (1),
  783. Y = Pos.AnchorEnd (1),
  784. Width = 1,
  785. Height = 1
  786. };
  787. subview.Padding.Add (paddingSubView);
  788. runnable.Add (subview);
  789. View? found = runnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ();
  790. Assert.Equal (expectedSubViewFound, found == paddingSubView);
  791. runnable.Dispose ();
  792. }
  793. [Theory]
  794. [InlineData (0, 0, false)]
  795. [InlineData (1, 1, false)]
  796. [InlineData (9, 9, false)]
  797. [InlineData (10, 10, false)]
  798. [InlineData (7, 8, false)]
  799. [InlineData (6, 7, false)]
  800. [InlineData (1, 2, false)]
  801. [InlineData (5, 6, false)]
  802. [InlineData (6, 5, false)]
  803. [InlineData (5, 5, true)]
  804. public void Returns_Correct_If_SubView_Is_Scrolled_And_Has_Adornment_WithSubView (int testX, int testY, bool expectedSubViewFound)
  805. {
  806. Runnable<bool>? runnable = new ()
  807. {
  808. Width = 10, Height = 10
  809. };
  810. IApplication? app = Application.Create ();
  811. app.Begin (runnable);
  812. // A subview with + Padding
  813. var subview = new View
  814. {
  815. X = 1, Y = 1,
  816. Width = 5, Height = 5
  817. };
  818. subview.Padding!.Thickness = new (1);
  819. // Scroll the subview
  820. subview.SetContentSize (new (10, 10));
  821. subview.Viewport = subview.Viewport with { Location = new (1, 1) };
  822. // This subview will be at the bottom-right-corner of subview
  823. // So screen-relative location will be X + Width - 1 = 5
  824. var paddingSubView = new View
  825. {
  826. X = Pos.AnchorEnd (1),
  827. Y = Pos.AnchorEnd (1),
  828. Width = 1,
  829. Height = 1
  830. };
  831. subview.Padding.Add (paddingSubView);
  832. runnable.Add (subview);
  833. View? found = runnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ();
  834. Assert.Equal (expectedSubViewFound, found == paddingSubView);
  835. runnable.Dispose ();
  836. }
  837. // Test that GetViewsUnderLocation works with nested subviews
  838. [Theory]
  839. [InlineData (0, 0, -1)]
  840. [InlineData (9, 9, -1)]
  841. [InlineData (10, 10, -1)]
  842. [InlineData (1, 1, 0)]
  843. [InlineData (1, 2, 0)]
  844. [InlineData (2, 2, 1)]
  845. [InlineData (3, 3, 2)]
  846. [InlineData (5, 5, 2)]
  847. public void Returns_Correct_With_NestedSubViews (int testX, int testY, int expectedSubViewFound)
  848. {
  849. Runnable<bool>? runnable = new ()
  850. {
  851. Width = 10, Height = 10
  852. };
  853. IApplication? app = Application.Create ();
  854. app.Begin (runnable);
  855. var numSubViews = 3;
  856. List<View> subviews = new ();
  857. for (var i = 0; i < numSubViews; i++)
  858. {
  859. var subview = new View
  860. {
  861. X = 1, Y = 1,
  862. Width = 5, Height = 5
  863. };
  864. subviews.Add (subview);
  865. if (i > 0)
  866. {
  867. subviews [i - 1].Add (subview);
  868. }
  869. }
  870. runnable.Add (subviews [0]);
  871. View? found = runnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ();
  872. Assert.Equal (expectedSubViewFound, subviews.IndexOf (found!));
  873. runnable.Dispose ();
  874. }
  875. [Theory]
  876. [InlineData (0, 0, new [] { "top" })]
  877. [InlineData (9, 9, new [] { "top" })]
  878. [InlineData (10, 10, new string [] { })]
  879. [InlineData (1, 1, new [] { "top", "view" })]
  880. [InlineData (1, 2, new [] { "top", "view" })]
  881. [InlineData (2, 1, new [] { "top", "view" })]
  882. [InlineData (2, 2, new [] { "top", "view", "subView" })]
  883. [InlineData (3, 3, new [] { "top" })] // clipped
  884. [InlineData (2, 3, new [] { "top" })] // clipped
  885. public void Tiled_SubViews (int mouseX, int mouseY, string [] viewIdStrings)
  886. {
  887. // Arrange
  888. Runnable<bool>? runnable = new ()
  889. {
  890. Frame = new (0, 0, 10, 10),
  891. Id = "top"
  892. };
  893. IApplication? app = Application.Create ();
  894. app.Begin (runnable);
  895. var view = new View
  896. {
  897. Id = "view",
  898. X = 1,
  899. Y = 1,
  900. Width = 2,
  901. Height = 2,
  902. Arrangement = ViewArrangement.Overlapped
  903. }; // at 1,1 to 3,2 (screen)
  904. var subView = new View
  905. {
  906. Id = "subView",
  907. X = 1,
  908. Y = 1,
  909. Width = 2,
  910. Height = 2,
  911. Arrangement = ViewArrangement.Overlapped
  912. }; // at 2,2 to 4,3 (screen)
  913. view.Add (subView);
  914. runnable.Add (view);
  915. List<View?> found = runnable.GetViewsUnderLocation (new (mouseX, mouseY), ViewportSettingsFlags.TransparentMouse);
  916. string [] foundIds = found.Select (v => v!.Id).ToArray ();
  917. Assert.Equal (viewIdStrings, foundIds);
  918. runnable.Dispose ();
  919. }
  920. [Theory]
  921. [InlineData (0, 0, new [] { "top" })]
  922. [InlineData (9, 9, new [] { "top" })]
  923. [InlineData (10, 10, new string [] { })]
  924. [InlineData (-1, -1, new string [] { })]
  925. [InlineData (1, 1, new [] { "top", "view" })]
  926. [InlineData (1, 2, new [] { "top", "view" })]
  927. [InlineData (2, 1, new [] { "top", "view" })]
  928. [InlineData (2, 2, new [] { "top", "view", "popover" })]
  929. [InlineData (3, 3, new [] { "top" })] // clipped
  930. [InlineData (2, 3, new [] { "top" })] // clipped
  931. public void Popover (int mouseX, int mouseY, string [] viewIdStrings)
  932. {
  933. // Arrange
  934. Runnable<bool>? runnable = new ()
  935. {
  936. Frame = new (0, 0, 10, 10),
  937. Id = "top"
  938. };
  939. IApplication? app = Application.Create ();
  940. app.Begin (runnable);
  941. var view = new View
  942. {
  943. Id = "view",
  944. X = 1,
  945. Y = 1,
  946. Width = 2,
  947. Height = 2,
  948. Arrangement = ViewArrangement.Overlapped
  949. }; // at 1,1 to 3,2 (screen)
  950. var popOver = new View
  951. {
  952. Id = "popover",
  953. X = 1,
  954. Y = 1,
  955. Width = 2,
  956. Height = 2,
  957. Arrangement = ViewArrangement.Overlapped
  958. }; // at 2,2 to 4,3 (screen)
  959. view.Add (popOver);
  960. runnable.Add (view);
  961. List<View?> found = runnable.GetViewsUnderLocation (new (mouseX, mouseY), ViewportSettingsFlags.TransparentMouse);
  962. string [] foundIds = found.Select (v => v!.Id).ToArray ();
  963. Assert.Equal (viewIdStrings, foundIds);
  964. runnable.Dispose ();
  965. }
  966. [Fact]
  967. public void Returns_TopRunnable_When_Point_Inside_Only_TopRunnable ()
  968. {
  969. IApplication? app = Application.Create ();
  970. Runnable<bool> runnable = new ()
  971. {
  972. Id = "topRunnable",
  973. Frame = new (0, 0, 20, 20)
  974. };
  975. Runnable<bool> secondaryRunnable = new ()
  976. {
  977. Id = "secondaryRunnable",
  978. Frame = new (5, 5, 10, 10)
  979. };
  980. secondaryRunnable.Margin!.Thickness = new (1);
  981. secondaryRunnable.Layout ();
  982. app.Begin (runnable);
  983. app.Begin (secondaryRunnable);
  984. List<View?> found = runnable.GetViewsUnderLocation (new (2, 2), ViewportSettingsFlags.TransparentMouse);
  985. Assert.Contains (found, v => v?.Id == runnable.Id);
  986. Assert.Contains (found, v => v == runnable);
  987. runnable.Dispose ();
  988. secondaryRunnable.Dispose ();
  989. }
  990. [Fact]
  991. public void Returns_SecondaryRunnable_When_Point_Inside_Only_SecondaryRunnable ()
  992. {
  993. IApplication? app = Application.Create ();
  994. Runnable<bool> runnable = new ()
  995. {
  996. Id = "topRunnable",
  997. Frame = new (0, 0, 20, 20)
  998. };
  999. Runnable<bool> secondaryRunnable = new ()
  1000. {
  1001. Id = "secondaryRunnable",
  1002. Frame = new (5, 5, 10, 10)
  1003. };
  1004. secondaryRunnable.Margin!.Thickness = new (1);
  1005. secondaryRunnable.Layout ();
  1006. app.Begin (runnable);
  1007. app.Begin (secondaryRunnable);
  1008. List<View?> found = runnable.GetViewsUnderLocation (new (7, 7), ViewportSettingsFlags.TransparentMouse);
  1009. Assert.Contains (found, v => v?.Id == secondaryRunnable.Id);
  1010. Assert.DoesNotContain (found, v => v?.Id == runnable.Id);
  1011. runnable.Dispose ();
  1012. secondaryRunnable.Dispose ();
  1013. }
  1014. [Fact]
  1015. public void Returns_Depends_On_Margin_ViewportSettings_When_Point_In_Margin_Of_SecondaryRunnable ()
  1016. {
  1017. IApplication? app = Application.Create ();
  1018. Runnable<bool> runnable = new ()
  1019. {
  1020. Id = "topRunnable",
  1021. Frame = new (0, 0, 20, 20)
  1022. };
  1023. Runnable<bool> secondaryRunnable = new ()
  1024. {
  1025. Id = "secondaryRunnable",
  1026. Frame = new (5, 5, 10, 10)
  1027. };
  1028. secondaryRunnable.Margin!.Thickness = new (1);
  1029. app.Begin (runnable);
  1030. app.Begin (secondaryRunnable);
  1031. secondaryRunnable.Margin!.ViewportSettings = ViewportSettingsFlags.None;
  1032. List<View?> found = runnable.GetViewsUnderLocation (new (5, 5), ViewportSettingsFlags.TransparentMouse);
  1033. Assert.Contains (found, v => v == secondaryRunnable);
  1034. Assert.Contains (found, v => v == secondaryRunnable.Margin);
  1035. Assert.DoesNotContain (found, v => v?.Id == runnable.Id);
  1036. secondaryRunnable.Margin!.ViewportSettings = ViewportSettingsFlags.TransparentMouse;
  1037. found = runnable.GetViewsUnderLocation (new (5, 5), ViewportSettingsFlags.TransparentMouse);
  1038. Assert.DoesNotContain (found, v => v == secondaryRunnable);
  1039. Assert.DoesNotContain (found, v => v == secondaryRunnable.Margin);
  1040. Assert.Contains (found, v => v?.Id == runnable.Id);
  1041. runnable.Dispose ();
  1042. secondaryRunnable.Dispose ();
  1043. }
  1044. [Fact]
  1045. public void Returns_Empty_When_Point_Outside_All_Runnables ()
  1046. {
  1047. IApplication? app = Application.Create ();
  1048. Runnable<bool> runnable = new ()
  1049. {
  1050. Id = "topRunnable",
  1051. Frame = new (0, 0, 20, 20)
  1052. };
  1053. Runnable<bool> secondaryRunnable = new ()
  1054. {
  1055. Id = "secondaryRunnable",
  1056. Frame = new (5, 5, 10, 10)
  1057. };
  1058. secondaryRunnable.Margin!.Thickness = new (1);
  1059. secondaryRunnable.Layout ();
  1060. app.Begin (runnable);
  1061. app.Begin (secondaryRunnable);
  1062. List<View?> found = runnable.GetViewsUnderLocation (new (20, 20), ViewportSettingsFlags.TransparentMouse);
  1063. Assert.Empty (found);
  1064. runnable.Dispose ();
  1065. secondaryRunnable.Dispose ();
  1066. }
  1067. }