mirror of
https://github.com/godotengine/godot.git
synced 2025-12-07 22:00:10 +00:00
[Window] Add unfiltered input handler signal for custom decorations.
This commit is contained in:
parent
cb7cd815ee
commit
101fbbbd1f
5 changed files with 96 additions and 47 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue