Merge pull request #111288 from bruvzg/move_input

[Window] Add unfiltered input handler signal for custom decorations.
This commit is contained in:
Thaddeus Crews 2025-11-05 11:48:06 -06:00
commit 3b4239d649
No known key found for this signature in database
GPG key ID: 8C6E5FEB5FC03CCC
5 changed files with 96 additions and 47 deletions

View file

@ -89,57 +89,71 @@ Control *EditorTitleBar::get_center_control() const {
}
void EditorTitleBar::_notification(int p_what) {
if (!center_control || p_what != NOTIFICATION_SORT_CHILDREN) {
return;
}
Control *prev = nullptr;
Control *base = nullptr;
Control *next = nullptr;
bool rtl = is_layout_rtl();
int start;
int end;
int delta;
if (rtl) {
start = get_child_count() - 1;
end = -1;
delta = -1;
} else {
start = 0;
end = get_child_count();
delta = +1;
}
for (int i = start; i != end; i += delta) {
Control *c = as_sortable_control(get_child(i));
if (!c) {
continue;
switch (p_what) {
case NOTIFICATION_EXIT_TREE: {
SceneTree::get_singleton()->get_root()->disconnect(SceneStringName(nonclient_window_input), callable_mp(this, &EditorTitleBar::gui_input));
get_window()->set_nonclient_area(Rect2i());
} break;
case NOTIFICATION_ENTER_TREE: {
SceneTree::get_singleton()->get_root()->connect(SceneStringName(nonclient_window_input), callable_mp(this, &EditorTitleBar::gui_input));
[[fallthrough]];
}
if (base) {
next = c;
break;
}
if (c != center_control) {
prev = c;
continue;
}
base = c;
}
if (base && prev && next) {
Size2i title_size = get_size();
Size2i c_size = base->get_combined_minimum_size();
case NOTIFICATION_RESIZED: {
get_window()->set_nonclient_area(get_global_transform().xform(Rect2i(get_position(), get_size())));
} break;
case NOTIFICATION_SORT_CHILDREN: {
if (!center_control) {
break;
}
Control *prev = nullptr;
Control *base = nullptr;
Control *next = nullptr;
int min_offset = prev->get_position().x + prev->get_combined_minimum_size().x;
int max_offset = next->get_position().x + next->get_size().x - next->get_combined_minimum_size().x - c_size.x;
bool rtl = is_layout_rtl();
int offset = (title_size.width - c_size.width) / 2;
offset = CLAMP(offset, min_offset, max_offset);
int start;
int end;
int delta;
if (rtl) {
start = get_child_count() - 1;
end = -1;
delta = -1;
} else {
start = 0;
end = get_child_count();
delta = +1;
}
fit_child_in_rect(prev, Rect2i(prev->get_position().x, 0, offset - prev->get_position().x, title_size.height));
fit_child_in_rect(base, Rect2i(offset, 0, c_size.width, title_size.height));
fit_child_in_rect(next, Rect2i(offset + c_size.width, 0, next->get_position().x + next->get_size().x - (offset + c_size.width), title_size.height));
for (int i = start; i != end; i += delta) {
Control *c = as_sortable_control(get_child(i));
if (!c) {
continue;
}
if (base) {
next = c;
break;
}
if (c != center_control) {
prev = c;
continue;
}
base = c;
}
if (base && prev && next) {
Size2i title_size = get_size();
Size2i c_size = base->get_combined_minimum_size();
int min_offset = prev->get_position().x + prev->get_combined_minimum_size().x;
int max_offset = next->get_position().x + next->get_size().x - next->get_combined_minimum_size().x - c_size.x;
int offset = (title_size.width - c_size.width) / 2;
offset = CLAMP(offset, min_offset, max_offset);
fit_child_in_rect(prev, Rect2i(prev->get_position().x, 0, offset - prev->get_position().x, title_size.height));
fit_child_in_rect(base, Rect2i(offset, 0, c_size.width, title_size.height));
fit_child_in_rect(next, Rect2i(offset + c_size.width, 0, next->get_position().x + next->get_size().x - (offset + c_size.width), title_size.height));
}
} break;
}
}