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:
@@ -31,14 +31,6 @@
|
||||
#include "panel_container.h"
|
||||
|
||||
Size2 PanelContainer::get_minimum_size() const {
|
||||
Ref<StyleBox> style;
|
||||
|
||||
if (has_theme_stylebox(SNAME("panel"))) {
|
||||
style = get_theme_stylebox(SNAME("panel"));
|
||||
} else {
|
||||
style = get_theme_stylebox(SNAME("panel"), SNAME("PanelContainer"));
|
||||
}
|
||||
|
||||
Size2 ms;
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
Control *c = Object::cast_to<Control>(get_child(i));
|
||||
@@ -54,8 +46,8 @@ Size2 PanelContainer::get_minimum_size() const {
|
||||
ms.height = MAX(ms.height, minsize.height);
|
||||
}
|
||||
|
||||
if (style.is_valid()) {
|
||||
ms += style->get_minimum_size();
|
||||
if (theme_cache.panel_style.is_valid()) {
|
||||
ms += theme_cache.panel_style->get_minimum_size();
|
||||
}
|
||||
return ms;
|
||||
}
|
||||
@@ -78,35 +70,25 @@ Vector<int> PanelContainer::get_allowed_size_flags_vertical() const {
|
||||
return flags;
|
||||
}
|
||||
|
||||
void PanelContainer::_update_theme_item_cache() {
|
||||
Container::_update_theme_item_cache();
|
||||
|
||||
theme_cache.panel_style = get_theme_stylebox(SNAME("panel"));
|
||||
}
|
||||
|
||||
void PanelContainer::_notification(int p_what) {
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_DRAW: {
|
||||
RID ci = get_canvas_item();
|
||||
Ref<StyleBox> style;
|
||||
|
||||
if (has_theme_stylebox(SNAME("panel"))) {
|
||||
style = get_theme_stylebox(SNAME("panel"));
|
||||
} else {
|
||||
style = get_theme_stylebox(SNAME("panel"), SNAME("PanelContainer"));
|
||||
}
|
||||
|
||||
style->draw(ci, Rect2(Point2(), get_size()));
|
||||
theme_cache.panel_style->draw(ci, Rect2(Point2(), get_size()));
|
||||
} break;
|
||||
|
||||
case NOTIFICATION_SORT_CHILDREN: {
|
||||
Ref<StyleBox> style;
|
||||
|
||||
if (has_theme_stylebox(SNAME("panel"))) {
|
||||
style = get_theme_stylebox(SNAME("panel"));
|
||||
} else {
|
||||
style = get_theme_stylebox(SNAME("panel"), SNAME("PanelContainer"));
|
||||
}
|
||||
|
||||
Size2 size = get_size();
|
||||
Point2 ofs;
|
||||
if (style.is_valid()) {
|
||||
size -= style->get_minimum_size();
|
||||
ofs += style->get_offset();
|
||||
if (theme_cache.panel_style.is_valid()) {
|
||||
size -= theme_cache.panel_style->get_minimum_size();
|
||||
ofs += theme_cache.panel_style->get_offset();
|
||||
}
|
||||
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
|
||||
Reference in New Issue
Block a user