Add a lifecycle method for manual theme item caching to Control

This commit is contained in:
Yuri Sizov
2022-08-31 15:02:40 +03:00
parent 0c221f0284
commit 3b1aa240dc
52 changed files with 1592 additions and 910 deletions

View File

@@ -33,24 +33,30 @@
Size2 Separator::get_minimum_size() const {
Size2 ms(3, 3);
if (orientation == VERTICAL) {
ms.x = get_theme_constant(SNAME("separation"));
ms.x = theme_cache.separation;
} else { // HORIZONTAL
ms.y = get_theme_constant(SNAME("separation"));
ms.y = theme_cache.separation;
}
return ms;
}
void Separator::_update_theme_item_cache() {
Control::_update_theme_item_cache();
theme_cache.separation = get_theme_constant(SNAME("separation"));
theme_cache.separator_style = get_theme_stylebox(SNAME("separator"));
}
void Separator::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_DRAW: {
Size2i size = get_size();
Ref<StyleBox> style = get_theme_stylebox(SNAME("separator"));
Size2i ssize = style->get_minimum_size() + style->get_center_size();
Size2i ssize = theme_cache.separator_style->get_minimum_size() + theme_cache.separator_style->get_center_size();
if (orientation == VERTICAL) {
style->draw(get_canvas_item(), Rect2((size.x - ssize.x) / 2, 0, ssize.x, size.y));
theme_cache.separator_style->draw(get_canvas_item(), Rect2((size.x - ssize.x) / 2, 0, ssize.x, size.y));
} else {
style->draw(get_canvas_item(), Rect2(0, (size.y - ssize.y) / 2, size.x, ssize.y));
theme_cache.separator_style->draw(get_canvas_item(), Rect2(0, (size.y - ssize.y) / 2, size.x, ssize.y));
}
} break;
}