Skip to content

Commit

Permalink
replace computed height with cached item minimum size
Browse files Browse the repository at this point in the history
replace computed height with cached item minimum size
  • Loading branch information
maidopi-usagi committed Sep 14, 2024
1 parent 97ef3c8 commit bd51ae2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 40 deletions.
46 changes: 6 additions & 40 deletions scene/gui/tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1513,7 +1513,7 @@ Size2 TreeItem::get_minimum_size(int p_column) {

const TreeItem::Cell &cell = cells[p_column];

if (cell.cached_minimum_size_dirty) {
if (cell.cached_minimum_size_dirty || cell.text_buf->is_dirty() || cell.dirty) {
Size2 size = Size2(
parent_tree->theme_cache.inner_item_margin_left + parent_tree->theme_cache.inner_item_margin_right,
parent_tree->theme_cache.inner_item_margin_top + parent_tree->theme_cache.inner_item_margin_bottom);
Expand All @@ -1532,7 +1532,9 @@ Size2 TreeItem::get_minimum_size(int p_column) {

// Icon.
if (cell.mode == CELL_MODE_CHECK) {
size.width += parent_tree->theme_cache.checked->get_width() + parent_tree->theme_cache.h_separation;
Size2i check_size = parent_tree->theme_cache.checked->get_size();
size.width += check_size.width + parent_tree->theme_cache.h_separation;
size.height = MAX(size.height, check_size.height);
}
if (cell.icon.is_valid()) {
Size2i icon_size = parent_tree->_get_cell_icon_size(cell);
Expand Down Expand Up @@ -1822,44 +1824,7 @@ int Tree::compute_item_height(TreeItem *p_item) const {
int height = 0;

for (int i = 0; i < columns.size(); i++) {
if (p_item->cells[i].dirty) {
const_cast<Tree *>(this)->update_item_cell(p_item, i);
}
height = MAX(height, p_item->cells[i].text_buf->get_size().y);
for (int j = 0; j < p_item->cells[i].buttons.size(); j++) {
Size2i s; // = cache.button_pressed->get_minimum_size();
s += p_item->cells[i].buttons[j].texture->get_size();
if (s.height > height) {
height = s.height;
}
}

switch (p_item->cells[i].mode) {
case TreeItem::CELL_MODE_CHECK: {
int check_icon_h = theme_cache.checked->get_height();
if (height < check_icon_h) {
height = check_icon_h;
}
[[fallthrough]];
}
case TreeItem::CELL_MODE_STRING:
case TreeItem::CELL_MODE_CUSTOM:
case TreeItem::CELL_MODE_ICON: {
Ref<Texture2D> icon = p_item->cells[i].icon;
if (!icon.is_null()) {
Size2i s = _get_cell_icon_size(p_item->cells[i]);
if (s.height > height) {
height = s.height;
}
}
if (p_item->cells[i].mode == TreeItem::CELL_MODE_CUSTOM && p_item->cells[i].custom_button) {
height += theme_cache.custom_button->get_minimum_size().height;
}

} break;
default: {
}
}
height = MAX(height, p_item->get_minimum_size(i).y);
}
int item_min_height = MAX(theme_cache.font->get_height(theme_cache.font_size), p_item->get_custom_minimum_height());
if (height < item_min_height) {
Expand Down Expand Up @@ -4488,6 +4453,7 @@ void Tree::item_edited(int p_column, TreeItem *p_item, MouseButton p_custom_mous
edited_col = p_column;
if (p_item != nullptr && p_column >= 0 && p_column < p_item->cells.size()) {
edited_item->cells.write[p_column].dirty = true;
edited_item->cells.write[p_column].cached_minimum_size_dirty = true;
}
emit_signal(SNAME("item_edited"));
if (p_custom_mouse_index != MouseButton::NONE) {
Expand Down
4 changes: 4 additions & 0 deletions scene/resources/text_paragraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,10 @@ int TextParagraph::hit_test(const Point2 &p_coords) const {
return TS->shaped_text_get_range(rid).y;
}

bool TextParagraph::is_dirty() {
return lines_dirty;
}

void TextParagraph::draw_dropcap(RID p_canvas, const Vector2 &p_pos, const Color &p_color) const {
_THREAD_SAFE_METHOD_

Expand Down
2 changes: 2 additions & 0 deletions scene/resources/text_paragraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ class TextParagraph : public RefCounted {

int hit_test(const Point2 &p_coords) const;

bool is_dirty();

Mutex &get_mutex() const { return _thread_safe_; };

TextParagraph(const String &p_text, const Ref<Font> &p_font, int p_font_size, const String &p_language = "", float p_width = -1.f, TextServer::Direction p_direction = TextServer::DIRECTION_AUTO, TextServer::Orientation p_orientation = TextServer::ORIENTATION_HORIZONTAL);
Expand Down

0 comments on commit bd51ae2

Please sign in to comment.