mirror of
https://github.com/godotengine/godot.git
synced 2026-01-03 18:11:19 +03:00
Add a lifecycle method for manual theme item caching to Control
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user