| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358 |
- /**************************************************************************/
- /* test_split_container.h */
- /**************************************************************************/
- /* This file is part of: */
- /* GODOT ENGINE */
- /* https://godotengine.org */
- /**************************************************************************/
- /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
- /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
- /* */
- /* Permission is hereby granted, free of charge, to any person obtaining */
- /* a copy of this software and associated documentation files (the */
- /* "Software"), to deal in the Software without restriction, including */
- /* without limitation the rights to use, copy, modify, merge, publish, */
- /* distribute, sublicense, and/or sell copies of the Software, and to */
- /* permit persons to whom the Software is furnished to do so, subject to */
- /* the following conditions: */
- /* */
- /* The above copyright notice and this permission notice shall be */
- /* included in all copies or substantial portions of the Software. */
- /* */
- /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
- /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
- /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
- /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
- /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
- /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
- /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
- /**************************************************************************/
- #pragma once
- #include "scene/gui/split_container.h"
- #include "scene/main/window.h"
- #include "tests/test_macros.h"
- namespace TestSplitContainer {
- #define CHECK_RECTS(m_rects, m_child_rects) \
- CHECK(m_rects.size() == m_child_rects.size()); \
- for (int i = 0; i < (int)m_child_rects.size(); i++) { \
- 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])); \
- }
- static inline Vector<Rect2> get_rects_multi(SplitContainer *p_sc, const Vector<int> &p_positions, int p_sep, bool p_horizontal = true) {
- // p_positions is the top/left side of the dragger.
- Vector<Rect2> rects;
- int last_pos = 0;
- for (int i = 0; i < (int)p_positions.size() + 1; i++) {
- const int pos = i >= (int)p_positions.size() ? p_sc->get_size()[p_horizontal ? 0 : 1] : p_positions[i];
- Rect2 rect;
- if (p_horizontal) {
- rect.size.y = p_sc->get_size().y;
- rect.position.x = last_pos;
- rect.size.x = pos - last_pos;
- } else {
- rect.size.x = p_sc->get_size().x;
- rect.position.y = last_pos;
- rect.size.y = pos - last_pos;
- }
- rects.push_back(rect);
- last_pos = pos + p_sep;
- }
- return rects;
- }
- static inline Vector<Rect2> get_rects(SplitContainer *p_sc, int p_position, int p_sep, bool p_horizontal = true) {
- return get_rects_multi(p_sc, Vector<int>({ p_position }), p_sep, p_horizontal);
- }
- static inline Vector<Rect2> get_rects_multi_rtl(SplitContainer *p_sc, const Vector<int> &p_positions, int p_sep) {
- Vector<Rect2> rects;
- int last_pos = p_sc->get_size().x;
- for (int i = 0; i < (int)p_positions.size() + 1; i++) {
- const int pos = i >= (int)p_positions.size() ? 0 : p_sc->get_size().x - p_positions[i];
- Rect2 rect;
- rect.size.y = p_sc->get_size().y;
- rect.position.x = pos;
- rect.size.x = last_pos - pos;
- rects.push_back(rect);
- last_pos = pos - p_sep;
- }
- return rects;
- }
- static inline Vector<Rect2> get_rects_rtl(SplitContainer *p_sc, int p_position, int p_sep) {
- return get_rects_multi_rtl(p_sc, Vector<int>({ p_position }), p_sep);
- }
- static inline Vector<Rect2> get_child_rects(SplitContainer *p_sc) {
- Vector<Rect2> rects;
- for (int i = 0; i < p_sc->get_child_count(false); i++) {
- Control *c = Object::cast_to<Control>(p_sc->get_child(i, false));
- if (!c || !c->is_visible()) {
- continue;
- }
- rects.push_back(c->get_rect());
- }
- return rects;
- }
- static inline void set_size_flags(SplitContainer *p_sc, Vector<float> p_expand_ratios, bool p_horizontal = true) {
- for (int i = 0; i < p_sc->get_child_count(false); i++) {
- Control *c = Object::cast_to<Control>(p_sc->get_child(i, false));
- if (!c || !c->is_visible()) {
- continue;
- }
- float ratio = p_expand_ratios[i];
- if (p_horizontal) {
- c->set_h_size_flags(ratio > 0 ? Control::SIZE_EXPAND_FILL : Control::SIZE_FILL);
- } else {
- c->set_v_size_flags(ratio > 0 ? Control::SIZE_EXPAND_FILL : Control::SIZE_FILL);
- }
- if (ratio > 0) {
- c->set_stretch_ratio(ratio);
- }
- }
- MessageQueue::get_singleton()->flush();
- }
- TEST_CASE("[SceneTree][SplitContainer] Add and remove children") {
- SplitContainer *split_container = memnew(SplitContainer);
- split_container->set_size(Size2(500, 500));
- SceneTree::get_singleton()->get_root()->add_child(split_container);
- SUBCASE("[SplitContainer] One child") {
- Control *child_a = memnew(Control);
- split_container->add_child(child_a);
- MessageQueue::get_singleton()->flush();
- // One child will fill the entire area.
- CHECK(child_a->get_rect() == split_container->get_rect());
- split_container->set_vertical(true);
- CHECK(child_a->get_rect() == split_container->get_rect());
- memdelete(child_a);
- }
- SUBCASE("[SplitContainer] Preserve split offset") {
- // The split offset is preserved through adding, removing, and changing visibility of children.
- split_container->set_split_offset(100);
- CHECK(split_container->get_split_offset() == 100);
- Control *child_a = memnew(Control);
- split_container->add_child(child_a);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 100);
- Control *child_b = memnew(Control);
- split_container->add_child(child_b);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 100);
- child_a->hide();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 100);
- child_b->hide();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 100);
- child_b->show();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 100);
- child_a->show();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 100);
- split_container->remove_child(child_a);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 100);
- split_container->add_child(child_a);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 100);
- memdelete(child_a);
- memdelete(child_b);
- }
- memdelete(split_container);
- }
- TEST_CASE("[SceneTree][SplitContainer] Dragger visibility") {
- SplitContainer *split_container = memnew(SplitContainer);
- split_container->set_size(Size2(500, 500));
- SceneTree::get_singleton()->get_root()->add_child(split_container);
- Control *child_a = memnew(Control);
- Control *child_b = memnew(Control);
- split_container->add_child(child_a);
- split_container->add_child(child_b);
- SplitContainerDragger *dragger = Object::cast_to<SplitContainerDragger>(split_container->get_child(2, true));
- split_container->add_theme_constant_override("autohide", 0);
- MessageQueue::get_singleton()->flush();
- const int sep_constant = split_container->get_theme_constant("separation");
- 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()));
- SUBCASE("[SplitContainer] Visibility based on child count") {
- split_container->remove_child(child_a);
- split_container->remove_child(child_b);
- MessageQueue::get_singleton()->flush();
- // No children, not visible.
- CHECK_FALSE(dragger->is_visible());
- // Add one child, not visible.
- split_container->add_child(child_a);
- MessageQueue::get_singleton()->flush();
- CHECK_FALSE(dragger->is_visible());
- // Two children, visible.
- split_container->add_child(child_b);
- MessageQueue::get_singleton()->flush();
- CHECK(dragger->is_visible());
- // Remove a child, not visible.
- split_container->remove_child(child_b);
- MessageQueue::get_singleton()->flush();
- CHECK_FALSE(dragger->is_visible());
- }
- SUBCASE("[SplitContainer] Set dragger visibility") {
- split_container->set_dragger_visibility(SplitContainer::DRAGGER_HIDDEN);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, 0, sep.x), get_child_rects(split_container));
- // Can't check the visibility since it happens in draw.
- split_container->set_dragger_visibility(SplitContainer::DRAGGER_HIDDEN_COLLAPSED);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, 0, 0), get_child_rects(split_container));
- split_container->set_dragger_visibility(SplitContainer::DRAGGER_VISIBLE);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, 0, sep.x), get_child_rects(split_container));
- }
- SUBCASE("[SplitContainer] Not visible when collapsed") {
- split_container->set_collapsed(true);
- MessageQueue::get_singleton()->flush();
- CHECK_FALSE(dragger->is_visible());
- split_container->set_collapsed(false);
- MessageQueue::get_singleton()->flush();
- CHECK(dragger->is_visible());
- }
- memdelete(child_a);
- memdelete(child_b);
- memdelete(split_container);
- }
- TEST_CASE("[SceneTree][SplitContainer] Collapsed") {
- DisplayServerMock *DS = (DisplayServerMock *)(DisplayServer::get_singleton());
- SplitContainer *split_container = memnew(SplitContainer);
- split_container->set_size(Size2(500, 500));
- SceneTree::get_singleton()->get_root()->add_child(split_container);
- Control *child_a = memnew(Control);
- split_container->add_child(child_a);
- Control *child_b = memnew(Control);
- split_container->add_child(child_b);
- MessageQueue::get_singleton()->flush();
- const int sep_constant = split_container->get_theme_constant("separation");
- 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()));
- SUBCASE("[SplitContainer] Dragging and cursor") {
- split_container->set_collapsed(true);
- // Cursor is default.
- SEND_GUI_MOUSE_MOTION_EVENT(Point2(1, 1), MouseButtonMask::NONE, Key::NONE);
- CHECK(DS->get_cursor_shape() == DisplayServer::CURSOR_ARROW);
- // Dragger is disabled, cannot drag.
- SEND_GUI_MOUSE_BUTTON_EVENT(Point2(1, 1), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, 0, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == 0);
- SEND_GUI_MOUSE_MOTION_EVENT(Point2(10, 1), MouseButtonMask::LEFT, Key::NONE);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, 0, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == 0);
- }
- SUBCASE("[SplitContainer] No expand flags") {
- int def_pos = 0;
- split_container->set_split_offset(10);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, def_pos + 10, sep.x), get_child_rects(split_container));
- split_container->set_collapsed(true);
- MessageQueue::get_singleton()->flush();
- // The split offset is treated as 0 when collapsed.
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == 10);
- }
- SUBCASE("[SplitContainer] First child expanded") {
- int def_pos = split_container->get_size().x - sep.x;
- child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- split_container->set_split_offset(-10);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, def_pos - 10, sep.x), get_child_rects(split_container));
- split_container->set_collapsed(true);
- MessageQueue::get_singleton()->flush();
- // The split offset is treated as 0 when collapsed.
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == -10);
- }
- SUBCASE("[SplitContainer] Second child expanded") {
- int def_pos = 0;
- child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- split_container->set_split_offset(10);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, def_pos + 10, sep.x), get_child_rects(split_container));
- split_container->set_collapsed(true);
- MessageQueue::get_singleton()->flush();
- // The split offset is treated as 0 when collapsed.
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == 10);
- }
- SUBCASE("[SplitContainer] Both children expanded") {
- int def_pos = (split_container->get_size().y - sep.y) / 2;
- child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- split_container->set_split_offset(10);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, def_pos + 10, sep.x), get_child_rects(split_container));
- split_container->set_collapsed(true);
- MessageQueue::get_singleton()->flush();
- // The split offset is treated as 0 when collapsed.
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == 10);
- }
- memdelete(child_a);
- memdelete(child_b);
- memdelete(split_container);
- }
- TEST_CASE("[SceneTree][SplitContainer] Cursor shape") {
- DisplayServerMock *DS = (DisplayServerMock *)(DisplayServer::get_singleton());
- SplitContainer *split_container = memnew(SplitContainer);
- split_container->set_size(Size2(500, 500));
- SceneTree::get_singleton()->get_root()->add_child(split_container);
- Control *child_a = memnew(Control);
- split_container->add_child(child_a);
- Control *child_b = memnew(Control);
- split_container->add_child(child_b);
- MessageQueue::get_singleton()->flush();
- Point2 on_dragger = Point2(1, 1);
- Point2 not_on_dragger = Point2(50, 50);
- // Default cursor shape.
- SEND_GUI_MOUSE_MOTION_EVENT(not_on_dragger, MouseButtonMask::NONE, Key::NONE);
- CHECK(DS->get_cursor_shape() == DisplayServer::CURSOR_ARROW);
- // Horizontal cursor shape.
- SEND_GUI_MOUSE_MOTION_EVENT(on_dragger, MouseButtonMask::NONE, Key::NONE);
- CHECK(DS->get_cursor_shape() == DisplayServer::CURSOR_HSPLIT);
- // Vertical cursor shape.
- split_container->set_vertical(true);
- SEND_GUI_MOUSE_MOTION_EVENT(on_dragger, MouseButtonMask::NONE, Key::NONE);
- CHECK(DS->get_cursor_shape() == DisplayServer::CURSOR_VSPLIT);
- // Move off, default cursor shape.
- SEND_GUI_MOUSE_MOTION_EVENT(not_on_dragger, MouseButtonMask::NONE, Key::NONE);
- CHECK(DS->get_cursor_shape() == DisplayServer::CURSOR_ARROW);
- memdelete(child_a);
- memdelete(child_b);
- memdelete(split_container);
- }
- TEST_CASE("[SceneTree][SplitContainer] Two children") {
- SplitContainer *split_container = memnew(SplitContainer);
- split_container->set_size(Size2(500, 500));
- SceneTree::get_singleton()->get_root()->add_child(split_container);
- Control *child_a = memnew(Control);
- Control *child_b = memnew(Control);
- split_container->add_child(child_a);
- split_container->add_child(child_b);
- MessageQueue::get_singleton()->flush();
- const int sep_constant = split_container->get_theme_constant("separation");
- 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()));
- SUBCASE("[SplitContainer] Minimum size") {
- // Minimum size is the sum of both children's minimum sizes and the separator depending on the vertical axis.
- child_a->set_custom_minimum_size(Size2(100, 200));
- child_b->set_custom_minimum_size(Size2(100, 200));
- MessageQueue::get_singleton()->flush();
- Size2 min_size = split_container->get_minimum_size();
- CHECK(min_size.x == 200 + sep.x);
- CHECK(min_size.y == 200);
- split_container->set_vertical(true);
- MessageQueue::get_singleton()->flush();
- min_size = split_container->get_minimum_size();
- CHECK(min_size.x == 100);
- CHECK(min_size.y == 400 + sep.y);
- }
- SUBCASE("[SplitContainer] Default position") {
- SUBCASE("[SplitContainer] Vertical") {
- // Make sure clamping the split offset doesn't change it or the position.
- split_container->set_vertical(true);
- // No expand flags set.
- MessageQueue::get_singleton()->flush();
- int def_pos = 0;
- CHECK_RECTS(get_rects(split_container, def_pos, sep.y, false), get_child_rects(split_container));
- split_container->clamp_split_offset();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 0);
- CHECK_RECTS(get_rects(split_container, def_pos, sep.y, false), get_child_rects(split_container));
- // First expand flags set.
- child_a->set_v_size_flags(Control::SIZE_EXPAND_FILL);
- child_b->set_v_size_flags(Control::SIZE_FILL);
- MessageQueue::get_singleton()->flush();
- def_pos = split_container->get_size().y - sep.y;
- CHECK_RECTS(get_rects(split_container, def_pos, sep.y, false), get_child_rects(split_container));
- split_container->clamp_split_offset();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 0);
- CHECK_RECTS(get_rects(split_container, def_pos, sep.y, false), get_child_rects(split_container));
- // Second expand flags set.
- child_a->set_v_size_flags(Control::SIZE_FILL);
- child_b->set_v_size_flags(Control::SIZE_EXPAND_FILL);
- MessageQueue::get_singleton()->flush();
- def_pos = 0;
- CHECK_RECTS(get_rects(split_container, 0, sep.y, false), get_child_rects(split_container));
- split_container->clamp_split_offset();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 0);
- CHECK_RECTS(get_rects(split_container, def_pos, sep.y, false), get_child_rects(split_container));
- // Both expand flags set.
- child_a->set_v_size_flags(Control::SIZE_EXPAND_FILL);
- child_b->set_v_size_flags(Control::SIZE_EXPAND_FILL);
- MessageQueue::get_singleton()->flush();
- def_pos = (split_container->get_size().y - sep.y) / 2;
- CHECK_RECTS(get_rects(split_container, def_pos, sep.y, false), get_child_rects(split_container));
- split_container->clamp_split_offset();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 0);
- CHECK_RECTS(get_rects(split_container, def_pos, sep.y, false), get_child_rects(split_container));
- // Unequal stretch ratios.
- child_a->set_stretch_ratio(2.0);
- MessageQueue::get_singleton()->flush();
- def_pos = (split_container->get_size().y * 2 / 3) - sep.y / 2;
- CHECK_RECTS(get_rects(split_container, def_pos, sep.y, false), get_child_rects(split_container));
- split_container->clamp_split_offset();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 0);
- CHECK_RECTS(get_rects(split_container, def_pos, sep.y, false), get_child_rects(split_container));
- }
- SUBCASE("[SplitContainer] Right to left") {
- split_container->set_layout_direction(Control::LAYOUT_DIRECTION_RTL);
- split_container->set_position(Point2(0, 0));
- // No expand flags set.
- MessageQueue::get_singleton()->flush();
- int def_pos = 0;
- CHECK_RECTS(get_rects_rtl(split_container, def_pos, sep.y), get_child_rects(split_container));
- split_container->clamp_split_offset();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 0);
- CHECK_RECTS(get_rects_rtl(split_container, def_pos, sep.y), get_child_rects(split_container));
- // First expand flags set.
- child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- child_b->set_h_size_flags(Control::SIZE_FILL);
- MessageQueue::get_singleton()->flush();
- def_pos = split_container->get_size().y - sep.y;
- CHECK_RECTS(get_rects_rtl(split_container, def_pos, sep.y), get_child_rects(split_container));
- split_container->clamp_split_offset();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 0);
- CHECK_RECTS(get_rects_rtl(split_container, def_pos, sep.y), get_child_rects(split_container));
- // Second expand flags set.
- child_a->set_h_size_flags(Control::SIZE_FILL);
- child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- MessageQueue::get_singleton()->flush();
- def_pos = 0;
- CHECK_RECTS(get_rects_rtl(split_container, def_pos, sep.y), get_child_rects(split_container));
- split_container->clamp_split_offset();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 0);
- CHECK_RECTS(get_rects_rtl(split_container, def_pos, sep.y), get_child_rects(split_container));
- // Both expand flags set.
- child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- MessageQueue::get_singleton()->flush();
- def_pos = (split_container->get_size().y - sep.y) / 2;
- CHECK_RECTS(get_rects_rtl(split_container, def_pos, sep.y), get_child_rects(split_container));
- split_container->clamp_split_offset();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 0);
- CHECK_RECTS(get_rects_rtl(split_container, def_pos, sep.y), get_child_rects(split_container));
- // Unequal stretch ratios.
- child_a->set_stretch_ratio(2.0);
- MessageQueue::get_singleton()->flush();
- def_pos = (split_container->get_size().y * 2 / 3) - sep.y / 2;
- CHECK_RECTS(get_rects_rtl(split_container, def_pos, sep.y), get_child_rects(split_container));
- split_container->clamp_split_offset();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 0);
- CHECK_RECTS(get_rects_rtl(split_container, def_pos, sep.y), get_child_rects(split_container));
- }
- SUBCASE("[SplitContainer] No expand flags") {
- int def_pos = 0;
- CHECK(split_container->get_split_offset() == 0);
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- split_container->clamp_split_offset();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 0);
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- // Minimum sizes affect default position.
- // First child with minimum size.
- child_a->set_custom_minimum_size(Size2(400, 0));
- MessageQueue::get_singleton()->flush();
- def_pos = 400;
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- split_container->clamp_split_offset();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == def_pos);
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- // Second child with minimum size.
- child_a->set_custom_minimum_size(Size2(0, 0));
- child_b->set_custom_minimum_size(Size2(400, 0));
- MessageQueue::get_singleton()->flush();
- def_pos = split_container->get_size().x - 400 - sep.x;
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- split_container->clamp_split_offset();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == def_pos);
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- // Both children with minimum size.
- child_a->set_custom_minimum_size(Size2(200, 0));
- child_b->set_custom_minimum_size(Size2(288, 0));
- MessageQueue::get_singleton()->flush();
- def_pos = 200;
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- split_container->clamp_split_offset();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == def_pos);
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- }
- SUBCASE("[SplitContainer] First child expanded") {
- const int def_pos = split_container->get_size().x - sep.x;
- child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- split_container->clamp_split_offset();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 0);
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- // Minimum sizes affect default position.
- // First child with minimum size.
- child_a->set_custom_minimum_size(Size2(400, 0));
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- split_container->clamp_split_offset();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 0);
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- // Second child with minimum size.
- child_a->set_custom_minimum_size(Size2(0, 0));
- child_b->set_custom_minimum_size(Size2(400, 0));
- MessageQueue::get_singleton()->flush();
- int pos = split_container->get_size().x - 400 - sep.x;
- CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
- split_container->clamp_split_offset();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == pos - def_pos);
- CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
- // Both children with minimum size.
- child_a->set_custom_minimum_size(Size2(200, 0));
- child_b->set_custom_minimum_size(Size2(288, 0));
- MessageQueue::get_singleton()->flush();
- pos = 200;
- CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
- split_container->clamp_split_offset();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == pos - def_pos);
- CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
- }
- SUBCASE("[SplitContainer] Second child expanded") {
- int def_pos = 0;
- child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- split_container->clamp_split_offset();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 0);
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- // Minimum sizes affect default position.
- // First child with minimum size.
- child_a->set_custom_minimum_size(Size2(400, 0));
- MessageQueue::get_singleton()->flush();
- def_pos = 400;
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- split_container->clamp_split_offset();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == def_pos);
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- // Second child with minimum size.
- child_a->set_custom_minimum_size(Size2(0, 0));
- child_b->set_custom_minimum_size(Size2(400, 0));
- MessageQueue::get_singleton()->flush();
- def_pos = 500 - 400 - sep.x;
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- split_container->clamp_split_offset();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == def_pos);
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- // Both children with minimum size.
- child_a->set_custom_minimum_size(Size2(200, 0));
- child_b->set_custom_minimum_size(Size2(288, 0));
- MessageQueue::get_singleton()->flush();
- def_pos = 200;
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- split_container->clamp_split_offset();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == def_pos);
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- }
- SUBCASE("[SplitContainer] Both children expanded") {
- const int def_pos = (split_container->get_size().x - sep.x) / 2;
- child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- split_container->clamp_split_offset();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 0);
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- // Minimum sizes affect default position.
- // First child with minimum size.
- child_a->set_custom_minimum_size(Size2(400, 0));
- MessageQueue::get_singleton()->flush();
- int pos = 400;
- CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
- split_container->clamp_split_offset();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == pos - def_pos);
- CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
- // Second child with minimum size.
- child_a->set_custom_minimum_size(Size2(0, 0));
- child_b->set_custom_minimum_size(Size2(400, 0));
- MessageQueue::get_singleton()->flush();
- pos = split_container->get_size().x - 400 - sep.x;
- CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
- split_container->clamp_split_offset();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == pos - def_pos);
- CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
- // Both children with minimum size.
- child_a->set_custom_minimum_size(Size2(200, 0));
- child_b->set_custom_minimum_size(Size2(288, 0));
- MessageQueue::get_singleton()->flush();
- pos = 200;
- CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
- split_container->clamp_split_offset();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == pos - def_pos);
- CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
- }
- SUBCASE("[SplitContainer] Unequal stretch ratios") {
- const int def_pos = (split_container->get_size().x * 2 / 3) - sep.x / 2;
- child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- child_a->set_stretch_ratio(2.0);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- split_container->clamp_split_offset();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 0);
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- // Minimum sizes affect default position.
- // First child with minimum size.
- child_a->set_custom_minimum_size(Size2(400, 0));
- MessageQueue::get_singleton()->flush();
- int pos = 400;
- CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
- split_container->clamp_split_offset();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == pos - def_pos);
- CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
- // Second child with minimum size.
- child_a->set_custom_minimum_size(Size2(0, 0));
- child_b->set_custom_minimum_size(Size2(400, 0));
- MessageQueue::get_singleton()->flush();
- pos = split_container->get_size().x - 400 - sep.x;
- CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
- split_container->clamp_split_offset();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == pos - def_pos);
- CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
- // Both children with minimum size.
- child_a->set_custom_minimum_size(Size2(200, 0));
- child_b->set_custom_minimum_size(Size2(288, 0));
- MessageQueue::get_singleton()->flush();
- pos = 200;
- CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
- split_container->clamp_split_offset();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == pos - def_pos);
- CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
- }
- }
- SUBCASE("[SplitContainer] Set split offset") {
- SUBCASE("[SplitContainer] Right to left") {
- split_container->set_layout_direction(Control::LAYOUT_DIRECTION_RTL);
- split_container->set_position(Point2(0, 0));
- int def_pos = 0;
- // Positive.
- split_container->set_split_offset(10);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 10);
- CHECK_RECTS(get_rects_rtl(split_container, def_pos + 10, sep.y), get_child_rects(split_container));
- // Negative.
- split_container->set_split_offset(-10);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == -10);
- CHECK_RECTS(get_rects_rtl(split_container, def_pos, sep.y), get_child_rects(split_container));
- }
- SUBCASE("[SplitContainer] No expand flags") {
- int def_pos = 0;
- // Positive.
- split_container->set_split_offset(10);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 10);
- CHECK_RECTS(get_rects(split_container, def_pos + 10, sep.x), get_child_rects(split_container));
- // Negative.
- split_container->set_split_offset(-10);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == -10);
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- // Clamped.
- split_container->set_split_offset(1000);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 1000);
- CHECK_RECTS(get_rects(split_container, split_container->get_size().x - sep.x, sep.x), get_child_rects(split_container));
- }
- SUBCASE("[SplitContainer] First child expanded") {
- int def_pos = split_container->get_size().x - sep.x;
- child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- MessageQueue::get_singleton()->flush();
- // Positive.
- split_container->set_split_offset(10);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 10);
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- // Negative.
- split_container->set_split_offset(-10);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == -10);
- CHECK_RECTS(get_rects(split_container, def_pos - 10, sep.x), get_child_rects(split_container));
- // Clamped.
- split_container->set_split_offset(-1000);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == -1000);
- CHECK_RECTS(get_rects(split_container, 0, sep.x), get_child_rects(split_container));
- }
- SUBCASE("[SplitContainer] Second child expanded") {
- int def_pos = 0;
- child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- MessageQueue::get_singleton()->flush();
- // Positive.
- split_container->set_split_offset(10);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 10);
- CHECK_RECTS(get_rects(split_container, def_pos + 10, sep.x), get_child_rects(split_container));
- // Negative.
- split_container->set_split_offset(-10);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == -10);
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- // Clamped.
- split_container->set_split_offset(1000);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 1000);
- CHECK_RECTS(get_rects(split_container, split_container->get_size().x - sep.x, sep.x), get_child_rects(split_container));
- }
- SUBCASE("[SplitContainer] Both children expanded") {
- int def_pos = (split_container->get_size().x - sep.x) / 2;
- child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- MessageQueue::get_singleton()->flush();
- // Positive.
- split_container->set_split_offset(10);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 10);
- CHECK_RECTS(get_rects(split_container, def_pos + 10, sep.x), get_child_rects(split_container));
- // Negative.
- split_container->set_split_offset(-10);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == -10);
- CHECK_RECTS(get_rects(split_container, def_pos - 10, sep.x), get_child_rects(split_container));
- // Clamped positive.
- split_container->set_split_offset(1000);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 1000);
- CHECK_RECTS(get_rects(split_container, split_container->get_size().x - sep.x, sep.x), get_child_rects(split_container));
- // Clamped negative.
- split_container->set_split_offset(-1000);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == -1000);
- CHECK_RECTS(get_rects(split_container, 0, sep.x), get_child_rects(split_container));
- }
- SUBCASE("[SplitContainer] Unequal stretch ratios") {
- int def_pos = (split_container->get_size().x * 2 / 3) - sep.x / 2;
- child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- child_a->set_stretch_ratio(2.0);
- MessageQueue::get_singleton()->flush();
- // Positive.
- split_container->set_split_offset(10);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 10);
- CHECK_RECTS(get_rects(split_container, def_pos + 10, sep.x), get_child_rects(split_container));
- // Negative.
- split_container->set_split_offset(-10);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == -10);
- CHECK_RECTS(get_rects(split_container, def_pos - 10, sep.x), get_child_rects(split_container));
- // Clamped positive.
- split_container->set_split_offset(1000);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 1000);
- CHECK_RECTS(get_rects(split_container, split_container->get_size().x - sep.x, sep.x), get_child_rects(split_container));
- // Clamped negative.
- split_container->set_split_offset(-1000);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == -1000);
- CHECK_RECTS(get_rects(split_container, 0, sep.x), get_child_rects(split_container));
- }
- }
- SUBCASE("[SplitContainer] Keep split offset when changing minimum size") {
- SUBCASE("[SplitContainer] No expand flags") {
- int def_pos = 0;
- split_container->set_split_offset(100);
- child_a->set_custom_minimum_size(Size2(10, 0));
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 100);
- CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
- child_a->set_custom_minimum_size(Size2(50, 0));
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 100);
- CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
- }
- SUBCASE("[SplitContainer] First child expanded") {
- int def_pos = split_container->get_size().x - sep.x;
- child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- MessageQueue::get_singleton()->flush();
- split_container->set_split_offset(-100);
- child_b->set_custom_minimum_size(Size2(10, 0));
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == -100);
- CHECK_RECTS(get_rects(split_container, def_pos - 100, sep.x), get_child_rects(split_container));
- child_b->set_custom_minimum_size(Size2(50, 0));
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == -100);
- CHECK_RECTS(get_rects(split_container, def_pos - 100, sep.x), get_child_rects(split_container));
- }
- SUBCASE("[SplitContainer] Second child expanded") {
- int def_pos = 0;
- child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- MessageQueue::get_singleton()->flush();
- split_container->set_split_offset(100);
- child_a->set_custom_minimum_size(Size2(10, 0));
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 100);
- CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
- child_a->set_custom_minimum_size(Size2(50, 0));
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 100);
- CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
- }
- SUBCASE("[SplitContainer] Both children expanded") {
- int def_pos = (split_container->get_size().x - sep.x) / 2;
- child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- MessageQueue::get_singleton()->flush();
- split_container->set_split_offset(20);
- child_a->set_custom_minimum_size(Size2(10, 0));
- child_b->set_custom_minimum_size(Size2(10, 0));
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 20);
- CHECK_RECTS(get_rects(split_container, def_pos + 20, sep.x), get_child_rects(split_container));
- child_a->set_custom_minimum_size(Size2(50, 0));
- child_b->set_custom_minimum_size(Size2(50, 0));
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 20);
- CHECK_RECTS(get_rects(split_container, def_pos + 20, sep.x), get_child_rects(split_container));
- }
- }
- SUBCASE("[SplitContainer] Keep split offset when changing visibility") {
- SUBCASE("[SplitContainer] No expand flags") {
- int def_pos = 0;
- split_container->set_split_offset(100);
- child_a->hide();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 100);
- CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
- child_b->hide();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 100);
- child_a->show();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 100);
- CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
- child_b->show();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 100);
- CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
- }
- SUBCASE("[SplitContainer] First child expanded") {
- int def_pos = split_container->get_size().x - sep.x;
- child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- MessageQueue::get_singleton()->flush();
- split_container->set_split_offset(-100);
- child_a->hide();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == -100);
- CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
- child_b->hide();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == -100);
- child_a->show();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == -100);
- CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
- child_b->show();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == -100);
- CHECK_RECTS(get_rects(split_container, def_pos - 100, sep.x), get_child_rects(split_container));
- }
- SUBCASE("[SplitContainer] Second child expanded") {
- int def_pos = 0;
- child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- MessageQueue::get_singleton()->flush();
- split_container->set_split_offset(100);
- child_a->hide();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 100);
- CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
- child_b->hide();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 100);
- child_a->show();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 100);
- CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
- child_b->show();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 100);
- CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
- }
- SUBCASE("[SplitContainer] Both children expanded") {
- int def_pos = (split_container->get_size().x - sep.x) / 2;
- child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- MessageQueue::get_singleton()->flush();
- split_container->set_split_offset(20);
- child_a->hide();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 20);
- CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
- child_b->hide();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 20);
- child_a->show();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 20);
- CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
- child_b->show();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 20);
- CHECK_RECTS(get_rects(split_container, def_pos + 20, sep.x), get_child_rects(split_container));
- }
- }
- SUBCASE("[SplitContainer] Keep split offset when removing children") {
- SUBCASE("[SplitContainer] No expand flags") {
- int def_pos = 0;
- split_container->set_split_offset(100);
- split_container->remove_child(child_a);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 100);
- CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
- split_container->remove_child(child_b);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 100);
- split_container->add_child(child_a);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 100);
- CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
- split_container->add_child(child_b);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 100);
- CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
- }
- SUBCASE("[SplitContainer] First child expanded") {
- int def_pos = split_container->get_size().x - sep.x;
- child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- MessageQueue::get_singleton()->flush();
- split_container->set_split_offset(-100);
- split_container->remove_child(child_a);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == -100);
- CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
- split_container->remove_child(child_b);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == -100);
- split_container->add_child(child_a);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == -100);
- CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
- split_container->add_child(child_b);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == -100);
- CHECK_RECTS(get_rects(split_container, def_pos - 100, sep.x), get_child_rects(split_container));
- }
- SUBCASE("[SplitContainer] Second child expanded") {
- int def_pos = 0;
- child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- MessageQueue::get_singleton()->flush();
- split_container->set_split_offset(100);
- split_container->remove_child(child_a);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 100);
- CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
- split_container->remove_child(child_b);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 100);
- split_container->add_child(child_a);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 100);
- CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
- split_container->add_child(child_b);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 100);
- CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
- }
- SUBCASE("[SplitContainer] Both children expanded") {
- int def_pos = (split_container->get_size().x - sep.x) / 2;
- child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- MessageQueue::get_singleton()->flush();
- split_container->set_split_offset(20);
- split_container->remove_child(child_a);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 20);
- CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
- split_container->remove_child(child_b);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 20);
- split_container->add_child(child_a);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 20);
- CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
- split_container->add_child(child_b);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 20);
- CHECK_RECTS(get_rects(split_container, def_pos + 20, sep.x), get_child_rects(split_container));
- }
- }
- SUBCASE("[SplitContainer] Keep split offset when changing expand flags") {
- int def_pos = 0;
- split_container->set_split_offset(20);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 20);
- CHECK_RECTS(get_rects(split_container, def_pos + 20, sep.x), get_child_rects(split_container));
- child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- def_pos = split_container->get_size().x - sep.x;
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 20);
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- child_a->set_h_size_flags(Control::SIZE_FILL);
- child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- def_pos = 0;
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 20);
- CHECK_RECTS(get_rects(split_container, def_pos + 20, sep.x), get_child_rects(split_container));
- child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- def_pos = (split_container->get_size().x - sep.x) / 2;
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 20);
- CHECK_RECTS(get_rects(split_container, def_pos + 20, sep.x), get_child_rects(split_container));
- child_a->set_h_size_flags(Control::SIZE_FILL);
- child_b->set_h_size_flags(Control::SIZE_FILL);
- def_pos = 0;
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 20);
- CHECK_RECTS(get_rects(split_container, def_pos + 20, sep.x), get_child_rects(split_container));
- }
- SUBCASE("[SplitContainer] Keep split offset when moving children") {
- int def_pos = 0;
- split_container->set_split_offset(100);
- split_container->move_child(child_a, 1);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offset() == 100);
- CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
- }
- SUBCASE("[SplitContainer] Resize split container") {
- SUBCASE("[SplitContainer] No expand flags") {
- int def_pos = 0;
- // Increase the size.
- split_container->set_size(Size2(600, 500));
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- // Decrease the size.
- split_container->set_size(Size2(400, 500));
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- // Change size with a split offset.
- split_container->set_split_offset(100);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
- split_container->set_size(Size2(500, 500));
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == 100);
- // Change size so that the first child changes size.
- split_container->set_size(Size2(80, 500));
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, 80 - sep.x, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == 100);
- // Increase size again.
- split_container->set_size(Size2(500, 500));
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == 100);
- }
- SUBCASE("[SplitContainer] First child expanded") {
- int def_pos = split_container->get_size().x - sep.x;
- child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- MessageQueue::get_singleton()->flush();
- // Increase the size.
- split_container->set_size(Size2(600, 500));
- def_pos = split_container->get_size().x - sep.x;
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- // Decrease the size.
- split_container->set_size(Size2(400, 500));
- def_pos = split_container->get_size().x - sep.x;
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- // Change size with a split offset.
- split_container->set_split_offset(-100);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, def_pos - 100, sep.x), get_child_rects(split_container));
- split_container->set_size(Size2(500, 500));
- def_pos = split_container->get_size().x - sep.x;
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, def_pos - 100, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == -100);
- // Change size so that the second child changes size.
- split_container->set_size(Size2(80, 500));
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, 0, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == -100);
- // Increase size again.
- split_container->set_size(Size2(500, 500));
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, def_pos - 100, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == -100);
- }
- SUBCASE("[SplitContainer] Second child expanded") {
- int def_pos = 0;
- child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- MessageQueue::get_singleton()->flush();
- // Increase the size.
- split_container->set_size(Size2(600, 500));
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- // Decrease the size.
- split_container->set_size(Size2(400, 500));
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- // Change size with a split offset.
- split_container->set_split_offset(100);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
- split_container->set_size(Size2(500, 500));
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == 100);
- // Change size so that the first child changes size.
- split_container->set_size(Size2(80, 500));
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, 80 - sep.x, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == 100);
- // Increase size again.
- split_container->set_size(Size2(500, 500));
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == 100);
- }
- SUBCASE("[SplitContainer] Both children expanded") {
- int def_pos = (split_container->get_size().x - sep.x) / 2;
- child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- MessageQueue::get_singleton()->flush();
- // Increase the size.
- split_container->set_size(Size2(600, 500));
- def_pos = (split_container->get_size().x - sep.x) / 2;
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- // Decrease the size.
- split_container->set_size(Size2(400, 500));
- def_pos = (split_container->get_size().x - sep.x) / 2;
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- // Change size with a split offset.
- split_container->set_split_offset(100);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
- split_container->set_size(Size2(500, 500));
- def_pos = (split_container->get_size().x - sep.x) / 2;
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == 100);
- // Change size so that the second child is minimized.
- split_container->set_size(Size2(80, 500));
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, 80 - sep.x, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == 100);
- // Increase size again.
- split_container->set_size(Size2(500, 500));
- def_pos = (split_container->get_size().x - sep.x) / 2;
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == 100);
- }
- SUBCASE("[SplitContainer] Unequal stretch ratios") {
- int def_pos = (split_container->get_size().x * 2 / 3) - sep.x / 2;
- child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- child_a->set_stretch_ratio(2.0);
- MessageQueue::get_singleton()->flush();
- // Increase the size.
- split_container->set_size(Size2(600, 500));
- def_pos = (split_container->get_size().x * 2 / 3) - sep.x / 2;
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- // Decrease the size.
- split_container->set_size(Size2(400, 500));
- def_pos = (split_container->get_size().x * 2 / 3) - sep.x / 2;
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
- // Change size with a split offset.
- split_container->set_split_offset(100);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
- split_container->set_size(Size2(500, 500));
- def_pos = (split_container->get_size().x * 2 / 3) - sep.x / 2;
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == 100);
- // Change size so that the second child is minimized.
- split_container->set_size(Size2(80, 500));
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, 80 - sep.x, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == 100);
- // Increase size again.
- split_container->set_size(Size2(500, 500));
- def_pos = (split_container->get_size().x * 2 / 3) - sep.x / 2;
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == 100);
- }
- }
- SUBCASE("[SplitContainer] Drag") {
- SUBCASE("[SplitContainer] Vertical, no expand flags") {
- SIGNAL_WATCH(split_container, "dragged");
- Array signal_args = { { 0 } };
- split_container->set_vertical(true);
- Point2 mouse_offset = Point2(1, 1);
- int dragger_pos = 0;
- int split_dragger_ofs = 0;
- // Grab the dragger.
- SEND_GUI_MOUSE_BUTTON_EVENT(mouse_offset + Point2(0, dragger_pos), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, dragger_pos, sep.y, false), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
- SIGNAL_CHECK_FALSE("dragged");
- // Move the dragger.
- dragger_pos = 10;
- SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(0, dragger_pos), MouseButtonMask::LEFT, Key::NONE);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, dragger_pos, sep.y, false), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
- // It is clamped.
- split_container->clamp_split_offset();
- CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
- ((Array)signal_args[0])[0] = split_container->get_split_offset();
- SIGNAL_CHECK("dragged", signal_args);
- // Move down.
- dragger_pos = 400;
- SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(0, dragger_pos), MouseButtonMask::LEFT, Key::NONE);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, dragger_pos, sep.y, false), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
- ((Array)signal_args[0])[0] = split_container->get_split_offset();
- SIGNAL_CHECK("dragged", signal_args);
- // Moves even when mouse is outside.
- dragger_pos = split_container->get_size().y - sep.y;
- SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(0, 1000), MouseButtonMask::LEFT, Key::NONE);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, dragger_pos, sep.y, false), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
- ((Array)signal_args[0])[0] = split_container->get_split_offset();
- SIGNAL_CHECK("dragged", signal_args);
- // Move up.
- dragger_pos = 100;
- SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(0, dragger_pos), MouseButtonMask::LEFT, Key::NONE);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, dragger_pos, sep.y, false), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
- ((Array)signal_args[0])[0] = split_container->get_split_offset();
- SIGNAL_CHECK("dragged", signal_args);
- // Release.
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(mouse_offset + Point2(0, dragger_pos), MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, dragger_pos, sep.y, false), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
- SIGNAL_CHECK_FALSE("dragged");
- // No longer moves with the mouse.
- SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(0, 200), MouseButtonMask::NONE, Key::NONE);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, dragger_pos, sep.y, false), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
- SIGNAL_CHECK_FALSE("dragged");
- SIGNAL_UNWATCH(split_container, "dragged");
- }
- SUBCASE("[SplitContainer] No expand flags") {
- Point2 mouse_offset = Point2(1, 1);
- int dragger_pos = 0;
- int split_dragger_ofs = 0;
- // Grab the dragger.
- SEND_GUI_MOUSE_BUTTON_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
- // Move the dragger.
- dragger_pos = 10;
- SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
- // It is clamped.
- split_container->clamp_split_offset();
- CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
- // Continue moving.
- dragger_pos = 400;
- SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
- // Moves even when mouse is outside.
- dragger_pos = split_container->get_size().x - sep.x;
- SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(1000, 0), MouseButtonMask::LEFT, Key::NONE);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
- // Move back in.
- dragger_pos = 100;
- SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
- // Release.
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
- // No longer moves with the mouse.
- SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(200, 0), MouseButtonMask::NONE, Key::NONE);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
- }
- SUBCASE("[SplitContainer] First child expanded") {
- child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- MessageQueue::get_singleton()->flush();
- Point2 mouse_offset = Point2(1, 1);
- int dragger_pos = split_container->get_size().x - sep.x;
- int split_dragger_ofs = -dragger_pos;
- // Grab the dragger.
- SEND_GUI_MOUSE_BUTTON_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
- // Move the dragger.
- dragger_pos -= 10;
- SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
- // It is clamped.
- split_container->clamp_split_offset();
- CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
- // Continue moving.
- dragger_pos = 400;
- SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
- // Moves even when mouse is outside.
- dragger_pos = split_container->get_size().x - sep.x;
- SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(1000, 0), MouseButtonMask::LEFT, Key::NONE);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
- // Move back in.
- dragger_pos = 100;
- SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
- // Release.
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
- // No longer moves with the mouse.
- SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(200, 0), MouseButtonMask::NONE, Key::NONE);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
- }
- SUBCASE("[SplitContainer] Second child expanded") {
- child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- MessageQueue::get_singleton()->flush();
- Point2 mouse_offset = Point2(1, 1);
- int dragger_pos = 0;
- int split_dragger_ofs = 0;
- // Grab the dragger.
- SEND_GUI_MOUSE_BUTTON_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
- // Move the dragger.
- dragger_pos = 10;
- SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
- // It is clamped.
- split_container->clamp_split_offset();
- CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
- // Continue moving.
- dragger_pos = 400;
- SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
- // Moves even when mouse is outside.
- dragger_pos = split_container->get_size().x - sep.x;
- SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(1000, 0), MouseButtonMask::LEFT, Key::NONE);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
- // Move back in.
- dragger_pos = 100;
- SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
- // Release.
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
- // No longer moves with the mouse.
- SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(200, 0), MouseButtonMask::NONE, Key::NONE);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
- }
- SUBCASE("[SplitContainer] Both children expanded") {
- child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- MessageQueue::get_singleton()->flush();
- Point2 mouse_offset = Point2(1, 1);
- int dragger_pos = (split_container->get_size().x - sep.x) / 2;
- int split_dragger_ofs = -dragger_pos;
- // Grab the dragger.
- SEND_GUI_MOUSE_BUTTON_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
- // Move the dragger.
- dragger_pos += 10;
- SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
- // It is clamped.
- split_container->clamp_split_offset();
- CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
- // Continue moving.
- dragger_pos = 400;
- SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
- // Moves even when mouse is outside.
- dragger_pos = split_container->get_size().x - sep.x;
- SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(1000, 0), MouseButtonMask::LEFT, Key::NONE);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
- // Move back in.
- dragger_pos = 100;
- SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
- // Release.
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
- // No longer moves with the mouse.
- SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(200, 0), MouseButtonMask::NONE, Key::NONE);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
- }
- }
- memdelete(child_b);
- memdelete(child_a);
- memdelete(split_container);
- }
- TEST_CASE("[SceneTree][SplitContainer] More children") {
- SplitContainer *split_container = memnew(SplitContainer);
- split_container->set_size(Size2(500, 500));
- SceneTree::get_singleton()->get_root()->add_child(split_container);
- Control *child_a = memnew(Control);
- Control *child_b = memnew(Control);
- Control *child_c = memnew(Control);
- split_container->add_child(child_a);
- split_container->add_child(child_b);
- split_container->add_child(child_c);
- Size2i min_size = Size2i(10, 10);
- child_a->set_custom_minimum_size(min_size);
- child_b->set_custom_minimum_size(min_size);
- child_c->set_custom_minimum_size(min_size);
- MessageQueue::get_singleton()->flush();
- const int sep_constant = split_container->get_theme_constant("separation");
- 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()));
- SUBCASE("[SplitContainer] Duplicate") {
- // Make sure dynamically added internal draggers duplicate properly.
- SplitContainer *duplicate = (SplitContainer *)(Node *)split_container->duplicate();
- MessageQueue::get_singleton()->flush();
- CHECK(duplicate->get_child_count(false) == split_container->get_child_count(false));
- CHECK(duplicate->get_child_count(true) == split_container->get_child_count(true));
- memdelete(duplicate);
- }
- SUBCASE("[SplitContainer] Default position") {
- CHECK(split_container->get_split_offsets() == Vector<int>({ 0, 0 }));
- set_size_flags(split_container, { -1, -1, -1 }); // None expanded.
- Vector<int> def_pos = { min_size.x, min_size.x * 2 + sep.x };
- CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
- split_container->clamp_split_offset();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == Vector<int>({ min_size.x, min_size.x * 2 + sep.x }));
- CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
- split_container->set_split_offsets({ 0, 0 });
- set_size_flags(split_container, { 1, -1, -1 }); // First expanded.
- 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 };
- CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
- split_container->clamp_split_offset();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == Vector<int>({ -min_size.x * 2 - sep.x, -min_size.x }));
- CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
- split_container->set_split_offsets({ 0, 0 });
- set_size_flags(split_container, { -1, 1, -1 }); // Second expanded.
- def_pos = { min_size.x, (int)split_container->get_size().x - min_size.x - sep.x };
- CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
- split_container->clamp_split_offset();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == Vector<int>({ min_size.x, -min_size.x }));
- CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
- split_container->set_split_offsets({ 0, 0 });
- set_size_flags(split_container, { -1, -1, 1 }); // Third expanded.
- def_pos = { min_size.x, min_size.x * 2 + sep.x };
- CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
- split_container->clamp_split_offset();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == Vector<int>({ min_size.x, min_size.x * 2 + sep.x }));
- CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
- split_container->set_split_offsets({ 0, 0 });
- set_size_flags(split_container, { 1, 1, -1 }); // First and second expanded.
- int child_2_expanded_size = ((int)split_container->get_size().x - min_size.x) / 2 - sep.x;
- def_pos = { child_2_expanded_size, (int)split_container->get_size().x - min_size.x - sep.x };
- CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
- split_container->clamp_split_offset();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == Vector<int>({ 0, -min_size.x }));
- CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
- split_container->set_split_offsets({ 0, 0 });
- set_size_flags(split_container, { 1, -1, 1 }); // First and third expanded.
- def_pos = { child_2_expanded_size, child_2_expanded_size + min_size.x + sep.x };
- CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
- split_container->clamp_split_offset();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == Vector<int>({ 0, 0 }));
- CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
- split_container->set_split_offsets({ 0, 0 });
- set_size_flags(split_container, { -1, 1, 1 }); // Second and third expanded.
- def_pos = { min_size.x, min_size.x + child_2_expanded_size + sep.x };
- CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
- split_container->clamp_split_offset();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == Vector<int>({ min_size.x, 0 }));
- CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
- split_container->set_split_offsets({ 0, 0 });
- set_size_flags(split_container, { 1, 1, 1 }); // All expanded.
- int child_3_expanded_size = (split_container->get_size().x - sep.x * 2) / 3;
- // Add 1 due to pixel error accumulation.
- def_pos = { child_3_expanded_size, child_3_expanded_size * 2 + sep.x + 1 };
- CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
- split_container->clamp_split_offset();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == Vector<int>({ 0, 0 }));
- CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
- split_container->set_split_offsets({ 0, 0 });
- set_size_flags(split_container, { 1, 2, 3 }); // All expanded, different ratios.
- int child_6_expanded_size = (split_container->get_size().x - sep.x * 2) / 6;
- def_pos = { child_6_expanded_size, child_6_expanded_size * 3 + sep.x + 1 };
- CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
- split_container->clamp_split_offset();
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == Vector<int>({ 0, 0 }));
- CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
- split_container->set_split_offsets({ 0, 0 });
- }
- SUBCASE("[SplitContainer] Set split offset") {
- const int expanded_single_size = (int)split_container->get_size().x - min_size.x * 2 - sep.x * 2;
- SUBCASE("[SplitContainer] No expand flags") {
- set_size_flags(split_container, { -1, -1, -1 }); // None expanded.
- // First is positive.
- split_container->set_split_offsets({ 50, 0 });
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == Vector<int>{ 50, 0 });
- CHECK_RECTS(get_rects_multi(split_container, { 50, 50 + min_size.x + sep.x }, sep.x), get_child_rects(split_container));
- // Second is positive.
- split_container->set_split_offsets({ 0, 50 });
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == Vector<int>{ 0, 50 });
- CHECK_RECTS(get_rects_multi(split_container, { min_size.x, 50 }, sep.x), get_child_rects(split_container));
- // Both are positive and equal, the first will override since they both start at 0.
- split_container->set_split_offsets({ 50, 50 });
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == Vector<int>{ 50, 50 });
- CHECK_RECTS(get_rects_multi(split_container, { 50, 50 + min_size.x + sep.x }, sep.x), get_child_rects(split_container));
- // Both are negative and clamped.
- split_container->set_split_offsets({ -50, -50 });
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == Vector<int>{ -50, -50 });
- CHECK_RECTS(get_rects_multi(split_container, { min_size.x, min_size.x * 2 + sep.x }, sep.x), get_child_rects(split_container));
- // First positive, second negative. First takes priority.
- split_container->set_split_offsets({ 50, -50 });
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == Vector<int>{ 50, -50 });
- CHECK_RECTS(get_rects_multi(split_container, { 50, 50 + min_size.x + sep.x }, sep.x), get_child_rects(split_container));
- // First is clamped and pushes second to the end.
- split_container->set_split_offsets({ 1000, 0 });
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == Vector<int>{ 1000, 0 });
- 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));
- // Second is clamped.
- split_container->set_split_offsets({ 0, 1000 });
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == Vector<int>{ 0, 1000 });
- 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));
- // Both are clamped positively, first one takes priority.
- split_container->set_split_offsets({ 1000, 1000 });
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == Vector<int>{ 1000, 1000 });
- 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));
- }
- SUBCASE("[SplitContainer] First child expanded") {
- set_size_flags(split_container, { 1, -1, -1 }); // First expanded.
- // First is positive and clamped.
- split_container->set_split_offsets({ 50, 0 });
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == Vector<int>{ 50, 0 });
- 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));
- // Second is positive and clamped.
- split_container->set_split_offsets({ 0, 50 });
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == Vector<int>{ 0, 50 });
- 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));
- // First is negative and moves left.
- split_container->set_split_offsets({ -50, 0 });
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == Vector<int>{ -50, 0 });
- 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));
- // Second is negative, but first has priority so it doesn't move.
- split_container->set_split_offsets({ 0, -50 });
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == Vector<int>{ 0, -50 });
- 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));
- // Both are negative and equal, they move left but the second doesn't move as much as wanted.
- split_container->set_split_offsets({ -50, -50 });
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == Vector<int>{ -50, -50 });
- 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));
- // Both are negative with space and move left.
- split_container->set_split_offsets({ -100, -50 });
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == Vector<int>{ -100, -50 });
- 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));
- // First moves all the way left.
- split_container->set_split_offsets({ -1000, 0 });
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == Vector<int>{ -1000, 0 });
- 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));
- // Second cannot move all the way left since first takes priority.
- split_container->set_split_offsets({ 0, -1000 });
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == Vector<int>{ 0, -1000 });
- 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));
- // First and second move all the way left.
- split_container->set_split_offsets({ -1000, -1000 });
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == Vector<int>{ -1000, -1000 });
- CHECK_RECTS(get_rects_multi(split_container, { min_size.x, min_size.x * 2 + sep.x }, sep.x), get_child_rects(split_container));
- }
- SUBCASE("[SplitContainer] All children expanded") {
- set_size_flags(split_container, { 1, 1, 1 }); // All expanded.
- const int child_3_expanded_size = (split_container->get_size().x - sep.x * 2) / 3;
- // First is moved positive, does not affect second.
- split_container->set_split_offsets({ 50, 0 });
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == Vector<int>{ 50, 0 });
- 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));
- // First is moved negative, does not affect second.
- split_container->set_split_offsets({ -50, 0 });
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == Vector<int>{ -50, 0 });
- 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));
- // Second is moved positive, does not affect first.
- split_container->set_split_offsets({ 0, 50 });
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == Vector<int>{ 0, 50 });
- 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));
- // Second is moved negative, does not affect first.
- split_container->set_split_offsets({ 0, -50 });
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == Vector<int>{ 0, -50 });
- 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));
- // First is moved positive enough to affect second.
- split_container->set_split_offsets({ 200, 0 });
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == Vector<int>{ 200, 0 });
- 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));
- // Second is moved enough to pass the first, but the first has priority.
- split_container->set_split_offsets({ 0, -200 });
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == Vector<int>{ 0, -200 });
- 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));
- }
- }
- SUBCASE("[SplitContainer] Resize") {
- SUBCASE("[SplitContainer] No expand flags") {
- Vector<int> def_pos = { min_size.x, min_size.x * 2 + sep.x };
- // Increase the size.
- split_container->set_size(Size2(600, 500));
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
- // Decrease the size.
- split_container->set_size(Size2(400, 500));
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
- // Change size with a split offset.
- split_container->set_split_offsets({ 50, 100 });
- split_container->set_size(Size2(500, 500));
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects_multi(split_container, { 50, 100 }, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offsets() == Vector<int>{ 50, 100 });
- // Change size so that the second child gets clamped and changes size.
- split_container->set_size(Size2(100, 500));
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects_multi(split_container, { 50, 100 - sep.x - min_size.x }, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offsets() == Vector<int>{ 50, 100 });
- // Change size so that the first child changes size.
- split_container->set_size(Size2(60, 500));
- MessageQueue::get_singleton()->flush();
- 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));
- CHECK(split_container->get_split_offsets() == Vector<int>{ 50, 100 });
- // Increase size again.
- split_container->set_size(Size2(500, 500));
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects_multi(split_container, { 50, 100 }, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offsets() == Vector<int>{ 50, 100 });
- }
- SUBCASE("[SplitContainer] First child expanded") {
- set_size_flags(split_container, { 1, -1, -1 });
- Vector<int> def_pos = { (int)split_container->get_size().x - sep.x * 2 - min_size.x, (int)split_container->get_size().x - sep.x };
- // Increase the size.
- split_container->set_size(Size2(600, 500));
- 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 };
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
- // Decrease the size.
- split_container->set_size(Size2(400, 500));
- 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 };
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
- // Change size with a split offset.
- split_container->set_split_offsets({ -100, -50 });
- split_container->set_size(Size2(500, 500));
- MessageQueue::get_singleton()->flush();
- 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));
- CHECK(split_container->get_split_offsets() == Vector<int>{ -100, -50 });
- // Change size so that the first child gets clamped and changes size.
- split_container->set_size(Size2(100, 500));
- MessageQueue::get_singleton()->flush();
- 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));
- CHECK(split_container->get_split_offsets() == Vector<int>{ -100, -50 });
- // Change size so that the second child changes size.
- split_container->set_size(Size2(50, 500));
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects_multi(split_container, { min_size.x, min_size.x * 2 + sep.x }, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offsets() == Vector<int>{ -100, -50 });
- // Increase size again.
- split_container->set_size(Size2(500, 500));
- MessageQueue::get_singleton()->flush();
- 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));
- CHECK(split_container->get_split_offsets() == Vector<int>{ -100, -50 });
- }
- SUBCASE("[SplitContainer] All children expanded") {
- set_size_flags(split_container, { 1, 1, 1 });
- // Increase the size.
- split_container->set_size(Size2(600, 500));
- MessageQueue::get_singleton()->flush();
- int child_3_expanded_size = (split_container->get_size().x - sep.x * 2) / 3;
- Vector<int> def_pos = { child_3_expanded_size, child_3_expanded_size * 2 + sep.x };
- CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
- // Decrease the size.
- split_container->set_size(Size2(400, 500));
- MessageQueue::get_singleton()->flush();
- child_3_expanded_size = (split_container->get_size().x - sep.x * 2) / 3;
- def_pos = { child_3_expanded_size, child_3_expanded_size * 2 + sep.x };
- CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
- // Change size with a split offset.
- split_container->set_split_offsets({ -50, 50 });
- split_container->set_size(Size2(500, 500));
- MessageQueue::get_singleton()->flush();
- child_3_expanded_size = (split_container->get_size().x - sep.x * 2) / 3;
- def_pos = { child_3_expanded_size, child_3_expanded_size * 2 + sep.x + 1 };
- CHECK_RECTS(get_rects_multi(split_container, { def_pos[0] - 50, def_pos[1] + 50 }, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offsets() == Vector<int>{ -50, 50 });
- // Change size so that the children get clamped and change sizes.
- split_container->set_size(Size2(100, 500));
- MessageQueue::get_singleton()->flush();
- 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));
- CHECK(split_container->get_split_offsets() == Vector<int>{ -50, 50 });
- // Increase size again.
- split_container->set_size(Size2(500, 500));
- MessageQueue::get_singleton()->flush();
- child_3_expanded_size = (split_container->get_size().x - sep.x * 2) / 3;
- def_pos = { child_3_expanded_size, child_3_expanded_size * 2 + sep.x + 1 };
- CHECK_RECTS(get_rects_multi(split_container, { def_pos[0] - 50, def_pos[1] + 50 }, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offsets() == Vector<int>{ -50, 50 });
- }
- }
- SUBCASE("[SplitContainer] Visibility changes") {
- set_size_flags(split_container, { -1, -1, -1 }); // None expanded.
- split_container->set_split_offsets({ 50, 122 });
- MessageQueue::get_singleton()->flush();
- Vector<int> def_pos = { 50, 122 };
- CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
- // Hide and show the first child.
- child_a->set_visible(false);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == Vector<int>({ 60 }));
- CHECK_RECTS(get_rects_multi(split_container, { 60 }, sep.x), get_child_rects(split_container));
- child_a->set_visible(true);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == def_pos);
- CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
- // Hide and show the second child.
- child_b->set_visible(false);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == Vector<int>({ 50 }));
- CHECK_RECTS(get_rects_multi(split_container, { 50 }, sep.x), get_child_rects(split_container));
- child_b->set_visible(true);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == def_pos);
- CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
- // Hide and show the last child.
- child_c->set_visible(false);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == Vector<int>({ 50 }));
- CHECK_RECTS(get_rects_multi(split_container, { 50 }, sep.x), get_child_rects(split_container));
- child_c->set_visible(true);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == def_pos);
- CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
- set_size_flags(split_container, { 1, 1, 1 }); // All expanded.
- split_container->set_split_offsets({ 50, 60 });
- MessageQueue::get_singleton()->flush();
- int child_3_expanded_size = (split_container->get_size().x - sep.x * 2) / 3;
- def_pos = { child_3_expanded_size + 50, child_3_expanded_size * 2 + sep.x + 1 + 60 };
- CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
- // Hide and show the first child.
- int child_2_expanded_size = (split_container->get_size().x - sep.x) / 2;
- child_a->set_visible(false);
- MessageQueue::get_singleton()->flush();
- int half_point = (split_container->get_size().x - def_pos[0]) / 2 - sep.x;
- int so = child_3_expanded_size + 11 - half_point; // 11 is from 60 - 50 + 1 to get the second child's size.
- CHECK_RECTS(get_rects_multi(split_container, { child_2_expanded_size + so }, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offsets() == Vector<int>({ so }));
- child_a->set_visible(true);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offsets() == Vector<int>({ 50, 60 }));
- // Hide and show the second child.
- child_b->set_visible(false);
- MessageQueue::get_singleton()->flush();
- half_point = (split_container->get_size().x - (def_pos[1] - def_pos[0] - sep.x)) / 2 - sep.x + 1;
- so = def_pos[0] - half_point;
- CHECK_RECTS(get_rects_multi(split_container, { child_2_expanded_size + so }, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offsets() == Vector<int>({ so }));
- child_b->set_visible(true);
- MessageQueue::get_singleton()->flush();
- // There is lost precision due to SplitContainer using ints, so this is off by one.
- CHECK_RECTS(get_rects_multi(split_container, { def_pos[0] - 1, def_pos[1] - 1 }, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offsets() == Vector<int>({ 49, 59 }));
- // Hide and show the last child.
- split_container->set_split_offsets({ 50, 60 });
- child_c->set_visible(false);
- MessageQueue::get_singleton()->flush();
- half_point = (def_pos[1] - sep.x) / 2 + 1;
- so = def_pos[0] - half_point;
- CHECK_RECTS(get_rects_multi(split_container, { child_2_expanded_size + so }, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offsets() == Vector<int>({ so }));
- child_c->set_visible(true);
- MessageQueue::get_singleton()->flush();
- CHECK_RECTS(get_rects_multi(split_container, { def_pos[0] - 1, def_pos[1] - 1 }, sep.x), get_child_rects(split_container));
- CHECK(split_container->get_split_offsets() == Vector<int>({ 49, 59 }));
- }
- SUBCASE("[SplitContainer] Adjust split offset when moving children") {
- split_container->set_split_offsets({ 50, 80 });
- split_container->move_child(child_a, 1);
- Vector<int> pos = { 30 - sep.x, 80 }; // 30 = 80 - 50.
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == pos);
- CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
- // Move last child to first.
- split_container->set_split_offsets({ 50, 80 });
- split_container->move_child(child_c, 0);
- pos = { (int)split_container->get_size().x - 80 - sep.x, (int)split_container->get_size().x - 30 };
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == pos);
- CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
- // Move it back.
- split_container->move_child(child_c, 2);
- pos = { 50, 80 };
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == pos);
- CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
- }
- SUBCASE("[SplitContainer] Showing child with not enough space shrinks the largest child first") {
- set_size_flags(split_container, { -1, -1, -1 }); // None expanded.
- // Second child is largest.
- child_a->set_visible(false);
- Vector<int> pos = { 360 };
- split_container->set_split_offsets(pos);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == pos);
- CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
- child_a->set_size(Vector2(100, 100));
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == pos);
- CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
- child_a->set_visible(true);
- pos = { 100, 360 };
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == pos);
- CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
- // Last child is largest.
- child_a->set_visible(false);
- pos = { 60 };
- split_container->set_split_offsets(pos);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == pos);
- CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
- child_a->set_size(Vector2(100, 100));
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == pos);
- CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
- child_a->set_visible(true);
- pos = { 100, 160 + sep.x };
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == pos);
- CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
- // Both visible children are the same size.
- child_a->set_visible(false);
- pos = { (int)split_container->get_size().x / 2 - sep.x / 2 };
- split_container->set_split_offsets(pos);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == pos);
- CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
- CHECK(child_b->get_size().x == child_c->get_size().x);
- child_a->set_size(Vector2(100, 100));
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == pos);
- CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
- child_a->set_visible(true);
- pos = { 100, (int)split_container->get_size().x / 2 + 50 };
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == pos);
- CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
- CHECK(child_b->get_size().x == child_c->get_size().x);
- // Second child is slightly larger than the last child.
- child_a->set_visible(false);
- pos = { (int)split_container->get_size().x / 2 - sep.x / 2 + 20 };
- split_container->set_split_offsets(pos);
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == pos);
- CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
- child_a->set_size(Vector2(100, 100));
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == pos);
- CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
- child_a->set_visible(true);
- pos = { 100, (int)split_container->get_size().x / 2 + 50 };
- MessageQueue::get_singleton()->flush();
- CHECK(split_container->get_split_offsets() == pos);
- CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
- CHECK(child_b->get_size().x == child_c->get_size().x);
- }
- memdelete(split_container);
- }
- } // namespace TestSplitContainer
|