Skip to content

Commit 34f005d

Browse files
committed
Merge pull request #106487 from bruvzg/rtl_fix
Revert #104357 and #106141 to fix Control RTL position
2 parents 202b117 + 25ae5c8 commit 34f005d

File tree

3 files changed

+9
-47
lines changed

3 files changed

+9
-47
lines changed

scene/gui/control.cpp

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -902,13 +902,6 @@ void Control::_compute_offsets(Rect2 p_rect, const real_t p_anchors[4], real_t (
902902
r_offsets[3] = p_rect.position.y + p_rect.size.y - (p_anchors[3] * parent_rect_size.y);
903903
}
904904

905-
void Control::_compute_edge_positions(Rect2 p_rect, real_t (&r_edge_positions)[4]) {
906-
for (int i = 0; i < 4; i++) {
907-
real_t area = p_rect.size[i & 1];
908-
r_edge_positions[i] = data.offset[i] + (data.anchor[i] * area);
909-
}
910-
}
911-
912905
/// Presets and layout modes.
913906

914907
void Control::_set_layout_mode(LayoutMode p_mode) {
@@ -1439,14 +1432,10 @@ void Control::set_position(const Point2 &p_point, bool p_keep_offsets) {
14391432
}
14401433
#endif // TOOLS_ENABLED
14411434

1442-
real_t edge_pos[4];
1443-
_compute_edge_positions(get_parent_anchorable_rect(), edge_pos);
1444-
Point2 offset_pos = Point2(edge_pos[0], edge_pos[1]) + (p_point - data.pos_cache);
1445-
Size2 offset_size(edge_pos[2] - edge_pos[0], edge_pos[3] - edge_pos[1]);
14461435
if (p_keep_offsets) {
1447-
_compute_anchors(Rect2(offset_pos, offset_size), data.offset, data.anchor);
1436+
_compute_anchors(Rect2(p_point, data.size_cache), data.offset, data.anchor);
14481437
} else {
1449-
_compute_offsets(Rect2(offset_pos, offset_size), data.anchor, data.offset);
1438+
_compute_offsets(Rect2(p_point, data.size_cache), data.anchor, data.offset);
14501439
}
14511440
_size_changed();
14521441
}
@@ -1736,8 +1725,14 @@ Size2 Control::get_combined_minimum_size() const {
17361725

17371726
void Control::_size_changed() {
17381727
Rect2 parent_rect = get_parent_anchorable_rect();
1728+
17391729
real_t edge_pos[4];
1740-
_compute_edge_positions(parent_rect, edge_pos);
1730+
1731+
for (int i = 0; i < 4; i++) {
1732+
real_t area = parent_rect.size[i & 1];
1733+
edge_pos[i] = data.offset[i] + (data.anchor[i] * area);
1734+
}
1735+
17411736
Point2 new_pos_cache = Point2(edge_pos[0], edge_pos[1]);
17421737
Size2 new_size_cache = Point2(edge_pos[2], edge_pos[3]) - new_pos_cache;
17431738

scene/gui/control.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,6 @@ class Control : public CanvasItem {
307307

308308
void _compute_offsets(Rect2 p_rect, const real_t p_anchors[4], real_t (&r_offsets)[4]);
309309
void _compute_anchors(Rect2 p_rect, const real_t p_offsets[4], real_t (&r_anchors)[4]);
310-
void _compute_edge_positions(Rect2 p_rect, real_t (&r_edge_positions)[4]);
311310

312311
void _set_layout_mode(LayoutMode p_mode);
313312
void _update_layout_mode();

tests/scene/test_control.h

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,38 +1096,6 @@ TEST_CASE("[SceneTree][Control] Anchoring") {
10961096
memdelete(test_control);
10971097
}
10981098

1099-
TEST_CASE("[SceneTree][Control] Set position does not cause size side-effects") {
1100-
Control *test_control = memnew(Control);
1101-
test_control->set_size(Size2(1, 1));
1102-
test_control->set_custom_minimum_size(Size2(2, 2));
1103-
Window *root = SceneTree::get_singleton()->get_root();
1104-
root->add_child(test_control);
1105-
1106-
SUBCASE("Shrinks after setting position and smaller custom minimum size (without keeping offsets)") {
1107-
test_control->set_position(Point2(10, 10), false);
1108-
SceneTree::get_singleton()->process(0);
1109-
1110-
test_control->set_custom_minimum_size(Size2(0, 0));
1111-
SceneTree::get_singleton()->process(0);
1112-
CHECK_MESSAGE(
1113-
test_control->get_size().is_equal_approx(Vector2(1, 1)),
1114-
"Should shrink to original size after setting a smaller custom minimum size.");
1115-
}
1116-
1117-
SUBCASE("Shrinks after setting position and smaller custom minimum size (while keeping offsets)") {
1118-
test_control->set_position(Point2(10, 10), true);
1119-
SceneTree::get_singleton()->process(0);
1120-
1121-
test_control->set_custom_minimum_size(Size2(0, 0));
1122-
SceneTree::get_singleton()->process(0);
1123-
CHECK_MESSAGE(
1124-
test_control->get_size().is_equal_approx(Vector2(1, 1)),
1125-
"Should shrink to original size after setting a smaller custom minimum size.");
1126-
}
1127-
1128-
memdelete(test_control);
1129-
}
1130-
11311099
TEST_CASE("[SceneTree][Control] Custom minimum size") {
11321100
Control *test_control = memnew(Control);
11331101
test_control->set_custom_minimum_size(Size2(4, 2));

0 commit comments

Comments
 (0)