Skip to content

Add layout and focus behavior unit test for Control #107037

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ericzhihuang
Copy link

This pull request contributes to issue #43440.

I have added unit tests to check anchor margins to position a child Control within a parent. Verifies that position and size are calculated correctly after the scene is processed. Also checks focus neighbor: the test sets left and right focus neighbors using set_focus_neighbour() and checks that get_focus_neighbour() returns the expected NodePath.

Copy link
Contributor

@qwertychomp qwertychomp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following suggestions should make your code pass the style check.

Comment on lines +31 to +34
#include "scene/gui/control.h"
#include "scene/main/window.h"
#include "scene/main/scene_tree.h"
#include "tests/test_macros.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#include "scene/gui/control.h"
#include "scene/main/window.h"
#include "scene/main/scene_tree.h"
#include "tests/test_macros.h"
#include "scene/gui/control.h"
#include "scene/main/scene_tree.h"
#include "scene/main/window.h"
#include "tests/test_macros.h"

Comment on lines +60 to +65
CHECK_MESSAGE(
child->get_position().is_equal_approx(Vector2(100, 100)),
"Child should be positioned at 25% of parent size.");
CHECK_MESSAGE(
child->get_size().is_equal_approx(Vector2(200, 200)),
"Child should be sized to 50% of parent width and height.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CHECK_MESSAGE(
child->get_position().is_equal_approx(Vector2(100, 100)),
"Child should be positioned at 25% of parent size.");
CHECK_MESSAGE(
child->get_size().is_equal_approx(Vector2(200, 200)),
"Child should be sized to 50% of parent width and height.");
CHECK_MESSAGE(
child->get_position().is_equal_approx(Vector2(100, 100)),
"Child should be positioned at 25% of parent size.");
CHECK_MESSAGE(
child->get_size().is_equal_approx(Vector2(200, 200)),
"Child should be sized to 50% of parent width and height.");

Comment on lines +72 to +77
CHECK_MESSAGE(
child->get_focus_neighbour(SIDE_LEFT) == NodePath("LeftControl"),
"Left focus neighbor should be correctly set.");
CHECK_MESSAGE(
child->get_focus_neighbour(SIDE_RIGHT) == NodePath("RightControl"),
"Right focus neighbor should be correctly set.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CHECK_MESSAGE(
child->get_focus_neighbour(SIDE_LEFT) == NodePath("LeftControl"),
"Left focus neighbor should be correctly set.");
CHECK_MESSAGE(
child->get_focus_neighbour(SIDE_RIGHT) == NodePath("RightControl"),
"Right focus neighbor should be correctly set.");
CHECK_MESSAGE(
child->get_focus_neighbour(SIDE_LEFT) == NodePath("LeftControl"),
"Left focus neighbor should be correctly set.");
CHECK_MESSAGE(
child->get_focus_neighbour(SIDE_RIGHT) == NodePath("RightControl"),
"Right focus neighbor should be correctly set.");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants