Path: blob/master/tests/scene/test_panel_container.cpp
59209 views
/**************************************************************************/1/* test_panel_container.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "tests/test_macros.h"3132TEST_FORCE_LINK(test_panel_container)3334#include "scene/gui/control.h"35#include "scene/gui/panel_container.h"36#include "scene/main/scene_tree.h"37#include "scene/main/window.h"38#include "scene/resources/style_box.h"3940namespace TestPanelContainer {4142TEST_CASE("[SceneTree][PanelContainer] Default properties") {43PanelContainer *panel_container = memnew(PanelContainer);44Window *root = SceneTree::get_singleton()->get_root();45root->add_child(panel_container);46SceneTree::get_singleton()->process(0);4748CHECK_MESSAGE(49panel_container->get_mouse_filter() == Control::MOUSE_FILTER_STOP,50"PanelContainer mouse filter is set to MOUSE_FILTER_STOP by default.");5152memdelete(panel_container);53}5455TEST_CASE("[SceneTree][PanelContainer] StyleBox affects layout and minimum size") {56PanelContainer *panel_container = memnew(PanelContainer);57Window *root = SceneTree::get_singleton()->get_root();58root->add_child(panel_container);5960Ref<StyleBoxEmpty> panel_style = memnew(StyleBoxEmpty);61panel_style->set_content_margin_individual(5, 6, 7, 8);62panel_container->add_theme_style_override("panel", panel_style);6364Control *child_control = memnew(Control);65child_control->set_custom_minimum_size(Size2(20, 10));66panel_container->add_child(child_control);6768panel_container->set_size(Size2(100, 80));69SceneTree::get_singleton()->process(0);7071CHECK_MESSAGE(72child_control->get_position().is_equal_approx(Point2(5, 6)),73"Child control is offset by the panel StyleBox margins.");7475CHECK_MESSAGE(76child_control->get_size().is_equal_approx(Size2(88, 66)),77"Child control size is reduced by the panel StyleBox minimum size.");7879CHECK_MESSAGE(80panel_container->get_minimum_size().is_equal_approx(Size2(32, 24)),81"Minimum size equals child minimum size plus panel StyleBox minimum size.");8283memdelete(child_control);84memdelete(panel_container);85}8687TEST_CASE("[SceneTree][PanelContainer] Multiple children use maximum minimum size") {88PanelContainer *panel_container = memnew(PanelContainer);89Window *root = SceneTree::get_singleton()->get_root();90root->add_child(panel_container);9192Ref<StyleBoxEmpty> panel_style = memnew(StyleBoxEmpty);93panel_style->set_content_margin_individual(2, 3, 4, 5);94panel_container->add_theme_style_override("panel", panel_style);9596Control *child_control_1 = memnew(Control);97Control *child_control_2 = memnew(Control);98child_control_1->set_custom_minimum_size(Size2(40, 10));99child_control_2->set_custom_minimum_size(Size2(20, 50));100panel_container->add_child(child_control_1);101panel_container->add_child(child_control_2);102SceneTree::get_singleton()->process(0);103104CHECK_MESSAGE(105panel_container->get_minimum_size().is_equal_approx(Size2(46, 58)),106"Minimum size uses maximum child minimum width/height plus panel StyleBox minimum size.");107108memdelete(child_control_2);109memdelete(child_control_1);110memdelete(panel_container);111}112113} // namespace TestPanelContainer114115116