test_split_container.h 109 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358
  1. /**************************************************************************/
  2. /* test_split_container.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #pragma once
  31. #include "scene/gui/split_container.h"
  32. #include "scene/main/window.h"
  33. #include "tests/test_macros.h"
  34. namespace TestSplitContainer {
  35. #define CHECK_RECTS(m_rects, m_child_rects) \
  36. CHECK(m_rects.size() == m_child_rects.size()); \
  37. for (int i = 0; i < (int)m_child_rects.size(); i++) { \
  38. CHECK_MESSAGE(m_child_rects[i] == m_rects[i], vformat("Child %s is the wrong size. Child rect: %s, expected: %s.", i, m_child_rects[i], m_rects[i])); \
  39. }
  40. static inline Vector<Rect2> get_rects_multi(SplitContainer *p_sc, const Vector<int> &p_positions, int p_sep, bool p_horizontal = true) {
  41. // p_positions is the top/left side of the dragger.
  42. Vector<Rect2> rects;
  43. int last_pos = 0;
  44. for (int i = 0; i < (int)p_positions.size() + 1; i++) {
  45. const int pos = i >= (int)p_positions.size() ? p_sc->get_size()[p_horizontal ? 0 : 1] : p_positions[i];
  46. Rect2 rect;
  47. if (p_horizontal) {
  48. rect.size.y = p_sc->get_size().y;
  49. rect.position.x = last_pos;
  50. rect.size.x = pos - last_pos;
  51. } else {
  52. rect.size.x = p_sc->get_size().x;
  53. rect.position.y = last_pos;
  54. rect.size.y = pos - last_pos;
  55. }
  56. rects.push_back(rect);
  57. last_pos = pos + p_sep;
  58. }
  59. return rects;
  60. }
  61. static inline Vector<Rect2> get_rects(SplitContainer *p_sc, int p_position, int p_sep, bool p_horizontal = true) {
  62. return get_rects_multi(p_sc, Vector<int>({ p_position }), p_sep, p_horizontal);
  63. }
  64. static inline Vector<Rect2> get_rects_multi_rtl(SplitContainer *p_sc, const Vector<int> &p_positions, int p_sep) {
  65. Vector<Rect2> rects;
  66. int last_pos = p_sc->get_size().x;
  67. for (int i = 0; i < (int)p_positions.size() + 1; i++) {
  68. const int pos = i >= (int)p_positions.size() ? 0 : p_sc->get_size().x - p_positions[i];
  69. Rect2 rect;
  70. rect.size.y = p_sc->get_size().y;
  71. rect.position.x = pos;
  72. rect.size.x = last_pos - pos;
  73. rects.push_back(rect);
  74. last_pos = pos - p_sep;
  75. }
  76. return rects;
  77. }
  78. static inline Vector<Rect2> get_rects_rtl(SplitContainer *p_sc, int p_position, int p_sep) {
  79. return get_rects_multi_rtl(p_sc, Vector<int>({ p_position }), p_sep);
  80. }
  81. static inline Vector<Rect2> get_child_rects(SplitContainer *p_sc) {
  82. Vector<Rect2> rects;
  83. for (int i = 0; i < p_sc->get_child_count(false); i++) {
  84. Control *c = Object::cast_to<Control>(p_sc->get_child(i, false));
  85. if (!c || !c->is_visible()) {
  86. continue;
  87. }
  88. rects.push_back(c->get_rect());
  89. }
  90. return rects;
  91. }
  92. static inline void set_size_flags(SplitContainer *p_sc, Vector<float> p_expand_ratios, bool p_horizontal = true) {
  93. for (int i = 0; i < p_sc->get_child_count(false); i++) {
  94. Control *c = Object::cast_to<Control>(p_sc->get_child(i, false));
  95. if (!c || !c->is_visible()) {
  96. continue;
  97. }
  98. float ratio = p_expand_ratios[i];
  99. if (p_horizontal) {
  100. c->set_h_size_flags(ratio > 0 ? Control::SIZE_EXPAND_FILL : Control::SIZE_FILL);
  101. } else {
  102. c->set_v_size_flags(ratio > 0 ? Control::SIZE_EXPAND_FILL : Control::SIZE_FILL);
  103. }
  104. if (ratio > 0) {
  105. c->set_stretch_ratio(ratio);
  106. }
  107. }
  108. MessageQueue::get_singleton()->flush();
  109. }
  110. TEST_CASE("[SceneTree][SplitContainer] Add and remove children") {
  111. SplitContainer *split_container = memnew(SplitContainer);
  112. split_container->set_size(Size2(500, 500));
  113. SceneTree::get_singleton()->get_root()->add_child(split_container);
  114. SUBCASE("[SplitContainer] One child") {
  115. Control *child_a = memnew(Control);
  116. split_container->add_child(child_a);
  117. MessageQueue::get_singleton()->flush();
  118. // One child will fill the entire area.
  119. CHECK(child_a->get_rect() == split_container->get_rect());
  120. split_container->set_vertical(true);
  121. CHECK(child_a->get_rect() == split_container->get_rect());
  122. memdelete(child_a);
  123. }
  124. SUBCASE("[SplitContainer] Preserve split offset") {
  125. // The split offset is preserved through adding, removing, and changing visibility of children.
  126. split_container->set_split_offset(100);
  127. CHECK(split_container->get_split_offset() == 100);
  128. Control *child_a = memnew(Control);
  129. split_container->add_child(child_a);
  130. MessageQueue::get_singleton()->flush();
  131. CHECK(split_container->get_split_offset() == 100);
  132. Control *child_b = memnew(Control);
  133. split_container->add_child(child_b);
  134. MessageQueue::get_singleton()->flush();
  135. CHECK(split_container->get_split_offset() == 100);
  136. child_a->hide();
  137. MessageQueue::get_singleton()->flush();
  138. CHECK(split_container->get_split_offset() == 100);
  139. child_b->hide();
  140. MessageQueue::get_singleton()->flush();
  141. CHECK(split_container->get_split_offset() == 100);
  142. child_b->show();
  143. MessageQueue::get_singleton()->flush();
  144. CHECK(split_container->get_split_offset() == 100);
  145. child_a->show();
  146. MessageQueue::get_singleton()->flush();
  147. CHECK(split_container->get_split_offset() == 100);
  148. split_container->remove_child(child_a);
  149. MessageQueue::get_singleton()->flush();
  150. CHECK(split_container->get_split_offset() == 100);
  151. split_container->add_child(child_a);
  152. MessageQueue::get_singleton()->flush();
  153. CHECK(split_container->get_split_offset() == 100);
  154. memdelete(child_a);
  155. memdelete(child_b);
  156. }
  157. memdelete(split_container);
  158. }
  159. TEST_CASE("[SceneTree][SplitContainer] Dragger visibility") {
  160. SplitContainer *split_container = memnew(SplitContainer);
  161. split_container->set_size(Size2(500, 500));
  162. SceneTree::get_singleton()->get_root()->add_child(split_container);
  163. Control *child_a = memnew(Control);
  164. Control *child_b = memnew(Control);
  165. split_container->add_child(child_a);
  166. split_container->add_child(child_b);
  167. SplitContainerDragger *dragger = Object::cast_to<SplitContainerDragger>(split_container->get_child(2, true));
  168. split_container->add_theme_constant_override("autohide", 0);
  169. MessageQueue::get_singleton()->flush();
  170. const int sep_constant = split_container->get_theme_constant("separation");
  171. const Size2i sep = Size2i(MAX(sep_constant, split_container->get_theme_icon("h_grabber")->get_width()), MAX(sep_constant, split_container->get_theme_icon("v_grabber")->get_height()));
  172. SUBCASE("[SplitContainer] Visibility based on child count") {
  173. split_container->remove_child(child_a);
  174. split_container->remove_child(child_b);
  175. MessageQueue::get_singleton()->flush();
  176. // No children, not visible.
  177. CHECK_FALSE(dragger->is_visible());
  178. // Add one child, not visible.
  179. split_container->add_child(child_a);
  180. MessageQueue::get_singleton()->flush();
  181. CHECK_FALSE(dragger->is_visible());
  182. // Two children, visible.
  183. split_container->add_child(child_b);
  184. MessageQueue::get_singleton()->flush();
  185. CHECK(dragger->is_visible());
  186. // Remove a child, not visible.
  187. split_container->remove_child(child_b);
  188. MessageQueue::get_singleton()->flush();
  189. CHECK_FALSE(dragger->is_visible());
  190. }
  191. SUBCASE("[SplitContainer] Set dragger visibility") {
  192. split_container->set_dragger_visibility(SplitContainer::DRAGGER_HIDDEN);
  193. MessageQueue::get_singleton()->flush();
  194. CHECK_RECTS(get_rects(split_container, 0, sep.x), get_child_rects(split_container));
  195. // Can't check the visibility since it happens in draw.
  196. split_container->set_dragger_visibility(SplitContainer::DRAGGER_HIDDEN_COLLAPSED);
  197. MessageQueue::get_singleton()->flush();
  198. CHECK_RECTS(get_rects(split_container, 0, 0), get_child_rects(split_container));
  199. split_container->set_dragger_visibility(SplitContainer::DRAGGER_VISIBLE);
  200. MessageQueue::get_singleton()->flush();
  201. CHECK_RECTS(get_rects(split_container, 0, sep.x), get_child_rects(split_container));
  202. }
  203. SUBCASE("[SplitContainer] Not visible when collapsed") {
  204. split_container->set_collapsed(true);
  205. MessageQueue::get_singleton()->flush();
  206. CHECK_FALSE(dragger->is_visible());
  207. split_container->set_collapsed(false);
  208. MessageQueue::get_singleton()->flush();
  209. CHECK(dragger->is_visible());
  210. }
  211. memdelete(child_a);
  212. memdelete(child_b);
  213. memdelete(split_container);
  214. }
  215. TEST_CASE("[SceneTree][SplitContainer] Collapsed") {
  216. DisplayServerMock *DS = (DisplayServerMock *)(DisplayServer::get_singleton());
  217. SplitContainer *split_container = memnew(SplitContainer);
  218. split_container->set_size(Size2(500, 500));
  219. SceneTree::get_singleton()->get_root()->add_child(split_container);
  220. Control *child_a = memnew(Control);
  221. split_container->add_child(child_a);
  222. Control *child_b = memnew(Control);
  223. split_container->add_child(child_b);
  224. MessageQueue::get_singleton()->flush();
  225. const int sep_constant = split_container->get_theme_constant("separation");
  226. const Size2i sep = Size2i(MAX(sep_constant, split_container->get_theme_icon("h_grabber")->get_width()), MAX(sep_constant, split_container->get_theme_icon("v_grabber")->get_height()));
  227. SUBCASE("[SplitContainer] Dragging and cursor") {
  228. split_container->set_collapsed(true);
  229. // Cursor is default.
  230. SEND_GUI_MOUSE_MOTION_EVENT(Point2(1, 1), MouseButtonMask::NONE, Key::NONE);
  231. CHECK(DS->get_cursor_shape() == DisplayServer::CURSOR_ARROW);
  232. // Dragger is disabled, cannot drag.
  233. SEND_GUI_MOUSE_BUTTON_EVENT(Point2(1, 1), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  234. MessageQueue::get_singleton()->flush();
  235. CHECK_RECTS(get_rects(split_container, 0, sep.x), get_child_rects(split_container));
  236. CHECK(split_container->get_split_offset() == 0);
  237. SEND_GUI_MOUSE_MOTION_EVENT(Point2(10, 1), MouseButtonMask::LEFT, Key::NONE);
  238. MessageQueue::get_singleton()->flush();
  239. CHECK_RECTS(get_rects(split_container, 0, sep.x), get_child_rects(split_container));
  240. CHECK(split_container->get_split_offset() == 0);
  241. }
  242. SUBCASE("[SplitContainer] No expand flags") {
  243. int def_pos = 0;
  244. split_container->set_split_offset(10);
  245. MessageQueue::get_singleton()->flush();
  246. CHECK_RECTS(get_rects(split_container, def_pos + 10, sep.x), get_child_rects(split_container));
  247. split_container->set_collapsed(true);
  248. MessageQueue::get_singleton()->flush();
  249. // The split offset is treated as 0 when collapsed.
  250. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  251. CHECK(split_container->get_split_offset() == 10);
  252. }
  253. SUBCASE("[SplitContainer] First child expanded") {
  254. int def_pos = split_container->get_size().x - sep.x;
  255. child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  256. split_container->set_split_offset(-10);
  257. MessageQueue::get_singleton()->flush();
  258. CHECK_RECTS(get_rects(split_container, def_pos - 10, sep.x), get_child_rects(split_container));
  259. split_container->set_collapsed(true);
  260. MessageQueue::get_singleton()->flush();
  261. // The split offset is treated as 0 when collapsed.
  262. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  263. CHECK(split_container->get_split_offset() == -10);
  264. }
  265. SUBCASE("[SplitContainer] Second child expanded") {
  266. int def_pos = 0;
  267. child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  268. split_container->set_split_offset(10);
  269. MessageQueue::get_singleton()->flush();
  270. CHECK_RECTS(get_rects(split_container, def_pos + 10, sep.x), get_child_rects(split_container));
  271. split_container->set_collapsed(true);
  272. MessageQueue::get_singleton()->flush();
  273. // The split offset is treated as 0 when collapsed.
  274. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  275. CHECK(split_container->get_split_offset() == 10);
  276. }
  277. SUBCASE("[SplitContainer] Both children expanded") {
  278. int def_pos = (split_container->get_size().y - sep.y) / 2;
  279. child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  280. child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  281. split_container->set_split_offset(10);
  282. MessageQueue::get_singleton()->flush();
  283. CHECK_RECTS(get_rects(split_container, def_pos + 10, sep.x), get_child_rects(split_container));
  284. split_container->set_collapsed(true);
  285. MessageQueue::get_singleton()->flush();
  286. // The split offset is treated as 0 when collapsed.
  287. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  288. CHECK(split_container->get_split_offset() == 10);
  289. }
  290. memdelete(child_a);
  291. memdelete(child_b);
  292. memdelete(split_container);
  293. }
  294. TEST_CASE("[SceneTree][SplitContainer] Cursor shape") {
  295. DisplayServerMock *DS = (DisplayServerMock *)(DisplayServer::get_singleton());
  296. SplitContainer *split_container = memnew(SplitContainer);
  297. split_container->set_size(Size2(500, 500));
  298. SceneTree::get_singleton()->get_root()->add_child(split_container);
  299. Control *child_a = memnew(Control);
  300. split_container->add_child(child_a);
  301. Control *child_b = memnew(Control);
  302. split_container->add_child(child_b);
  303. MessageQueue::get_singleton()->flush();
  304. Point2 on_dragger = Point2(1, 1);
  305. Point2 not_on_dragger = Point2(50, 50);
  306. // Default cursor shape.
  307. SEND_GUI_MOUSE_MOTION_EVENT(not_on_dragger, MouseButtonMask::NONE, Key::NONE);
  308. CHECK(DS->get_cursor_shape() == DisplayServer::CURSOR_ARROW);
  309. // Horizontal cursor shape.
  310. SEND_GUI_MOUSE_MOTION_EVENT(on_dragger, MouseButtonMask::NONE, Key::NONE);
  311. CHECK(DS->get_cursor_shape() == DisplayServer::CURSOR_HSPLIT);
  312. // Vertical cursor shape.
  313. split_container->set_vertical(true);
  314. SEND_GUI_MOUSE_MOTION_EVENT(on_dragger, MouseButtonMask::NONE, Key::NONE);
  315. CHECK(DS->get_cursor_shape() == DisplayServer::CURSOR_VSPLIT);
  316. // Move off, default cursor shape.
  317. SEND_GUI_MOUSE_MOTION_EVENT(not_on_dragger, MouseButtonMask::NONE, Key::NONE);
  318. CHECK(DS->get_cursor_shape() == DisplayServer::CURSOR_ARROW);
  319. memdelete(child_a);
  320. memdelete(child_b);
  321. memdelete(split_container);
  322. }
  323. TEST_CASE("[SceneTree][SplitContainer] Two children") {
  324. SplitContainer *split_container = memnew(SplitContainer);
  325. split_container->set_size(Size2(500, 500));
  326. SceneTree::get_singleton()->get_root()->add_child(split_container);
  327. Control *child_a = memnew(Control);
  328. Control *child_b = memnew(Control);
  329. split_container->add_child(child_a);
  330. split_container->add_child(child_b);
  331. MessageQueue::get_singleton()->flush();
  332. const int sep_constant = split_container->get_theme_constant("separation");
  333. const Size2i sep = Size2i(MAX(sep_constant, split_container->get_theme_icon("h_grabber")->get_width()), MAX(sep_constant, split_container->get_theme_icon("v_grabber")->get_height()));
  334. SUBCASE("[SplitContainer] Minimum size") {
  335. // Minimum size is the sum of both children's minimum sizes and the separator depending on the vertical axis.
  336. child_a->set_custom_minimum_size(Size2(100, 200));
  337. child_b->set_custom_minimum_size(Size2(100, 200));
  338. MessageQueue::get_singleton()->flush();
  339. Size2 min_size = split_container->get_minimum_size();
  340. CHECK(min_size.x == 200 + sep.x);
  341. CHECK(min_size.y == 200);
  342. split_container->set_vertical(true);
  343. MessageQueue::get_singleton()->flush();
  344. min_size = split_container->get_minimum_size();
  345. CHECK(min_size.x == 100);
  346. CHECK(min_size.y == 400 + sep.y);
  347. }
  348. SUBCASE("[SplitContainer] Default position") {
  349. SUBCASE("[SplitContainer] Vertical") {
  350. // Make sure clamping the split offset doesn't change it or the position.
  351. split_container->set_vertical(true);
  352. // No expand flags set.
  353. MessageQueue::get_singleton()->flush();
  354. int def_pos = 0;
  355. CHECK_RECTS(get_rects(split_container, def_pos, sep.y, false), get_child_rects(split_container));
  356. split_container->clamp_split_offset();
  357. MessageQueue::get_singleton()->flush();
  358. CHECK(split_container->get_split_offset() == 0);
  359. CHECK_RECTS(get_rects(split_container, def_pos, sep.y, false), get_child_rects(split_container));
  360. // First expand flags set.
  361. child_a->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  362. child_b->set_v_size_flags(Control::SIZE_FILL);
  363. MessageQueue::get_singleton()->flush();
  364. def_pos = split_container->get_size().y - sep.y;
  365. CHECK_RECTS(get_rects(split_container, def_pos, sep.y, false), get_child_rects(split_container));
  366. split_container->clamp_split_offset();
  367. MessageQueue::get_singleton()->flush();
  368. CHECK(split_container->get_split_offset() == 0);
  369. CHECK_RECTS(get_rects(split_container, def_pos, sep.y, false), get_child_rects(split_container));
  370. // Second expand flags set.
  371. child_a->set_v_size_flags(Control::SIZE_FILL);
  372. child_b->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  373. MessageQueue::get_singleton()->flush();
  374. def_pos = 0;
  375. CHECK_RECTS(get_rects(split_container, 0, sep.y, false), get_child_rects(split_container));
  376. split_container->clamp_split_offset();
  377. MessageQueue::get_singleton()->flush();
  378. CHECK(split_container->get_split_offset() == 0);
  379. CHECK_RECTS(get_rects(split_container, def_pos, sep.y, false), get_child_rects(split_container));
  380. // Both expand flags set.
  381. child_a->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  382. child_b->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  383. MessageQueue::get_singleton()->flush();
  384. def_pos = (split_container->get_size().y - sep.y) / 2;
  385. CHECK_RECTS(get_rects(split_container, def_pos, sep.y, false), get_child_rects(split_container));
  386. split_container->clamp_split_offset();
  387. MessageQueue::get_singleton()->flush();
  388. CHECK(split_container->get_split_offset() == 0);
  389. CHECK_RECTS(get_rects(split_container, def_pos, sep.y, false), get_child_rects(split_container));
  390. // Unequal stretch ratios.
  391. child_a->set_stretch_ratio(2.0);
  392. MessageQueue::get_singleton()->flush();
  393. def_pos = (split_container->get_size().y * 2 / 3) - sep.y / 2;
  394. CHECK_RECTS(get_rects(split_container, def_pos, sep.y, false), get_child_rects(split_container));
  395. split_container->clamp_split_offset();
  396. MessageQueue::get_singleton()->flush();
  397. CHECK(split_container->get_split_offset() == 0);
  398. CHECK_RECTS(get_rects(split_container, def_pos, sep.y, false), get_child_rects(split_container));
  399. }
  400. SUBCASE("[SplitContainer] Right to left") {
  401. split_container->set_layout_direction(Control::LAYOUT_DIRECTION_RTL);
  402. split_container->set_position(Point2(0, 0));
  403. // No expand flags set.
  404. MessageQueue::get_singleton()->flush();
  405. int def_pos = 0;
  406. CHECK_RECTS(get_rects_rtl(split_container, def_pos, sep.y), get_child_rects(split_container));
  407. split_container->clamp_split_offset();
  408. MessageQueue::get_singleton()->flush();
  409. CHECK(split_container->get_split_offset() == 0);
  410. CHECK_RECTS(get_rects_rtl(split_container, def_pos, sep.y), get_child_rects(split_container));
  411. // First expand flags set.
  412. child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  413. child_b->set_h_size_flags(Control::SIZE_FILL);
  414. MessageQueue::get_singleton()->flush();
  415. def_pos = split_container->get_size().y - sep.y;
  416. CHECK_RECTS(get_rects_rtl(split_container, def_pos, sep.y), get_child_rects(split_container));
  417. split_container->clamp_split_offset();
  418. MessageQueue::get_singleton()->flush();
  419. CHECK(split_container->get_split_offset() == 0);
  420. CHECK_RECTS(get_rects_rtl(split_container, def_pos, sep.y), get_child_rects(split_container));
  421. // Second expand flags set.
  422. child_a->set_h_size_flags(Control::SIZE_FILL);
  423. child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  424. MessageQueue::get_singleton()->flush();
  425. def_pos = 0;
  426. CHECK_RECTS(get_rects_rtl(split_container, def_pos, sep.y), get_child_rects(split_container));
  427. split_container->clamp_split_offset();
  428. MessageQueue::get_singleton()->flush();
  429. CHECK(split_container->get_split_offset() == 0);
  430. CHECK_RECTS(get_rects_rtl(split_container, def_pos, sep.y), get_child_rects(split_container));
  431. // Both expand flags set.
  432. child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  433. child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  434. MessageQueue::get_singleton()->flush();
  435. def_pos = (split_container->get_size().y - sep.y) / 2;
  436. CHECK_RECTS(get_rects_rtl(split_container, def_pos, sep.y), get_child_rects(split_container));
  437. split_container->clamp_split_offset();
  438. MessageQueue::get_singleton()->flush();
  439. CHECK(split_container->get_split_offset() == 0);
  440. CHECK_RECTS(get_rects_rtl(split_container, def_pos, sep.y), get_child_rects(split_container));
  441. // Unequal stretch ratios.
  442. child_a->set_stretch_ratio(2.0);
  443. MessageQueue::get_singleton()->flush();
  444. def_pos = (split_container->get_size().y * 2 / 3) - sep.y / 2;
  445. CHECK_RECTS(get_rects_rtl(split_container, def_pos, sep.y), get_child_rects(split_container));
  446. split_container->clamp_split_offset();
  447. MessageQueue::get_singleton()->flush();
  448. CHECK(split_container->get_split_offset() == 0);
  449. CHECK_RECTS(get_rects_rtl(split_container, def_pos, sep.y), get_child_rects(split_container));
  450. }
  451. SUBCASE("[SplitContainer] No expand flags") {
  452. int def_pos = 0;
  453. CHECK(split_container->get_split_offset() == 0);
  454. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  455. split_container->clamp_split_offset();
  456. MessageQueue::get_singleton()->flush();
  457. CHECK(split_container->get_split_offset() == 0);
  458. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  459. // Minimum sizes affect default position.
  460. // First child with minimum size.
  461. child_a->set_custom_minimum_size(Size2(400, 0));
  462. MessageQueue::get_singleton()->flush();
  463. def_pos = 400;
  464. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  465. split_container->clamp_split_offset();
  466. MessageQueue::get_singleton()->flush();
  467. CHECK(split_container->get_split_offset() == def_pos);
  468. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  469. // Second child with minimum size.
  470. child_a->set_custom_minimum_size(Size2(0, 0));
  471. child_b->set_custom_minimum_size(Size2(400, 0));
  472. MessageQueue::get_singleton()->flush();
  473. def_pos = split_container->get_size().x - 400 - sep.x;
  474. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  475. split_container->clamp_split_offset();
  476. MessageQueue::get_singleton()->flush();
  477. CHECK(split_container->get_split_offset() == def_pos);
  478. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  479. // Both children with minimum size.
  480. child_a->set_custom_minimum_size(Size2(200, 0));
  481. child_b->set_custom_minimum_size(Size2(288, 0));
  482. MessageQueue::get_singleton()->flush();
  483. def_pos = 200;
  484. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  485. split_container->clamp_split_offset();
  486. MessageQueue::get_singleton()->flush();
  487. CHECK(split_container->get_split_offset() == def_pos);
  488. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  489. }
  490. SUBCASE("[SplitContainer] First child expanded") {
  491. const int def_pos = split_container->get_size().x - sep.x;
  492. child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  493. MessageQueue::get_singleton()->flush();
  494. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  495. split_container->clamp_split_offset();
  496. MessageQueue::get_singleton()->flush();
  497. CHECK(split_container->get_split_offset() == 0);
  498. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  499. // Minimum sizes affect default position.
  500. // First child with minimum size.
  501. child_a->set_custom_minimum_size(Size2(400, 0));
  502. MessageQueue::get_singleton()->flush();
  503. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  504. split_container->clamp_split_offset();
  505. MessageQueue::get_singleton()->flush();
  506. CHECK(split_container->get_split_offset() == 0);
  507. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  508. // Second child with minimum size.
  509. child_a->set_custom_minimum_size(Size2(0, 0));
  510. child_b->set_custom_minimum_size(Size2(400, 0));
  511. MessageQueue::get_singleton()->flush();
  512. int pos = split_container->get_size().x - 400 - sep.x;
  513. CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
  514. split_container->clamp_split_offset();
  515. MessageQueue::get_singleton()->flush();
  516. CHECK(split_container->get_split_offset() == pos - def_pos);
  517. CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
  518. // Both children with minimum size.
  519. child_a->set_custom_minimum_size(Size2(200, 0));
  520. child_b->set_custom_minimum_size(Size2(288, 0));
  521. MessageQueue::get_singleton()->flush();
  522. pos = 200;
  523. CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
  524. split_container->clamp_split_offset();
  525. MessageQueue::get_singleton()->flush();
  526. CHECK(split_container->get_split_offset() == pos - def_pos);
  527. CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
  528. }
  529. SUBCASE("[SplitContainer] Second child expanded") {
  530. int def_pos = 0;
  531. child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  532. MessageQueue::get_singleton()->flush();
  533. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  534. split_container->clamp_split_offset();
  535. MessageQueue::get_singleton()->flush();
  536. CHECK(split_container->get_split_offset() == 0);
  537. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  538. // Minimum sizes affect default position.
  539. // First child with minimum size.
  540. child_a->set_custom_minimum_size(Size2(400, 0));
  541. MessageQueue::get_singleton()->flush();
  542. def_pos = 400;
  543. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  544. split_container->clamp_split_offset();
  545. MessageQueue::get_singleton()->flush();
  546. CHECK(split_container->get_split_offset() == def_pos);
  547. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  548. // Second child with minimum size.
  549. child_a->set_custom_minimum_size(Size2(0, 0));
  550. child_b->set_custom_minimum_size(Size2(400, 0));
  551. MessageQueue::get_singleton()->flush();
  552. def_pos = 500 - 400 - sep.x;
  553. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  554. split_container->clamp_split_offset();
  555. MessageQueue::get_singleton()->flush();
  556. CHECK(split_container->get_split_offset() == def_pos);
  557. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  558. // Both children with minimum size.
  559. child_a->set_custom_minimum_size(Size2(200, 0));
  560. child_b->set_custom_minimum_size(Size2(288, 0));
  561. MessageQueue::get_singleton()->flush();
  562. def_pos = 200;
  563. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  564. split_container->clamp_split_offset();
  565. MessageQueue::get_singleton()->flush();
  566. CHECK(split_container->get_split_offset() == def_pos);
  567. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  568. }
  569. SUBCASE("[SplitContainer] Both children expanded") {
  570. const int def_pos = (split_container->get_size().x - sep.x) / 2;
  571. child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  572. child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  573. MessageQueue::get_singleton()->flush();
  574. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  575. split_container->clamp_split_offset();
  576. MessageQueue::get_singleton()->flush();
  577. CHECK(split_container->get_split_offset() == 0);
  578. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  579. // Minimum sizes affect default position.
  580. // First child with minimum size.
  581. child_a->set_custom_minimum_size(Size2(400, 0));
  582. MessageQueue::get_singleton()->flush();
  583. int pos = 400;
  584. CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
  585. split_container->clamp_split_offset();
  586. MessageQueue::get_singleton()->flush();
  587. CHECK(split_container->get_split_offset() == pos - def_pos);
  588. CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
  589. // Second child with minimum size.
  590. child_a->set_custom_minimum_size(Size2(0, 0));
  591. child_b->set_custom_minimum_size(Size2(400, 0));
  592. MessageQueue::get_singleton()->flush();
  593. pos = split_container->get_size().x - 400 - sep.x;
  594. CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
  595. split_container->clamp_split_offset();
  596. MessageQueue::get_singleton()->flush();
  597. CHECK(split_container->get_split_offset() == pos - def_pos);
  598. CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
  599. // Both children with minimum size.
  600. child_a->set_custom_minimum_size(Size2(200, 0));
  601. child_b->set_custom_minimum_size(Size2(288, 0));
  602. MessageQueue::get_singleton()->flush();
  603. pos = 200;
  604. CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
  605. split_container->clamp_split_offset();
  606. MessageQueue::get_singleton()->flush();
  607. CHECK(split_container->get_split_offset() == pos - def_pos);
  608. CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
  609. }
  610. SUBCASE("[SplitContainer] Unequal stretch ratios") {
  611. const int def_pos = (split_container->get_size().x * 2 / 3) - sep.x / 2;
  612. child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  613. child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  614. child_a->set_stretch_ratio(2.0);
  615. MessageQueue::get_singleton()->flush();
  616. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  617. split_container->clamp_split_offset();
  618. MessageQueue::get_singleton()->flush();
  619. CHECK(split_container->get_split_offset() == 0);
  620. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  621. // Minimum sizes affect default position.
  622. // First child with minimum size.
  623. child_a->set_custom_minimum_size(Size2(400, 0));
  624. MessageQueue::get_singleton()->flush();
  625. int pos = 400;
  626. CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
  627. split_container->clamp_split_offset();
  628. MessageQueue::get_singleton()->flush();
  629. CHECK(split_container->get_split_offset() == pos - def_pos);
  630. CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
  631. // Second child with minimum size.
  632. child_a->set_custom_minimum_size(Size2(0, 0));
  633. child_b->set_custom_minimum_size(Size2(400, 0));
  634. MessageQueue::get_singleton()->flush();
  635. pos = split_container->get_size().x - 400 - sep.x;
  636. CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
  637. split_container->clamp_split_offset();
  638. MessageQueue::get_singleton()->flush();
  639. CHECK(split_container->get_split_offset() == pos - def_pos);
  640. CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
  641. // Both children with minimum size.
  642. child_a->set_custom_minimum_size(Size2(200, 0));
  643. child_b->set_custom_minimum_size(Size2(288, 0));
  644. MessageQueue::get_singleton()->flush();
  645. pos = 200;
  646. CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
  647. split_container->clamp_split_offset();
  648. MessageQueue::get_singleton()->flush();
  649. CHECK(split_container->get_split_offset() == pos - def_pos);
  650. CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
  651. }
  652. }
  653. SUBCASE("[SplitContainer] Set split offset") {
  654. SUBCASE("[SplitContainer] Right to left") {
  655. split_container->set_layout_direction(Control::LAYOUT_DIRECTION_RTL);
  656. split_container->set_position(Point2(0, 0));
  657. int def_pos = 0;
  658. // Positive.
  659. split_container->set_split_offset(10);
  660. MessageQueue::get_singleton()->flush();
  661. CHECK(split_container->get_split_offset() == 10);
  662. CHECK_RECTS(get_rects_rtl(split_container, def_pos + 10, sep.y), get_child_rects(split_container));
  663. // Negative.
  664. split_container->set_split_offset(-10);
  665. MessageQueue::get_singleton()->flush();
  666. CHECK(split_container->get_split_offset() == -10);
  667. CHECK_RECTS(get_rects_rtl(split_container, def_pos, sep.y), get_child_rects(split_container));
  668. }
  669. SUBCASE("[SplitContainer] No expand flags") {
  670. int def_pos = 0;
  671. // Positive.
  672. split_container->set_split_offset(10);
  673. MessageQueue::get_singleton()->flush();
  674. CHECK(split_container->get_split_offset() == 10);
  675. CHECK_RECTS(get_rects(split_container, def_pos + 10, sep.x), get_child_rects(split_container));
  676. // Negative.
  677. split_container->set_split_offset(-10);
  678. MessageQueue::get_singleton()->flush();
  679. CHECK(split_container->get_split_offset() == -10);
  680. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  681. // Clamped.
  682. split_container->set_split_offset(1000);
  683. MessageQueue::get_singleton()->flush();
  684. CHECK(split_container->get_split_offset() == 1000);
  685. CHECK_RECTS(get_rects(split_container, split_container->get_size().x - sep.x, sep.x), get_child_rects(split_container));
  686. }
  687. SUBCASE("[SplitContainer] First child expanded") {
  688. int def_pos = split_container->get_size().x - sep.x;
  689. child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  690. MessageQueue::get_singleton()->flush();
  691. // Positive.
  692. split_container->set_split_offset(10);
  693. MessageQueue::get_singleton()->flush();
  694. CHECK(split_container->get_split_offset() == 10);
  695. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  696. // Negative.
  697. split_container->set_split_offset(-10);
  698. MessageQueue::get_singleton()->flush();
  699. CHECK(split_container->get_split_offset() == -10);
  700. CHECK_RECTS(get_rects(split_container, def_pos - 10, sep.x), get_child_rects(split_container));
  701. // Clamped.
  702. split_container->set_split_offset(-1000);
  703. MessageQueue::get_singleton()->flush();
  704. CHECK(split_container->get_split_offset() == -1000);
  705. CHECK_RECTS(get_rects(split_container, 0, sep.x), get_child_rects(split_container));
  706. }
  707. SUBCASE("[SplitContainer] Second child expanded") {
  708. int def_pos = 0;
  709. child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  710. MessageQueue::get_singleton()->flush();
  711. // Positive.
  712. split_container->set_split_offset(10);
  713. MessageQueue::get_singleton()->flush();
  714. CHECK(split_container->get_split_offset() == 10);
  715. CHECK_RECTS(get_rects(split_container, def_pos + 10, sep.x), get_child_rects(split_container));
  716. // Negative.
  717. split_container->set_split_offset(-10);
  718. MessageQueue::get_singleton()->flush();
  719. CHECK(split_container->get_split_offset() == -10);
  720. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  721. // Clamped.
  722. split_container->set_split_offset(1000);
  723. MessageQueue::get_singleton()->flush();
  724. CHECK(split_container->get_split_offset() == 1000);
  725. CHECK_RECTS(get_rects(split_container, split_container->get_size().x - sep.x, sep.x), get_child_rects(split_container));
  726. }
  727. SUBCASE("[SplitContainer] Both children expanded") {
  728. int def_pos = (split_container->get_size().x - sep.x) / 2;
  729. child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  730. child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  731. MessageQueue::get_singleton()->flush();
  732. // Positive.
  733. split_container->set_split_offset(10);
  734. MessageQueue::get_singleton()->flush();
  735. CHECK(split_container->get_split_offset() == 10);
  736. CHECK_RECTS(get_rects(split_container, def_pos + 10, sep.x), get_child_rects(split_container));
  737. // Negative.
  738. split_container->set_split_offset(-10);
  739. MessageQueue::get_singleton()->flush();
  740. CHECK(split_container->get_split_offset() == -10);
  741. CHECK_RECTS(get_rects(split_container, def_pos - 10, sep.x), get_child_rects(split_container));
  742. // Clamped positive.
  743. split_container->set_split_offset(1000);
  744. MessageQueue::get_singleton()->flush();
  745. CHECK(split_container->get_split_offset() == 1000);
  746. CHECK_RECTS(get_rects(split_container, split_container->get_size().x - sep.x, sep.x), get_child_rects(split_container));
  747. // Clamped negative.
  748. split_container->set_split_offset(-1000);
  749. MessageQueue::get_singleton()->flush();
  750. CHECK(split_container->get_split_offset() == -1000);
  751. CHECK_RECTS(get_rects(split_container, 0, sep.x), get_child_rects(split_container));
  752. }
  753. SUBCASE("[SplitContainer] Unequal stretch ratios") {
  754. int def_pos = (split_container->get_size().x * 2 / 3) - sep.x / 2;
  755. child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  756. child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  757. child_a->set_stretch_ratio(2.0);
  758. MessageQueue::get_singleton()->flush();
  759. // Positive.
  760. split_container->set_split_offset(10);
  761. MessageQueue::get_singleton()->flush();
  762. CHECK(split_container->get_split_offset() == 10);
  763. CHECK_RECTS(get_rects(split_container, def_pos + 10, sep.x), get_child_rects(split_container));
  764. // Negative.
  765. split_container->set_split_offset(-10);
  766. MessageQueue::get_singleton()->flush();
  767. CHECK(split_container->get_split_offset() == -10);
  768. CHECK_RECTS(get_rects(split_container, def_pos - 10, sep.x), get_child_rects(split_container));
  769. // Clamped positive.
  770. split_container->set_split_offset(1000);
  771. MessageQueue::get_singleton()->flush();
  772. CHECK(split_container->get_split_offset() == 1000);
  773. CHECK_RECTS(get_rects(split_container, split_container->get_size().x - sep.x, sep.x), get_child_rects(split_container));
  774. // Clamped negative.
  775. split_container->set_split_offset(-1000);
  776. MessageQueue::get_singleton()->flush();
  777. CHECK(split_container->get_split_offset() == -1000);
  778. CHECK_RECTS(get_rects(split_container, 0, sep.x), get_child_rects(split_container));
  779. }
  780. }
  781. SUBCASE("[SplitContainer] Keep split offset when changing minimum size") {
  782. SUBCASE("[SplitContainer] No expand flags") {
  783. int def_pos = 0;
  784. split_container->set_split_offset(100);
  785. child_a->set_custom_minimum_size(Size2(10, 0));
  786. MessageQueue::get_singleton()->flush();
  787. CHECK(split_container->get_split_offset() == 100);
  788. CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
  789. child_a->set_custom_minimum_size(Size2(50, 0));
  790. MessageQueue::get_singleton()->flush();
  791. CHECK(split_container->get_split_offset() == 100);
  792. CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
  793. }
  794. SUBCASE("[SplitContainer] First child expanded") {
  795. int def_pos = split_container->get_size().x - sep.x;
  796. child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  797. MessageQueue::get_singleton()->flush();
  798. split_container->set_split_offset(-100);
  799. child_b->set_custom_minimum_size(Size2(10, 0));
  800. MessageQueue::get_singleton()->flush();
  801. CHECK(split_container->get_split_offset() == -100);
  802. CHECK_RECTS(get_rects(split_container, def_pos - 100, sep.x), get_child_rects(split_container));
  803. child_b->set_custom_minimum_size(Size2(50, 0));
  804. MessageQueue::get_singleton()->flush();
  805. CHECK(split_container->get_split_offset() == -100);
  806. CHECK_RECTS(get_rects(split_container, def_pos - 100, sep.x), get_child_rects(split_container));
  807. }
  808. SUBCASE("[SplitContainer] Second child expanded") {
  809. int def_pos = 0;
  810. child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  811. MessageQueue::get_singleton()->flush();
  812. split_container->set_split_offset(100);
  813. child_a->set_custom_minimum_size(Size2(10, 0));
  814. MessageQueue::get_singleton()->flush();
  815. CHECK(split_container->get_split_offset() == 100);
  816. CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
  817. child_a->set_custom_minimum_size(Size2(50, 0));
  818. MessageQueue::get_singleton()->flush();
  819. CHECK(split_container->get_split_offset() == 100);
  820. CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
  821. }
  822. SUBCASE("[SplitContainer] Both children expanded") {
  823. int def_pos = (split_container->get_size().x - sep.x) / 2;
  824. child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  825. child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  826. MessageQueue::get_singleton()->flush();
  827. split_container->set_split_offset(20);
  828. child_a->set_custom_minimum_size(Size2(10, 0));
  829. child_b->set_custom_minimum_size(Size2(10, 0));
  830. MessageQueue::get_singleton()->flush();
  831. CHECK(split_container->get_split_offset() == 20);
  832. CHECK_RECTS(get_rects(split_container, def_pos + 20, sep.x), get_child_rects(split_container));
  833. child_a->set_custom_minimum_size(Size2(50, 0));
  834. child_b->set_custom_minimum_size(Size2(50, 0));
  835. MessageQueue::get_singleton()->flush();
  836. CHECK(split_container->get_split_offset() == 20);
  837. CHECK_RECTS(get_rects(split_container, def_pos + 20, sep.x), get_child_rects(split_container));
  838. }
  839. }
  840. SUBCASE("[SplitContainer] Keep split offset when changing visibility") {
  841. SUBCASE("[SplitContainer] No expand flags") {
  842. int def_pos = 0;
  843. split_container->set_split_offset(100);
  844. child_a->hide();
  845. MessageQueue::get_singleton()->flush();
  846. CHECK(split_container->get_split_offset() == 100);
  847. CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
  848. child_b->hide();
  849. MessageQueue::get_singleton()->flush();
  850. CHECK(split_container->get_split_offset() == 100);
  851. child_a->show();
  852. MessageQueue::get_singleton()->flush();
  853. CHECK(split_container->get_split_offset() == 100);
  854. CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
  855. child_b->show();
  856. MessageQueue::get_singleton()->flush();
  857. CHECK(split_container->get_split_offset() == 100);
  858. CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
  859. }
  860. SUBCASE("[SplitContainer] First child expanded") {
  861. int def_pos = split_container->get_size().x - sep.x;
  862. child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  863. MessageQueue::get_singleton()->flush();
  864. split_container->set_split_offset(-100);
  865. child_a->hide();
  866. MessageQueue::get_singleton()->flush();
  867. CHECK(split_container->get_split_offset() == -100);
  868. CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
  869. child_b->hide();
  870. MessageQueue::get_singleton()->flush();
  871. CHECK(split_container->get_split_offset() == -100);
  872. child_a->show();
  873. MessageQueue::get_singleton()->flush();
  874. CHECK(split_container->get_split_offset() == -100);
  875. CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
  876. child_b->show();
  877. MessageQueue::get_singleton()->flush();
  878. CHECK(split_container->get_split_offset() == -100);
  879. CHECK_RECTS(get_rects(split_container, def_pos - 100, sep.x), get_child_rects(split_container));
  880. }
  881. SUBCASE("[SplitContainer] Second child expanded") {
  882. int def_pos = 0;
  883. child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  884. MessageQueue::get_singleton()->flush();
  885. split_container->set_split_offset(100);
  886. child_a->hide();
  887. MessageQueue::get_singleton()->flush();
  888. CHECK(split_container->get_split_offset() == 100);
  889. CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
  890. child_b->hide();
  891. MessageQueue::get_singleton()->flush();
  892. CHECK(split_container->get_split_offset() == 100);
  893. child_a->show();
  894. MessageQueue::get_singleton()->flush();
  895. CHECK(split_container->get_split_offset() == 100);
  896. CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
  897. child_b->show();
  898. MessageQueue::get_singleton()->flush();
  899. CHECK(split_container->get_split_offset() == 100);
  900. CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
  901. }
  902. SUBCASE("[SplitContainer] Both children expanded") {
  903. int def_pos = (split_container->get_size().x - sep.x) / 2;
  904. child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  905. child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  906. MessageQueue::get_singleton()->flush();
  907. split_container->set_split_offset(20);
  908. child_a->hide();
  909. MessageQueue::get_singleton()->flush();
  910. CHECK(split_container->get_split_offset() == 20);
  911. CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
  912. child_b->hide();
  913. MessageQueue::get_singleton()->flush();
  914. CHECK(split_container->get_split_offset() == 20);
  915. child_a->show();
  916. MessageQueue::get_singleton()->flush();
  917. CHECK(split_container->get_split_offset() == 20);
  918. CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
  919. child_b->show();
  920. MessageQueue::get_singleton()->flush();
  921. CHECK(split_container->get_split_offset() == 20);
  922. CHECK_RECTS(get_rects(split_container, def_pos + 20, sep.x), get_child_rects(split_container));
  923. }
  924. }
  925. SUBCASE("[SplitContainer] Keep split offset when removing children") {
  926. SUBCASE("[SplitContainer] No expand flags") {
  927. int def_pos = 0;
  928. split_container->set_split_offset(100);
  929. split_container->remove_child(child_a);
  930. MessageQueue::get_singleton()->flush();
  931. CHECK(split_container->get_split_offset() == 100);
  932. CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
  933. split_container->remove_child(child_b);
  934. MessageQueue::get_singleton()->flush();
  935. CHECK(split_container->get_split_offset() == 100);
  936. split_container->add_child(child_a);
  937. MessageQueue::get_singleton()->flush();
  938. CHECK(split_container->get_split_offset() == 100);
  939. CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
  940. split_container->add_child(child_b);
  941. MessageQueue::get_singleton()->flush();
  942. CHECK(split_container->get_split_offset() == 100);
  943. CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
  944. }
  945. SUBCASE("[SplitContainer] First child expanded") {
  946. int def_pos = split_container->get_size().x - sep.x;
  947. child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  948. MessageQueue::get_singleton()->flush();
  949. split_container->set_split_offset(-100);
  950. split_container->remove_child(child_a);
  951. MessageQueue::get_singleton()->flush();
  952. CHECK(split_container->get_split_offset() == -100);
  953. CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
  954. split_container->remove_child(child_b);
  955. MessageQueue::get_singleton()->flush();
  956. CHECK(split_container->get_split_offset() == -100);
  957. split_container->add_child(child_a);
  958. MessageQueue::get_singleton()->flush();
  959. CHECK(split_container->get_split_offset() == -100);
  960. CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
  961. split_container->add_child(child_b);
  962. MessageQueue::get_singleton()->flush();
  963. CHECK(split_container->get_split_offset() == -100);
  964. CHECK_RECTS(get_rects(split_container, def_pos - 100, sep.x), get_child_rects(split_container));
  965. }
  966. SUBCASE("[SplitContainer] Second child expanded") {
  967. int def_pos = 0;
  968. child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  969. MessageQueue::get_singleton()->flush();
  970. split_container->set_split_offset(100);
  971. split_container->remove_child(child_a);
  972. MessageQueue::get_singleton()->flush();
  973. CHECK(split_container->get_split_offset() == 100);
  974. CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
  975. split_container->remove_child(child_b);
  976. MessageQueue::get_singleton()->flush();
  977. CHECK(split_container->get_split_offset() == 100);
  978. split_container->add_child(child_a);
  979. MessageQueue::get_singleton()->flush();
  980. CHECK(split_container->get_split_offset() == 100);
  981. CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
  982. split_container->add_child(child_b);
  983. MessageQueue::get_singleton()->flush();
  984. CHECK(split_container->get_split_offset() == 100);
  985. CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
  986. }
  987. SUBCASE("[SplitContainer] Both children expanded") {
  988. int def_pos = (split_container->get_size().x - sep.x) / 2;
  989. child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  990. child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  991. MessageQueue::get_singleton()->flush();
  992. split_container->set_split_offset(20);
  993. split_container->remove_child(child_a);
  994. MessageQueue::get_singleton()->flush();
  995. CHECK(split_container->get_split_offset() == 20);
  996. CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
  997. split_container->remove_child(child_b);
  998. MessageQueue::get_singleton()->flush();
  999. CHECK(split_container->get_split_offset() == 20);
  1000. split_container->add_child(child_a);
  1001. MessageQueue::get_singleton()->flush();
  1002. CHECK(split_container->get_split_offset() == 20);
  1003. CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
  1004. split_container->add_child(child_b);
  1005. MessageQueue::get_singleton()->flush();
  1006. CHECK(split_container->get_split_offset() == 20);
  1007. CHECK_RECTS(get_rects(split_container, def_pos + 20, sep.x), get_child_rects(split_container));
  1008. }
  1009. }
  1010. SUBCASE("[SplitContainer] Keep split offset when changing expand flags") {
  1011. int def_pos = 0;
  1012. split_container->set_split_offset(20);
  1013. MessageQueue::get_singleton()->flush();
  1014. CHECK(split_container->get_split_offset() == 20);
  1015. CHECK_RECTS(get_rects(split_container, def_pos + 20, sep.x), get_child_rects(split_container));
  1016. child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1017. def_pos = split_container->get_size().x - sep.x;
  1018. MessageQueue::get_singleton()->flush();
  1019. CHECK(split_container->get_split_offset() == 20);
  1020. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  1021. child_a->set_h_size_flags(Control::SIZE_FILL);
  1022. child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1023. def_pos = 0;
  1024. MessageQueue::get_singleton()->flush();
  1025. CHECK(split_container->get_split_offset() == 20);
  1026. CHECK_RECTS(get_rects(split_container, def_pos + 20, sep.x), get_child_rects(split_container));
  1027. child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1028. child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1029. def_pos = (split_container->get_size().x - sep.x) / 2;
  1030. MessageQueue::get_singleton()->flush();
  1031. CHECK(split_container->get_split_offset() == 20);
  1032. CHECK_RECTS(get_rects(split_container, def_pos + 20, sep.x), get_child_rects(split_container));
  1033. child_a->set_h_size_flags(Control::SIZE_FILL);
  1034. child_b->set_h_size_flags(Control::SIZE_FILL);
  1035. def_pos = 0;
  1036. MessageQueue::get_singleton()->flush();
  1037. CHECK(split_container->get_split_offset() == 20);
  1038. CHECK_RECTS(get_rects(split_container, def_pos + 20, sep.x), get_child_rects(split_container));
  1039. }
  1040. SUBCASE("[SplitContainer] Keep split offset when moving children") {
  1041. int def_pos = 0;
  1042. split_container->set_split_offset(100);
  1043. split_container->move_child(child_a, 1);
  1044. MessageQueue::get_singleton()->flush();
  1045. CHECK(split_container->get_split_offset() == 100);
  1046. CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
  1047. }
  1048. SUBCASE("[SplitContainer] Resize split container") {
  1049. SUBCASE("[SplitContainer] No expand flags") {
  1050. int def_pos = 0;
  1051. // Increase the size.
  1052. split_container->set_size(Size2(600, 500));
  1053. MessageQueue::get_singleton()->flush();
  1054. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  1055. // Decrease the size.
  1056. split_container->set_size(Size2(400, 500));
  1057. MessageQueue::get_singleton()->flush();
  1058. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  1059. // Change size with a split offset.
  1060. split_container->set_split_offset(100);
  1061. MessageQueue::get_singleton()->flush();
  1062. CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
  1063. split_container->set_size(Size2(500, 500));
  1064. MessageQueue::get_singleton()->flush();
  1065. CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
  1066. CHECK(split_container->get_split_offset() == 100);
  1067. // Change size so that the first child changes size.
  1068. split_container->set_size(Size2(80, 500));
  1069. MessageQueue::get_singleton()->flush();
  1070. CHECK_RECTS(get_rects(split_container, 80 - sep.x, sep.x), get_child_rects(split_container));
  1071. CHECK(split_container->get_split_offset() == 100);
  1072. // Increase size again.
  1073. split_container->set_size(Size2(500, 500));
  1074. MessageQueue::get_singleton()->flush();
  1075. CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
  1076. CHECK(split_container->get_split_offset() == 100);
  1077. }
  1078. SUBCASE("[SplitContainer] First child expanded") {
  1079. int def_pos = split_container->get_size().x - sep.x;
  1080. child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1081. MessageQueue::get_singleton()->flush();
  1082. // Increase the size.
  1083. split_container->set_size(Size2(600, 500));
  1084. def_pos = split_container->get_size().x - sep.x;
  1085. MessageQueue::get_singleton()->flush();
  1086. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  1087. // Decrease the size.
  1088. split_container->set_size(Size2(400, 500));
  1089. def_pos = split_container->get_size().x - sep.x;
  1090. MessageQueue::get_singleton()->flush();
  1091. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  1092. // Change size with a split offset.
  1093. split_container->set_split_offset(-100);
  1094. MessageQueue::get_singleton()->flush();
  1095. CHECK_RECTS(get_rects(split_container, def_pos - 100, sep.x), get_child_rects(split_container));
  1096. split_container->set_size(Size2(500, 500));
  1097. def_pos = split_container->get_size().x - sep.x;
  1098. MessageQueue::get_singleton()->flush();
  1099. CHECK_RECTS(get_rects(split_container, def_pos - 100, sep.x), get_child_rects(split_container));
  1100. CHECK(split_container->get_split_offset() == -100);
  1101. // Change size so that the second child changes size.
  1102. split_container->set_size(Size2(80, 500));
  1103. MessageQueue::get_singleton()->flush();
  1104. CHECK_RECTS(get_rects(split_container, 0, sep.x), get_child_rects(split_container));
  1105. CHECK(split_container->get_split_offset() == -100);
  1106. // Increase size again.
  1107. split_container->set_size(Size2(500, 500));
  1108. MessageQueue::get_singleton()->flush();
  1109. CHECK_RECTS(get_rects(split_container, def_pos - 100, sep.x), get_child_rects(split_container));
  1110. CHECK(split_container->get_split_offset() == -100);
  1111. }
  1112. SUBCASE("[SplitContainer] Second child expanded") {
  1113. int def_pos = 0;
  1114. child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1115. MessageQueue::get_singleton()->flush();
  1116. // Increase the size.
  1117. split_container->set_size(Size2(600, 500));
  1118. MessageQueue::get_singleton()->flush();
  1119. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  1120. // Decrease the size.
  1121. split_container->set_size(Size2(400, 500));
  1122. MessageQueue::get_singleton()->flush();
  1123. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  1124. // Change size with a split offset.
  1125. split_container->set_split_offset(100);
  1126. MessageQueue::get_singleton()->flush();
  1127. CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
  1128. split_container->set_size(Size2(500, 500));
  1129. MessageQueue::get_singleton()->flush();
  1130. CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
  1131. CHECK(split_container->get_split_offset() == 100);
  1132. // Change size so that the first child changes size.
  1133. split_container->set_size(Size2(80, 500));
  1134. MessageQueue::get_singleton()->flush();
  1135. CHECK_RECTS(get_rects(split_container, 80 - sep.x, sep.x), get_child_rects(split_container));
  1136. CHECK(split_container->get_split_offset() == 100);
  1137. // Increase size again.
  1138. split_container->set_size(Size2(500, 500));
  1139. MessageQueue::get_singleton()->flush();
  1140. CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
  1141. CHECK(split_container->get_split_offset() == 100);
  1142. }
  1143. SUBCASE("[SplitContainer] Both children expanded") {
  1144. int def_pos = (split_container->get_size().x - sep.x) / 2;
  1145. child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1146. child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1147. MessageQueue::get_singleton()->flush();
  1148. // Increase the size.
  1149. split_container->set_size(Size2(600, 500));
  1150. def_pos = (split_container->get_size().x - sep.x) / 2;
  1151. MessageQueue::get_singleton()->flush();
  1152. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  1153. // Decrease the size.
  1154. split_container->set_size(Size2(400, 500));
  1155. def_pos = (split_container->get_size().x - sep.x) / 2;
  1156. MessageQueue::get_singleton()->flush();
  1157. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  1158. // Change size with a split offset.
  1159. split_container->set_split_offset(100);
  1160. MessageQueue::get_singleton()->flush();
  1161. CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
  1162. split_container->set_size(Size2(500, 500));
  1163. def_pos = (split_container->get_size().x - sep.x) / 2;
  1164. MessageQueue::get_singleton()->flush();
  1165. CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
  1166. CHECK(split_container->get_split_offset() == 100);
  1167. // Change size so that the second child is minimized.
  1168. split_container->set_size(Size2(80, 500));
  1169. MessageQueue::get_singleton()->flush();
  1170. CHECK_RECTS(get_rects(split_container, 80 - sep.x, sep.x), get_child_rects(split_container));
  1171. CHECK(split_container->get_split_offset() == 100);
  1172. // Increase size again.
  1173. split_container->set_size(Size2(500, 500));
  1174. def_pos = (split_container->get_size().x - sep.x) / 2;
  1175. MessageQueue::get_singleton()->flush();
  1176. CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
  1177. CHECK(split_container->get_split_offset() == 100);
  1178. }
  1179. SUBCASE("[SplitContainer] Unequal stretch ratios") {
  1180. int def_pos = (split_container->get_size().x * 2 / 3) - sep.x / 2;
  1181. child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1182. child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1183. child_a->set_stretch_ratio(2.0);
  1184. MessageQueue::get_singleton()->flush();
  1185. // Increase the size.
  1186. split_container->set_size(Size2(600, 500));
  1187. def_pos = (split_container->get_size().x * 2 / 3) - sep.x / 2;
  1188. MessageQueue::get_singleton()->flush();
  1189. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  1190. // Decrease the size.
  1191. split_container->set_size(Size2(400, 500));
  1192. def_pos = (split_container->get_size().x * 2 / 3) - sep.x / 2;
  1193. MessageQueue::get_singleton()->flush();
  1194. CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
  1195. // Change size with a split offset.
  1196. split_container->set_split_offset(100);
  1197. MessageQueue::get_singleton()->flush();
  1198. CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
  1199. split_container->set_size(Size2(500, 500));
  1200. def_pos = (split_container->get_size().x * 2 / 3) - sep.x / 2;
  1201. MessageQueue::get_singleton()->flush();
  1202. CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
  1203. CHECK(split_container->get_split_offset() == 100);
  1204. // Change size so that the second child is minimized.
  1205. split_container->set_size(Size2(80, 500));
  1206. MessageQueue::get_singleton()->flush();
  1207. CHECK_RECTS(get_rects(split_container, 80 - sep.x, sep.x), get_child_rects(split_container));
  1208. CHECK(split_container->get_split_offset() == 100);
  1209. // Increase size again.
  1210. split_container->set_size(Size2(500, 500));
  1211. def_pos = (split_container->get_size().x * 2 / 3) - sep.x / 2;
  1212. MessageQueue::get_singleton()->flush();
  1213. CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
  1214. CHECK(split_container->get_split_offset() == 100);
  1215. }
  1216. }
  1217. SUBCASE("[SplitContainer] Drag") {
  1218. SUBCASE("[SplitContainer] Vertical, no expand flags") {
  1219. SIGNAL_WATCH(split_container, "dragged");
  1220. Array signal_args = { { 0 } };
  1221. split_container->set_vertical(true);
  1222. Point2 mouse_offset = Point2(1, 1);
  1223. int dragger_pos = 0;
  1224. int split_dragger_ofs = 0;
  1225. // Grab the dragger.
  1226. SEND_GUI_MOUSE_BUTTON_EVENT(mouse_offset + Point2(0, dragger_pos), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  1227. MessageQueue::get_singleton()->flush();
  1228. CHECK_RECTS(get_rects(split_container, dragger_pos, sep.y, false), get_child_rects(split_container));
  1229. CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
  1230. SIGNAL_CHECK_FALSE("dragged");
  1231. // Move the dragger.
  1232. dragger_pos = 10;
  1233. SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(0, dragger_pos), MouseButtonMask::LEFT, Key::NONE);
  1234. MessageQueue::get_singleton()->flush();
  1235. CHECK_RECTS(get_rects(split_container, dragger_pos, sep.y, false), get_child_rects(split_container));
  1236. CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
  1237. // It is clamped.
  1238. split_container->clamp_split_offset();
  1239. CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
  1240. ((Array)signal_args[0])[0] = split_container->get_split_offset();
  1241. SIGNAL_CHECK("dragged", signal_args);
  1242. // Move down.
  1243. dragger_pos = 400;
  1244. SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(0, dragger_pos), MouseButtonMask::LEFT, Key::NONE);
  1245. MessageQueue::get_singleton()->flush();
  1246. CHECK_RECTS(get_rects(split_container, dragger_pos, sep.y, false), get_child_rects(split_container));
  1247. CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
  1248. ((Array)signal_args[0])[0] = split_container->get_split_offset();
  1249. SIGNAL_CHECK("dragged", signal_args);
  1250. // Moves even when mouse is outside.
  1251. dragger_pos = split_container->get_size().y - sep.y;
  1252. SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(0, 1000), MouseButtonMask::LEFT, Key::NONE);
  1253. MessageQueue::get_singleton()->flush();
  1254. CHECK_RECTS(get_rects(split_container, dragger_pos, sep.y, false), get_child_rects(split_container));
  1255. CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
  1256. ((Array)signal_args[0])[0] = split_container->get_split_offset();
  1257. SIGNAL_CHECK("dragged", signal_args);
  1258. // Move up.
  1259. dragger_pos = 100;
  1260. SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(0, dragger_pos), MouseButtonMask::LEFT, Key::NONE);
  1261. MessageQueue::get_singleton()->flush();
  1262. CHECK_RECTS(get_rects(split_container, dragger_pos, sep.y, false), get_child_rects(split_container));
  1263. CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
  1264. ((Array)signal_args[0])[0] = split_container->get_split_offset();
  1265. SIGNAL_CHECK("dragged", signal_args);
  1266. // Release.
  1267. SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(mouse_offset + Point2(0, dragger_pos), MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
  1268. MessageQueue::get_singleton()->flush();
  1269. CHECK_RECTS(get_rects(split_container, dragger_pos, sep.y, false), get_child_rects(split_container));
  1270. CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
  1271. SIGNAL_CHECK_FALSE("dragged");
  1272. // No longer moves with the mouse.
  1273. SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(0, 200), MouseButtonMask::NONE, Key::NONE);
  1274. MessageQueue::get_singleton()->flush();
  1275. CHECK_RECTS(get_rects(split_container, dragger_pos, sep.y, false), get_child_rects(split_container));
  1276. CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
  1277. SIGNAL_CHECK_FALSE("dragged");
  1278. SIGNAL_UNWATCH(split_container, "dragged");
  1279. }
  1280. SUBCASE("[SplitContainer] No expand flags") {
  1281. Point2 mouse_offset = Point2(1, 1);
  1282. int dragger_pos = 0;
  1283. int split_dragger_ofs = 0;
  1284. // Grab the dragger.
  1285. SEND_GUI_MOUSE_BUTTON_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  1286. MessageQueue::get_singleton()->flush();
  1287. CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
  1288. CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
  1289. // Move the dragger.
  1290. dragger_pos = 10;
  1291. SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
  1292. MessageQueue::get_singleton()->flush();
  1293. CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
  1294. CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
  1295. // It is clamped.
  1296. split_container->clamp_split_offset();
  1297. CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
  1298. // Continue moving.
  1299. dragger_pos = 400;
  1300. SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
  1301. MessageQueue::get_singleton()->flush();
  1302. CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
  1303. CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
  1304. // Moves even when mouse is outside.
  1305. dragger_pos = split_container->get_size().x - sep.x;
  1306. SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(1000, 0), MouseButtonMask::LEFT, Key::NONE);
  1307. MessageQueue::get_singleton()->flush();
  1308. CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
  1309. CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
  1310. // Move back in.
  1311. dragger_pos = 100;
  1312. SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
  1313. MessageQueue::get_singleton()->flush();
  1314. CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
  1315. CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
  1316. // Release.
  1317. SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
  1318. MessageQueue::get_singleton()->flush();
  1319. CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
  1320. CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
  1321. // No longer moves with the mouse.
  1322. SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(200, 0), MouseButtonMask::NONE, Key::NONE);
  1323. MessageQueue::get_singleton()->flush();
  1324. CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
  1325. CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
  1326. }
  1327. SUBCASE("[SplitContainer] First child expanded") {
  1328. child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1329. MessageQueue::get_singleton()->flush();
  1330. Point2 mouse_offset = Point2(1, 1);
  1331. int dragger_pos = split_container->get_size().x - sep.x;
  1332. int split_dragger_ofs = -dragger_pos;
  1333. // Grab the dragger.
  1334. SEND_GUI_MOUSE_BUTTON_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  1335. MessageQueue::get_singleton()->flush();
  1336. CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
  1337. CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
  1338. // Move the dragger.
  1339. dragger_pos -= 10;
  1340. SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
  1341. MessageQueue::get_singleton()->flush();
  1342. CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
  1343. CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
  1344. // It is clamped.
  1345. split_container->clamp_split_offset();
  1346. CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
  1347. // Continue moving.
  1348. dragger_pos = 400;
  1349. SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
  1350. MessageQueue::get_singleton()->flush();
  1351. CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
  1352. CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
  1353. // Moves even when mouse is outside.
  1354. dragger_pos = split_container->get_size().x - sep.x;
  1355. SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(1000, 0), MouseButtonMask::LEFT, Key::NONE);
  1356. MessageQueue::get_singleton()->flush();
  1357. CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
  1358. CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
  1359. // Move back in.
  1360. dragger_pos = 100;
  1361. SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
  1362. MessageQueue::get_singleton()->flush();
  1363. CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
  1364. CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
  1365. // Release.
  1366. SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
  1367. MessageQueue::get_singleton()->flush();
  1368. CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
  1369. CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
  1370. // No longer moves with the mouse.
  1371. SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(200, 0), MouseButtonMask::NONE, Key::NONE);
  1372. MessageQueue::get_singleton()->flush();
  1373. CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
  1374. CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
  1375. }
  1376. SUBCASE("[SplitContainer] Second child expanded") {
  1377. child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1378. MessageQueue::get_singleton()->flush();
  1379. Point2 mouse_offset = Point2(1, 1);
  1380. int dragger_pos = 0;
  1381. int split_dragger_ofs = 0;
  1382. // Grab the dragger.
  1383. SEND_GUI_MOUSE_BUTTON_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  1384. MessageQueue::get_singleton()->flush();
  1385. CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
  1386. CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
  1387. // Move the dragger.
  1388. dragger_pos = 10;
  1389. SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
  1390. MessageQueue::get_singleton()->flush();
  1391. CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
  1392. CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
  1393. // It is clamped.
  1394. split_container->clamp_split_offset();
  1395. CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
  1396. // Continue moving.
  1397. dragger_pos = 400;
  1398. SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
  1399. MessageQueue::get_singleton()->flush();
  1400. CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
  1401. CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
  1402. // Moves even when mouse is outside.
  1403. dragger_pos = split_container->get_size().x - sep.x;
  1404. SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(1000, 0), MouseButtonMask::LEFT, Key::NONE);
  1405. MessageQueue::get_singleton()->flush();
  1406. CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
  1407. CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
  1408. // Move back in.
  1409. dragger_pos = 100;
  1410. SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
  1411. MessageQueue::get_singleton()->flush();
  1412. CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
  1413. CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
  1414. // Release.
  1415. SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
  1416. MessageQueue::get_singleton()->flush();
  1417. CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
  1418. CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
  1419. // No longer moves with the mouse.
  1420. SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(200, 0), MouseButtonMask::NONE, Key::NONE);
  1421. MessageQueue::get_singleton()->flush();
  1422. CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
  1423. CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
  1424. }
  1425. SUBCASE("[SplitContainer] Both children expanded") {
  1426. child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1427. child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1428. MessageQueue::get_singleton()->flush();
  1429. Point2 mouse_offset = Point2(1, 1);
  1430. int dragger_pos = (split_container->get_size().x - sep.x) / 2;
  1431. int split_dragger_ofs = -dragger_pos;
  1432. // Grab the dragger.
  1433. SEND_GUI_MOUSE_BUTTON_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  1434. MessageQueue::get_singleton()->flush();
  1435. CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
  1436. CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
  1437. // Move the dragger.
  1438. dragger_pos += 10;
  1439. SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
  1440. MessageQueue::get_singleton()->flush();
  1441. CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
  1442. CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
  1443. // It is clamped.
  1444. split_container->clamp_split_offset();
  1445. CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
  1446. // Continue moving.
  1447. dragger_pos = 400;
  1448. SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
  1449. MessageQueue::get_singleton()->flush();
  1450. CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
  1451. CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
  1452. // Moves even when mouse is outside.
  1453. dragger_pos = split_container->get_size().x - sep.x;
  1454. SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(1000, 0), MouseButtonMask::LEFT, Key::NONE);
  1455. MessageQueue::get_singleton()->flush();
  1456. CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
  1457. CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
  1458. // Move back in.
  1459. dragger_pos = 100;
  1460. SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
  1461. MessageQueue::get_singleton()->flush();
  1462. CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
  1463. CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
  1464. // Release.
  1465. SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
  1466. MessageQueue::get_singleton()->flush();
  1467. CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
  1468. CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
  1469. // No longer moves with the mouse.
  1470. SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(200, 0), MouseButtonMask::NONE, Key::NONE);
  1471. MessageQueue::get_singleton()->flush();
  1472. CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
  1473. CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
  1474. }
  1475. }
  1476. memdelete(child_b);
  1477. memdelete(child_a);
  1478. memdelete(split_container);
  1479. }
  1480. TEST_CASE("[SceneTree][SplitContainer] More children") {
  1481. SplitContainer *split_container = memnew(SplitContainer);
  1482. split_container->set_size(Size2(500, 500));
  1483. SceneTree::get_singleton()->get_root()->add_child(split_container);
  1484. Control *child_a = memnew(Control);
  1485. Control *child_b = memnew(Control);
  1486. Control *child_c = memnew(Control);
  1487. split_container->add_child(child_a);
  1488. split_container->add_child(child_b);
  1489. split_container->add_child(child_c);
  1490. Size2i min_size = Size2i(10, 10);
  1491. child_a->set_custom_minimum_size(min_size);
  1492. child_b->set_custom_minimum_size(min_size);
  1493. child_c->set_custom_minimum_size(min_size);
  1494. MessageQueue::get_singleton()->flush();
  1495. const int sep_constant = split_container->get_theme_constant("separation");
  1496. const Size2i sep = Size2i(MAX(sep_constant, split_container->get_theme_icon("h_grabber")->get_width()), MAX(sep_constant, split_container->get_theme_icon("v_grabber")->get_height()));
  1497. SUBCASE("[SplitContainer] Duplicate") {
  1498. // Make sure dynamically added internal draggers duplicate properly.
  1499. SplitContainer *duplicate = (SplitContainer *)(Node *)split_container->duplicate();
  1500. MessageQueue::get_singleton()->flush();
  1501. CHECK(duplicate->get_child_count(false) == split_container->get_child_count(false));
  1502. CHECK(duplicate->get_child_count(true) == split_container->get_child_count(true));
  1503. memdelete(duplicate);
  1504. }
  1505. SUBCASE("[SplitContainer] Default position") {
  1506. CHECK(split_container->get_split_offsets() == Vector<int>({ 0, 0 }));
  1507. set_size_flags(split_container, { -1, -1, -1 }); // None expanded.
  1508. Vector<int> def_pos = { min_size.x, min_size.x * 2 + sep.x };
  1509. CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
  1510. split_container->clamp_split_offset();
  1511. MessageQueue::get_singleton()->flush();
  1512. CHECK(split_container->get_split_offsets() == Vector<int>({ min_size.x, min_size.x * 2 + sep.x }));
  1513. CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
  1514. split_container->set_split_offsets({ 0, 0 });
  1515. set_size_flags(split_container, { 1, -1, -1 }); // First expanded.
  1516. def_pos = { (int)split_container->get_size().x - sep.x * 2 - min_size.x * 2, (int)split_container->get_size().x - sep.x - min_size.x };
  1517. CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
  1518. split_container->clamp_split_offset();
  1519. MessageQueue::get_singleton()->flush();
  1520. CHECK(split_container->get_split_offsets() == Vector<int>({ -min_size.x * 2 - sep.x, -min_size.x }));
  1521. CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
  1522. split_container->set_split_offsets({ 0, 0 });
  1523. set_size_flags(split_container, { -1, 1, -1 }); // Second expanded.
  1524. def_pos = { min_size.x, (int)split_container->get_size().x - min_size.x - sep.x };
  1525. CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
  1526. split_container->clamp_split_offset();
  1527. MessageQueue::get_singleton()->flush();
  1528. CHECK(split_container->get_split_offsets() == Vector<int>({ min_size.x, -min_size.x }));
  1529. CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
  1530. split_container->set_split_offsets({ 0, 0 });
  1531. set_size_flags(split_container, { -1, -1, 1 }); // Third expanded.
  1532. def_pos = { min_size.x, min_size.x * 2 + sep.x };
  1533. CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
  1534. split_container->clamp_split_offset();
  1535. MessageQueue::get_singleton()->flush();
  1536. CHECK(split_container->get_split_offsets() == Vector<int>({ min_size.x, min_size.x * 2 + sep.x }));
  1537. CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
  1538. split_container->set_split_offsets({ 0, 0 });
  1539. set_size_flags(split_container, { 1, 1, -1 }); // First and second expanded.
  1540. int child_2_expanded_size = ((int)split_container->get_size().x - min_size.x) / 2 - sep.x;
  1541. def_pos = { child_2_expanded_size, (int)split_container->get_size().x - min_size.x - sep.x };
  1542. CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
  1543. split_container->clamp_split_offset();
  1544. MessageQueue::get_singleton()->flush();
  1545. CHECK(split_container->get_split_offsets() == Vector<int>({ 0, -min_size.x }));
  1546. CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
  1547. split_container->set_split_offsets({ 0, 0 });
  1548. set_size_flags(split_container, { 1, -1, 1 }); // First and third expanded.
  1549. def_pos = { child_2_expanded_size, child_2_expanded_size + min_size.x + sep.x };
  1550. CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
  1551. split_container->clamp_split_offset();
  1552. MessageQueue::get_singleton()->flush();
  1553. CHECK(split_container->get_split_offsets() == Vector<int>({ 0, 0 }));
  1554. CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
  1555. split_container->set_split_offsets({ 0, 0 });
  1556. set_size_flags(split_container, { -1, 1, 1 }); // Second and third expanded.
  1557. def_pos = { min_size.x, min_size.x + child_2_expanded_size + sep.x };
  1558. CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
  1559. split_container->clamp_split_offset();
  1560. MessageQueue::get_singleton()->flush();
  1561. CHECK(split_container->get_split_offsets() == Vector<int>({ min_size.x, 0 }));
  1562. CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
  1563. split_container->set_split_offsets({ 0, 0 });
  1564. set_size_flags(split_container, { 1, 1, 1 }); // All expanded.
  1565. int child_3_expanded_size = (split_container->get_size().x - sep.x * 2) / 3;
  1566. // Add 1 due to pixel error accumulation.
  1567. def_pos = { child_3_expanded_size, child_3_expanded_size * 2 + sep.x + 1 };
  1568. CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
  1569. split_container->clamp_split_offset();
  1570. MessageQueue::get_singleton()->flush();
  1571. CHECK(split_container->get_split_offsets() == Vector<int>({ 0, 0 }));
  1572. CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
  1573. split_container->set_split_offsets({ 0, 0 });
  1574. set_size_flags(split_container, { 1, 2, 3 }); // All expanded, different ratios.
  1575. int child_6_expanded_size = (split_container->get_size().x - sep.x * 2) / 6;
  1576. def_pos = { child_6_expanded_size, child_6_expanded_size * 3 + sep.x + 1 };
  1577. CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
  1578. split_container->clamp_split_offset();
  1579. MessageQueue::get_singleton()->flush();
  1580. CHECK(split_container->get_split_offsets() == Vector<int>({ 0, 0 }));
  1581. CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
  1582. split_container->set_split_offsets({ 0, 0 });
  1583. }
  1584. SUBCASE("[SplitContainer] Set split offset") {
  1585. const int expanded_single_size = (int)split_container->get_size().x - min_size.x * 2 - sep.x * 2;
  1586. SUBCASE("[SplitContainer] No expand flags") {
  1587. set_size_flags(split_container, { -1, -1, -1 }); // None expanded.
  1588. // First is positive.
  1589. split_container->set_split_offsets({ 50, 0 });
  1590. MessageQueue::get_singleton()->flush();
  1591. CHECK(split_container->get_split_offsets() == Vector<int>{ 50, 0 });
  1592. CHECK_RECTS(get_rects_multi(split_container, { 50, 50 + min_size.x + sep.x }, sep.x), get_child_rects(split_container));
  1593. // Second is positive.
  1594. split_container->set_split_offsets({ 0, 50 });
  1595. MessageQueue::get_singleton()->flush();
  1596. CHECK(split_container->get_split_offsets() == Vector<int>{ 0, 50 });
  1597. CHECK_RECTS(get_rects_multi(split_container, { min_size.x, 50 }, sep.x), get_child_rects(split_container));
  1598. // Both are positive and equal, the first will override since they both start at 0.
  1599. split_container->set_split_offsets({ 50, 50 });
  1600. MessageQueue::get_singleton()->flush();
  1601. CHECK(split_container->get_split_offsets() == Vector<int>{ 50, 50 });
  1602. CHECK_RECTS(get_rects_multi(split_container, { 50, 50 + min_size.x + sep.x }, sep.x), get_child_rects(split_container));
  1603. // Both are negative and clamped.
  1604. split_container->set_split_offsets({ -50, -50 });
  1605. MessageQueue::get_singleton()->flush();
  1606. CHECK(split_container->get_split_offsets() == Vector<int>{ -50, -50 });
  1607. CHECK_RECTS(get_rects_multi(split_container, { min_size.x, min_size.x * 2 + sep.x }, sep.x), get_child_rects(split_container));
  1608. // First positive, second negative. First takes priority.
  1609. split_container->set_split_offsets({ 50, -50 });
  1610. MessageQueue::get_singleton()->flush();
  1611. CHECK(split_container->get_split_offsets() == Vector<int>{ 50, -50 });
  1612. CHECK_RECTS(get_rects_multi(split_container, { 50, 50 + min_size.x + sep.x }, sep.x), get_child_rects(split_container));
  1613. // First is clamped and pushes second to the end.
  1614. split_container->set_split_offsets({ 1000, 0 });
  1615. MessageQueue::get_singleton()->flush();
  1616. CHECK(split_container->get_split_offsets() == Vector<int>{ 1000, 0 });
  1617. CHECK_RECTS(get_rects_multi(split_container, { expanded_single_size, expanded_single_size + min_size.x + sep.x }, sep.x), get_child_rects(split_container));
  1618. // Second is clamped.
  1619. split_container->set_split_offsets({ 0, 1000 });
  1620. MessageQueue::get_singleton()->flush();
  1621. CHECK(split_container->get_split_offsets() == Vector<int>{ 0, 1000 });
  1622. CHECK_RECTS(get_rects_multi(split_container, { min_size.x, expanded_single_size + min_size.x + sep.x }, sep.x), get_child_rects(split_container));
  1623. // Both are clamped positively, first one takes priority.
  1624. split_container->set_split_offsets({ 1000, 1000 });
  1625. MessageQueue::get_singleton()->flush();
  1626. CHECK(split_container->get_split_offsets() == Vector<int>{ 1000, 1000 });
  1627. CHECK_RECTS(get_rects_multi(split_container, { expanded_single_size, expanded_single_size + min_size.x + sep.x }, sep.x), get_child_rects(split_container));
  1628. }
  1629. SUBCASE("[SplitContainer] First child expanded") {
  1630. set_size_flags(split_container, { 1, -1, -1 }); // First expanded.
  1631. // First is positive and clamped.
  1632. split_container->set_split_offsets({ 50, 0 });
  1633. MessageQueue::get_singleton()->flush();
  1634. CHECK(split_container->get_split_offsets() == Vector<int>{ 50, 0 });
  1635. CHECK_RECTS(get_rects_multi(split_container, { expanded_single_size, expanded_single_size + min_size.x + sep.x }, sep.x), get_child_rects(split_container));
  1636. // Second is positive and clamped.
  1637. split_container->set_split_offsets({ 0, 50 });
  1638. MessageQueue::get_singleton()->flush();
  1639. CHECK(split_container->get_split_offsets() == Vector<int>{ 0, 50 });
  1640. CHECK_RECTS(get_rects_multi(split_container, { expanded_single_size, expanded_single_size + min_size.x + sep.x }, sep.x), get_child_rects(split_container));
  1641. // First is negative and moves left.
  1642. split_container->set_split_offsets({ -50, 0 });
  1643. MessageQueue::get_singleton()->flush();
  1644. CHECK(split_container->get_split_offsets() == Vector<int>{ -50, 0 });
  1645. CHECK_RECTS(get_rects_multi(split_container, { (int)split_container->get_size().x - 50 - sep.x, (int)split_container->get_size().x - min_size.x - sep.x }, sep.x), get_child_rects(split_container));
  1646. // Second is negative, but first has priority so it doesn't move.
  1647. split_container->set_split_offsets({ 0, -50 });
  1648. MessageQueue::get_singleton()->flush();
  1649. CHECK(split_container->get_split_offsets() == Vector<int>{ 0, -50 });
  1650. CHECK_RECTS(get_rects_multi(split_container, { expanded_single_size, expanded_single_size + min_size.x + sep.x }, sep.x), get_child_rects(split_container));
  1651. // Both are negative and equal, they move left but the second doesn't move as much as wanted.
  1652. split_container->set_split_offsets({ -50, -50 });
  1653. MessageQueue::get_singleton()->flush();
  1654. CHECK(split_container->get_split_offsets() == Vector<int>{ -50, -50 });
  1655. CHECK_RECTS(get_rects_multi(split_container, { (int)split_container->get_size().x - 50 - sep.x, (int)split_container->get_size().x - 50 + min_size.x }, sep.x), get_child_rects(split_container));
  1656. // Both are negative with space and move left.
  1657. split_container->set_split_offsets({ -100, -50 });
  1658. MessageQueue::get_singleton()->flush();
  1659. CHECK(split_container->get_split_offsets() == Vector<int>{ -100, -50 });
  1660. CHECK_RECTS(get_rects_multi(split_container, { (int)split_container->get_size().x - 100 - sep.x, (int)split_container->get_size().x - 50 - sep.x }, sep.x), get_child_rects(split_container));
  1661. // First moves all the way left.
  1662. split_container->set_split_offsets({ -1000, 0 });
  1663. MessageQueue::get_singleton()->flush();
  1664. CHECK(split_container->get_split_offsets() == Vector<int>{ -1000, 0 });
  1665. CHECK_RECTS(get_rects_multi(split_container, { min_size.x, expanded_single_size + min_size.x + sep.x }, sep.x), get_child_rects(split_container));
  1666. // Second cannot move all the way left since first takes priority.
  1667. split_container->set_split_offsets({ 0, -1000 });
  1668. MessageQueue::get_singleton()->flush();
  1669. CHECK(split_container->get_split_offsets() == Vector<int>{ 0, -1000 });
  1670. CHECK_RECTS(get_rects_multi(split_container, { expanded_single_size, expanded_single_size + min_size.x + sep.x }, sep.x), get_child_rects(split_container));
  1671. // First and second move all the way left.
  1672. split_container->set_split_offsets({ -1000, -1000 });
  1673. MessageQueue::get_singleton()->flush();
  1674. CHECK(split_container->get_split_offsets() == Vector<int>{ -1000, -1000 });
  1675. CHECK_RECTS(get_rects_multi(split_container, { min_size.x, min_size.x * 2 + sep.x }, sep.x), get_child_rects(split_container));
  1676. }
  1677. SUBCASE("[SplitContainer] All children expanded") {
  1678. set_size_flags(split_container, { 1, 1, 1 }); // All expanded.
  1679. const int child_3_expanded_size = (split_container->get_size().x - sep.x * 2) / 3;
  1680. // First is moved positive, does not affect second.
  1681. split_container->set_split_offsets({ 50, 0 });
  1682. MessageQueue::get_singleton()->flush();
  1683. CHECK(split_container->get_split_offsets() == Vector<int>{ 50, 0 });
  1684. CHECK_RECTS(get_rects_multi(split_container, { child_3_expanded_size + 50, child_3_expanded_size * 2 + sep.x + 1 }, sep.x), get_child_rects(split_container));
  1685. // First is moved negative, does not affect second.
  1686. split_container->set_split_offsets({ -50, 0 });
  1687. MessageQueue::get_singleton()->flush();
  1688. CHECK(split_container->get_split_offsets() == Vector<int>{ -50, 0 });
  1689. CHECK_RECTS(get_rects_multi(split_container, { child_3_expanded_size - 50, child_3_expanded_size * 2 + sep.x + 1 }, sep.x), get_child_rects(split_container));
  1690. // Second is moved positive, does not affect first.
  1691. split_container->set_split_offsets({ 0, 50 });
  1692. MessageQueue::get_singleton()->flush();
  1693. CHECK(split_container->get_split_offsets() == Vector<int>{ 0, 50 });
  1694. CHECK_RECTS(get_rects_multi(split_container, { child_3_expanded_size, child_3_expanded_size * 2 + 50 + sep.x + 1 }, sep.x), get_child_rects(split_container));
  1695. // Second is moved negative, does not affect first.
  1696. split_container->set_split_offsets({ 0, -50 });
  1697. MessageQueue::get_singleton()->flush();
  1698. CHECK(split_container->get_split_offsets() == Vector<int>{ 0, -50 });
  1699. CHECK_RECTS(get_rects_multi(split_container, { child_3_expanded_size, child_3_expanded_size * 2 - 50 + sep.x + 1 }, sep.x), get_child_rects(split_container));
  1700. // First is moved positive enough to affect second.
  1701. split_container->set_split_offsets({ 200, 0 });
  1702. MessageQueue::get_singleton()->flush();
  1703. CHECK(split_container->get_split_offsets() == Vector<int>{ 200, 0 });
  1704. CHECK_RECTS(get_rects_multi(split_container, { child_3_expanded_size + 200, child_3_expanded_size + 200 + sep.x + min_size.x }, sep.x), get_child_rects(split_container));
  1705. // Second is moved enough to pass the first, but the first has priority.
  1706. split_container->set_split_offsets({ 0, -200 });
  1707. MessageQueue::get_singleton()->flush();
  1708. CHECK(split_container->get_split_offsets() == Vector<int>{ 0, -200 });
  1709. CHECK_RECTS(get_rects_multi(split_container, { child_3_expanded_size, child_3_expanded_size + min_size.x + sep.x }, sep.x), get_child_rects(split_container));
  1710. }
  1711. }
  1712. SUBCASE("[SplitContainer] Resize") {
  1713. SUBCASE("[SplitContainer] No expand flags") {
  1714. Vector<int> def_pos = { min_size.x, min_size.x * 2 + sep.x };
  1715. // Increase the size.
  1716. split_container->set_size(Size2(600, 500));
  1717. MessageQueue::get_singleton()->flush();
  1718. CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
  1719. // Decrease the size.
  1720. split_container->set_size(Size2(400, 500));
  1721. MessageQueue::get_singleton()->flush();
  1722. CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
  1723. // Change size with a split offset.
  1724. split_container->set_split_offsets({ 50, 100 });
  1725. split_container->set_size(Size2(500, 500));
  1726. MessageQueue::get_singleton()->flush();
  1727. CHECK_RECTS(get_rects_multi(split_container, { 50, 100 }, sep.x), get_child_rects(split_container));
  1728. CHECK(split_container->get_split_offsets() == Vector<int>{ 50, 100 });
  1729. // Change size so that the second child gets clamped and changes size.
  1730. split_container->set_size(Size2(100, 500));
  1731. MessageQueue::get_singleton()->flush();
  1732. CHECK_RECTS(get_rects_multi(split_container, { 50, 100 - sep.x - min_size.x }, sep.x), get_child_rects(split_container));
  1733. CHECK(split_container->get_split_offsets() == Vector<int>{ 50, 100 });
  1734. // Change size so that the first child changes size.
  1735. split_container->set_size(Size2(60, 500));
  1736. MessageQueue::get_singleton()->flush();
  1737. CHECK_RECTS(get_rects_multi(split_container, { 60 - min_size.x * 2 - sep.x * 2, 60 - sep.x - min_size.x }, sep.x), get_child_rects(split_container));
  1738. CHECK(split_container->get_split_offsets() == Vector<int>{ 50, 100 });
  1739. // Increase size again.
  1740. split_container->set_size(Size2(500, 500));
  1741. MessageQueue::get_singleton()->flush();
  1742. CHECK_RECTS(get_rects_multi(split_container, { 50, 100 }, sep.x), get_child_rects(split_container));
  1743. CHECK(split_container->get_split_offsets() == Vector<int>{ 50, 100 });
  1744. }
  1745. SUBCASE("[SplitContainer] First child expanded") {
  1746. set_size_flags(split_container, { 1, -1, -1 });
  1747. Vector<int> def_pos = { (int)split_container->get_size().x - sep.x * 2 - min_size.x, (int)split_container->get_size().x - sep.x };
  1748. // Increase the size.
  1749. split_container->set_size(Size2(600, 500));
  1750. def_pos = { (int)split_container->get_size().x - sep.x * 2 - min_size.x * 2, (int)split_container->get_size().x - sep.x - min_size.x };
  1751. MessageQueue::get_singleton()->flush();
  1752. CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
  1753. // Decrease the size.
  1754. split_container->set_size(Size2(400, 500));
  1755. def_pos = { (int)split_container->get_size().x - sep.x * 2 - min_size.x * 2, (int)split_container->get_size().x - sep.x - min_size.x };
  1756. MessageQueue::get_singleton()->flush();
  1757. CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
  1758. // Change size with a split offset.
  1759. split_container->set_split_offsets({ -100, -50 });
  1760. split_container->set_size(Size2(500, 500));
  1761. MessageQueue::get_singleton()->flush();
  1762. CHECK_RECTS(get_rects_multi(split_container, { (int)split_container->get_size().x - 100 - sep.x, (int)split_container->get_size().x - 50 - sep.x }, sep.x), get_child_rects(split_container));
  1763. CHECK(split_container->get_split_offsets() == Vector<int>{ -100, -50 });
  1764. // Change size so that the first child gets clamped and changes size.
  1765. split_container->set_size(Size2(100, 500));
  1766. MessageQueue::get_singleton()->flush();
  1767. CHECK_RECTS(get_rects_multi(split_container, { min_size.x, (int)split_container->get_size().x - 50 - sep.x }, sep.x), get_child_rects(split_container));
  1768. CHECK(split_container->get_split_offsets() == Vector<int>{ -100, -50 });
  1769. // Change size so that the second child changes size.
  1770. split_container->set_size(Size2(50, 500));
  1771. MessageQueue::get_singleton()->flush();
  1772. CHECK_RECTS(get_rects_multi(split_container, { min_size.x, min_size.x * 2 + sep.x }, sep.x), get_child_rects(split_container));
  1773. CHECK(split_container->get_split_offsets() == Vector<int>{ -100, -50 });
  1774. // Increase size again.
  1775. split_container->set_size(Size2(500, 500));
  1776. MessageQueue::get_singleton()->flush();
  1777. CHECK_RECTS(get_rects_multi(split_container, { (int)split_container->get_size().x - 100 - sep.x, (int)split_container->get_size().x - 50 - sep.x }, sep.x), get_child_rects(split_container));
  1778. CHECK(split_container->get_split_offsets() == Vector<int>{ -100, -50 });
  1779. }
  1780. SUBCASE("[SplitContainer] All children expanded") {
  1781. set_size_flags(split_container, { 1, 1, 1 });
  1782. // Increase the size.
  1783. split_container->set_size(Size2(600, 500));
  1784. MessageQueue::get_singleton()->flush();
  1785. int child_3_expanded_size = (split_container->get_size().x - sep.x * 2) / 3;
  1786. Vector<int> def_pos = { child_3_expanded_size, child_3_expanded_size * 2 + sep.x };
  1787. CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
  1788. // Decrease the size.
  1789. split_container->set_size(Size2(400, 500));
  1790. MessageQueue::get_singleton()->flush();
  1791. child_3_expanded_size = (split_container->get_size().x - sep.x * 2) / 3;
  1792. def_pos = { child_3_expanded_size, child_3_expanded_size * 2 + sep.x };
  1793. CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
  1794. // Change size with a split offset.
  1795. split_container->set_split_offsets({ -50, 50 });
  1796. split_container->set_size(Size2(500, 500));
  1797. MessageQueue::get_singleton()->flush();
  1798. child_3_expanded_size = (split_container->get_size().x - sep.x * 2) / 3;
  1799. def_pos = { child_3_expanded_size, child_3_expanded_size * 2 + sep.x + 1 };
  1800. CHECK_RECTS(get_rects_multi(split_container, { def_pos[0] - 50, def_pos[1] + 50 }, sep.x), get_child_rects(split_container));
  1801. CHECK(split_container->get_split_offsets() == Vector<int>{ -50, 50 });
  1802. // Change size so that the children get clamped and change sizes.
  1803. split_container->set_size(Size2(100, 500));
  1804. MessageQueue::get_singleton()->flush();
  1805. CHECK_RECTS(get_rects_multi(split_container, { min_size.x, (int)split_container->get_size().x - sep.x - min_size.x }, sep.x), get_child_rects(split_container));
  1806. CHECK(split_container->get_split_offsets() == Vector<int>{ -50, 50 });
  1807. // Increase size again.
  1808. split_container->set_size(Size2(500, 500));
  1809. MessageQueue::get_singleton()->flush();
  1810. child_3_expanded_size = (split_container->get_size().x - sep.x * 2) / 3;
  1811. def_pos = { child_3_expanded_size, child_3_expanded_size * 2 + sep.x + 1 };
  1812. CHECK_RECTS(get_rects_multi(split_container, { def_pos[0] - 50, def_pos[1] + 50 }, sep.x), get_child_rects(split_container));
  1813. CHECK(split_container->get_split_offsets() == Vector<int>{ -50, 50 });
  1814. }
  1815. }
  1816. SUBCASE("[SplitContainer] Visibility changes") {
  1817. set_size_flags(split_container, { -1, -1, -1 }); // None expanded.
  1818. split_container->set_split_offsets({ 50, 122 });
  1819. MessageQueue::get_singleton()->flush();
  1820. Vector<int> def_pos = { 50, 122 };
  1821. CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
  1822. // Hide and show the first child.
  1823. child_a->set_visible(false);
  1824. MessageQueue::get_singleton()->flush();
  1825. CHECK(split_container->get_split_offsets() == Vector<int>({ 60 }));
  1826. CHECK_RECTS(get_rects_multi(split_container, { 60 }, sep.x), get_child_rects(split_container));
  1827. child_a->set_visible(true);
  1828. MessageQueue::get_singleton()->flush();
  1829. CHECK(split_container->get_split_offsets() == def_pos);
  1830. CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
  1831. // Hide and show the second child.
  1832. child_b->set_visible(false);
  1833. MessageQueue::get_singleton()->flush();
  1834. CHECK(split_container->get_split_offsets() == Vector<int>({ 50 }));
  1835. CHECK_RECTS(get_rects_multi(split_container, { 50 }, sep.x), get_child_rects(split_container));
  1836. child_b->set_visible(true);
  1837. MessageQueue::get_singleton()->flush();
  1838. CHECK(split_container->get_split_offsets() == def_pos);
  1839. CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
  1840. // Hide and show the last child.
  1841. child_c->set_visible(false);
  1842. MessageQueue::get_singleton()->flush();
  1843. CHECK(split_container->get_split_offsets() == Vector<int>({ 50 }));
  1844. CHECK_RECTS(get_rects_multi(split_container, { 50 }, sep.x), get_child_rects(split_container));
  1845. child_c->set_visible(true);
  1846. MessageQueue::get_singleton()->flush();
  1847. CHECK(split_container->get_split_offsets() == def_pos);
  1848. CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
  1849. set_size_flags(split_container, { 1, 1, 1 }); // All expanded.
  1850. split_container->set_split_offsets({ 50, 60 });
  1851. MessageQueue::get_singleton()->flush();
  1852. int child_3_expanded_size = (split_container->get_size().x - sep.x * 2) / 3;
  1853. def_pos = { child_3_expanded_size + 50, child_3_expanded_size * 2 + sep.x + 1 + 60 };
  1854. CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
  1855. // Hide and show the first child.
  1856. int child_2_expanded_size = (split_container->get_size().x - sep.x) / 2;
  1857. child_a->set_visible(false);
  1858. MessageQueue::get_singleton()->flush();
  1859. int half_point = (split_container->get_size().x - def_pos[0]) / 2 - sep.x;
  1860. int so = child_3_expanded_size + 11 - half_point; // 11 is from 60 - 50 + 1 to get the second child's size.
  1861. CHECK_RECTS(get_rects_multi(split_container, { child_2_expanded_size + so }, sep.x), get_child_rects(split_container));
  1862. CHECK(split_container->get_split_offsets() == Vector<int>({ so }));
  1863. child_a->set_visible(true);
  1864. MessageQueue::get_singleton()->flush();
  1865. CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
  1866. CHECK(split_container->get_split_offsets() == Vector<int>({ 50, 60 }));
  1867. // Hide and show the second child.
  1868. child_b->set_visible(false);
  1869. MessageQueue::get_singleton()->flush();
  1870. half_point = (split_container->get_size().x - (def_pos[1] - def_pos[0] - sep.x)) / 2 - sep.x + 1;
  1871. so = def_pos[0] - half_point;
  1872. CHECK_RECTS(get_rects_multi(split_container, { child_2_expanded_size + so }, sep.x), get_child_rects(split_container));
  1873. CHECK(split_container->get_split_offsets() == Vector<int>({ so }));
  1874. child_b->set_visible(true);
  1875. MessageQueue::get_singleton()->flush();
  1876. // There is lost precision due to SplitContainer using ints, so this is off by one.
  1877. CHECK_RECTS(get_rects_multi(split_container, { def_pos[0] - 1, def_pos[1] - 1 }, sep.x), get_child_rects(split_container));
  1878. CHECK(split_container->get_split_offsets() == Vector<int>({ 49, 59 }));
  1879. // Hide and show the last child.
  1880. split_container->set_split_offsets({ 50, 60 });
  1881. child_c->set_visible(false);
  1882. MessageQueue::get_singleton()->flush();
  1883. half_point = (def_pos[1] - sep.x) / 2 + 1;
  1884. so = def_pos[0] - half_point;
  1885. CHECK_RECTS(get_rects_multi(split_container, { child_2_expanded_size + so }, sep.x), get_child_rects(split_container));
  1886. CHECK(split_container->get_split_offsets() == Vector<int>({ so }));
  1887. child_c->set_visible(true);
  1888. MessageQueue::get_singleton()->flush();
  1889. CHECK_RECTS(get_rects_multi(split_container, { def_pos[0] - 1, def_pos[1] - 1 }, sep.x), get_child_rects(split_container));
  1890. CHECK(split_container->get_split_offsets() == Vector<int>({ 49, 59 }));
  1891. }
  1892. SUBCASE("[SplitContainer] Adjust split offset when moving children") {
  1893. split_container->set_split_offsets({ 50, 80 });
  1894. split_container->move_child(child_a, 1);
  1895. Vector<int> pos = { 30 - sep.x, 80 }; // 30 = 80 - 50.
  1896. MessageQueue::get_singleton()->flush();
  1897. CHECK(split_container->get_split_offsets() == pos);
  1898. CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
  1899. // Move last child to first.
  1900. split_container->set_split_offsets({ 50, 80 });
  1901. split_container->move_child(child_c, 0);
  1902. pos = { (int)split_container->get_size().x - 80 - sep.x, (int)split_container->get_size().x - 30 };
  1903. MessageQueue::get_singleton()->flush();
  1904. CHECK(split_container->get_split_offsets() == pos);
  1905. CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
  1906. // Move it back.
  1907. split_container->move_child(child_c, 2);
  1908. pos = { 50, 80 };
  1909. MessageQueue::get_singleton()->flush();
  1910. CHECK(split_container->get_split_offsets() == pos);
  1911. CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
  1912. }
  1913. SUBCASE("[SplitContainer] Showing child with not enough space shrinks the largest child first") {
  1914. set_size_flags(split_container, { -1, -1, -1 }); // None expanded.
  1915. // Second child is largest.
  1916. child_a->set_visible(false);
  1917. Vector<int> pos = { 360 };
  1918. split_container->set_split_offsets(pos);
  1919. MessageQueue::get_singleton()->flush();
  1920. CHECK(split_container->get_split_offsets() == pos);
  1921. CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
  1922. child_a->set_size(Vector2(100, 100));
  1923. MessageQueue::get_singleton()->flush();
  1924. CHECK(split_container->get_split_offsets() == pos);
  1925. CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
  1926. child_a->set_visible(true);
  1927. pos = { 100, 360 };
  1928. MessageQueue::get_singleton()->flush();
  1929. CHECK(split_container->get_split_offsets() == pos);
  1930. CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
  1931. // Last child is largest.
  1932. child_a->set_visible(false);
  1933. pos = { 60 };
  1934. split_container->set_split_offsets(pos);
  1935. MessageQueue::get_singleton()->flush();
  1936. CHECK(split_container->get_split_offsets() == pos);
  1937. CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
  1938. child_a->set_size(Vector2(100, 100));
  1939. MessageQueue::get_singleton()->flush();
  1940. CHECK(split_container->get_split_offsets() == pos);
  1941. CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
  1942. child_a->set_visible(true);
  1943. pos = { 100, 160 + sep.x };
  1944. MessageQueue::get_singleton()->flush();
  1945. CHECK(split_container->get_split_offsets() == pos);
  1946. CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
  1947. // Both visible children are the same size.
  1948. child_a->set_visible(false);
  1949. pos = { (int)split_container->get_size().x / 2 - sep.x / 2 };
  1950. split_container->set_split_offsets(pos);
  1951. MessageQueue::get_singleton()->flush();
  1952. CHECK(split_container->get_split_offsets() == pos);
  1953. CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
  1954. CHECK(child_b->get_size().x == child_c->get_size().x);
  1955. child_a->set_size(Vector2(100, 100));
  1956. MessageQueue::get_singleton()->flush();
  1957. CHECK(split_container->get_split_offsets() == pos);
  1958. CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
  1959. child_a->set_visible(true);
  1960. pos = { 100, (int)split_container->get_size().x / 2 + 50 };
  1961. MessageQueue::get_singleton()->flush();
  1962. CHECK(split_container->get_split_offsets() == pos);
  1963. CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
  1964. CHECK(child_b->get_size().x == child_c->get_size().x);
  1965. // Second child is slightly larger than the last child.
  1966. child_a->set_visible(false);
  1967. pos = { (int)split_container->get_size().x / 2 - sep.x / 2 + 20 };
  1968. split_container->set_split_offsets(pos);
  1969. MessageQueue::get_singleton()->flush();
  1970. CHECK(split_container->get_split_offsets() == pos);
  1971. CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
  1972. child_a->set_size(Vector2(100, 100));
  1973. MessageQueue::get_singleton()->flush();
  1974. CHECK(split_container->get_split_offsets() == pos);
  1975. CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
  1976. child_a->set_visible(true);
  1977. pos = { 100, (int)split_container->get_size().x / 2 + 50 };
  1978. MessageQueue::get_singleton()->flush();
  1979. CHECK(split_container->get_split_offsets() == pos);
  1980. CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
  1981. CHECK(child_b->get_size().x == child_c->get_size().x);
  1982. }
  1983. memdelete(split_container);
  1984. }
  1985. } // namespace TestSplitContainer