diff options
Diffstat (limited to 'scene/gui/tree.cpp')
-rw-r--r-- | scene/gui/tree.cpp | 183 |
1 files changed, 101 insertions, 82 deletions
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 3c1be2d5fe..4ed52bd465 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -40,6 +40,7 @@ #include "scene/gui/box_container.h" #include "scene/gui/text_edit.h" #include "scene/main/window.h" +#include "scene/theme/theme_db.h" #include <limits.h> @@ -352,6 +353,24 @@ TextServer::AutowrapMode TreeItem::get_autowrap_mode(int p_column) const { return cells[p_column].autowrap_mode; } +void TreeItem::set_text_overrun_behavior(int p_column, TextServer::OverrunBehavior p_behavior) { + ERR_FAIL_INDEX(p_column, cells.size()); + + if (cells[p_column].text_buf->get_text_overrun_behavior() == p_behavior) { + return; + } + + cells.write[p_column].text_buf->set_text_overrun_behavior(p_behavior); + cells.write[p_column].dirty = true; + _changed_notify(p_column); + cells.write[p_column].cached_minimum_size_dirty = true; +} + +TextServer::OverrunBehavior TreeItem::get_text_overrun_behavior(int p_column) const { + ERR_FAIL_INDEX_V(p_column, cells.size(), TextServer::OVERRUN_TRIM_ELLIPSIS); + return cells[p_column].text_buf->get_text_overrun_behavior(); +} + void TreeItem::set_structured_text_bidi_override(int p_column, TextServer::StructuredTextParser p_parser) { ERR_FAIL_INDEX(p_column, cells.size()); @@ -1512,6 +1531,9 @@ void TreeItem::_bind_methods() { ClassDB::bind_method(D_METHOD("set_autowrap_mode", "column", "autowrap_mode"), &TreeItem::set_autowrap_mode); ClassDB::bind_method(D_METHOD("get_autowrap_mode", "column"), &TreeItem::get_autowrap_mode); + ClassDB::bind_method(D_METHOD("set_text_overrun_behavior", "column", "overrun_behavior"), &TreeItem::set_text_overrun_behavior); + ClassDB::bind_method(D_METHOD("get_text_overrun_behavior", "column"), &TreeItem::get_text_overrun_behavior); + ClassDB::bind_method(D_METHOD("set_structured_text_bidi_override", "column", "parser"), &TreeItem::set_structured_text_bidi_override); ClassDB::bind_method(D_METHOD("get_structured_text_bidi_override", "column"), &TreeItem::get_structured_text_bidi_override); @@ -1679,76 +1701,6 @@ TreeItem::~TreeItem() { void Tree::_update_theme_item_cache() { Control::_update_theme_item_cache(); - theme_cache.panel_style = get_theme_stylebox(SNAME("panel")); - theme_cache.focus_style = get_theme_stylebox(SNAME("focus")); - - theme_cache.font = get_theme_font(SNAME("font")); - theme_cache.font_size = get_theme_font_size(SNAME("font_size")); - theme_cache.tb_font = get_theme_font(SNAME("title_button_font")); - theme_cache.tb_font_size = get_theme_font_size(SNAME("title_button_font_size")); - - theme_cache.selected = get_theme_stylebox(SNAME("selected")); - theme_cache.selected_focus = get_theme_stylebox(SNAME("selected_focus")); - theme_cache.cursor = get_theme_stylebox(SNAME("cursor")); - theme_cache.cursor_unfocus = get_theme_stylebox(SNAME("cursor_unfocused")); - theme_cache.button_pressed = get_theme_stylebox(SNAME("button_pressed")); - - theme_cache.checked = get_theme_icon(SNAME("checked")); - theme_cache.unchecked = get_theme_icon(SNAME("unchecked")); - theme_cache.indeterminate = get_theme_icon(SNAME("indeterminate")); - theme_cache.arrow = get_theme_icon(SNAME("arrow")); - theme_cache.arrow_collapsed = get_theme_icon(SNAME("arrow_collapsed")); - theme_cache.arrow_collapsed_mirrored = get_theme_icon(SNAME("arrow_collapsed_mirrored")); - theme_cache.select_arrow = get_theme_icon(SNAME("select_arrow")); - theme_cache.updown = get_theme_icon(SNAME("updown")); - - theme_cache.custom_button = get_theme_stylebox(SNAME("custom_button")); - theme_cache.custom_button_hover = get_theme_stylebox(SNAME("custom_button_hover")); - theme_cache.custom_button_pressed = get_theme_stylebox(SNAME("custom_button_pressed")); - theme_cache.custom_button_font_highlight = get_theme_color(SNAME("custom_button_font_highlight")); - - theme_cache.font_color = get_theme_color(SNAME("font_color")); - theme_cache.font_selected_color = get_theme_color(SNAME("font_selected_color")); - theme_cache.drop_position_color = get_theme_color(SNAME("drop_position_color")); - theme_cache.h_separation = get_theme_constant(SNAME("h_separation")); - theme_cache.v_separation = get_theme_constant(SNAME("v_separation")); - theme_cache.inner_item_margin_bottom = get_theme_constant(SNAME("inner_item_margin_bottom")); - theme_cache.inner_item_margin_left = get_theme_constant(SNAME("inner_item_margin_left")); - theme_cache.inner_item_margin_right = get_theme_constant(SNAME("inner_item_margin_right")); - theme_cache.inner_item_margin_top = get_theme_constant(SNAME("inner_item_margin_top")); - theme_cache.item_margin = get_theme_constant(SNAME("item_margin")); - theme_cache.button_margin = get_theme_constant(SNAME("button_margin")); - theme_cache.icon_max_width = get_theme_constant(SNAME("icon_max_width")); - - theme_cache.font_outline_color = get_theme_color(SNAME("font_outline_color")); - theme_cache.font_outline_size = get_theme_constant(SNAME("outline_size")); - - theme_cache.draw_guides = get_theme_constant(SNAME("draw_guides")); - theme_cache.guide_color = get_theme_color(SNAME("guide_color")); - theme_cache.draw_relationship_lines = get_theme_constant(SNAME("draw_relationship_lines")); - theme_cache.relationship_line_width = get_theme_constant(SNAME("relationship_line_width")); - theme_cache.parent_hl_line_width = get_theme_constant(SNAME("parent_hl_line_width")); - theme_cache.children_hl_line_width = get_theme_constant(SNAME("children_hl_line_width")); - theme_cache.parent_hl_line_margin = get_theme_constant(SNAME("parent_hl_line_margin")); - theme_cache.relationship_line_color = get_theme_color(SNAME("relationship_line_color")); - theme_cache.parent_hl_line_color = get_theme_color(SNAME("parent_hl_line_color")); - theme_cache.children_hl_line_color = get_theme_color(SNAME("children_hl_line_color")); - - theme_cache.scroll_border = get_theme_constant(SNAME("scroll_border")); - theme_cache.scroll_speed = get_theme_constant(SNAME("scroll_speed")); - - theme_cache.scrollbar_margin_top = get_theme_constant(SNAME("scrollbar_margin_top")); - theme_cache.scrollbar_margin_right = get_theme_constant(SNAME("scrollbar_margin_right")); - theme_cache.scrollbar_margin_bottom = get_theme_constant(SNAME("scrollbar_margin_bottom")); - theme_cache.scrollbar_margin_left = get_theme_constant(SNAME("scrollbar_margin_left")); - theme_cache.scrollbar_h_separation = get_theme_constant(SNAME("scrollbar_h_separation")); - theme_cache.scrollbar_v_separation = get_theme_constant(SNAME("scrollbar_v_separation")); - - theme_cache.title_button = get_theme_stylebox(SNAME("title_button_normal")); - theme_cache.title_button_pressed = get_theme_stylebox(SNAME("title_button_pressed")); - theme_cache.title_button_hover = get_theme_stylebox(SNAME("title_button_hover")); - theme_cache.title_button_color = get_theme_color(SNAME("title_button_color")); - theme_cache.base_scale = get_theme_default_base_scale(); } @@ -2096,7 +2048,12 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 buttons_width += button_size.width + theme_cache.button_margin; } - p_item->cells.write[i].text_buf->set_width(item_width); + int text_width = item_width - theme_cache.inner_item_margin_left - theme_cache.inner_item_margin_right; + if (p_item->cells[i].icon.is_valid()) { + text_width -= p_item->cells[i].get_icon_size().x + theme_cache.h_separation; + } + + p_item->cells.write[i].text_buf->set_width(text_width); r_self_height = compute_item_height(p_item); label_h = r_self_height + theme_cache.v_separation; @@ -2224,7 +2181,6 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 Point2i text_pos = item_rect.position; text_pos.y += Math::floor(p_draw_ofs.y) - _get_title_button_height(); - int text_width = p_item->cells[i].text_buf->get_size().x; switch (p_item->cells[i].mode) { case TreeItem::CELL_MODE_STRING: { @@ -2386,6 +2342,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 if (rtl) { button_ofs.x = get_size().width - button_ofs.x - button_texture->get_width(); } + p_item->cells.write[i].buttons.write[j].rect = Rect2i(button_ofs, button_size); button_texture->draw(ci, button_ofs, p_item->cells[i].buttons[j].disabled ? Color(1, 1, 1, 0.5) : p_item->cells[i].buttons[j].color); item_width_with_buttons -= button_size.width + theme_cache.button_margin; } @@ -5325,6 +5282,7 @@ String Tree::get_tooltip(const Point2 &p_pos) const { return Control::get_tooltip(p_pos); } + Point2 button_pos = pos; if (h_scroll->is_visible_in_tree()) { pos.x += h_scroll->get_value(); } @@ -5337,22 +5295,13 @@ String Tree::get_tooltip(const Point2 &p_pos) const { if (it) { const TreeItem::Cell &c = it->cells[col]; - int col_width = get_column_width(col); - - for (int i = 0; i < col; i++) { - pos.x -= get_column_width(i); - } - for (int j = c.buttons.size() - 1; j >= 0; j--) { - Ref<Texture2D> b = c.buttons[j].texture; - Size2 size = b->get_size() + theme_cache.button_pressed->get_minimum_size(); - if (pos.x > col_width - size.width) { + if (c.buttons[j].rect.has_point(button_pos)) { String tooltip = c.buttons[j].tooltip; if (!tooltip.is_empty()) { return tooltip; } } - col_width -= size.width; } String ret; if (it->get_tooltip_text(col) == "") { @@ -5559,6 +5508,76 @@ void Tree::_bind_methods() { BIND_ENUM_CONSTANT(DROP_MODE_DISABLED); BIND_ENUM_CONSTANT(DROP_MODE_ON_ITEM); BIND_ENUM_CONSTANT(DROP_MODE_INBETWEEN); + + BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, Tree, panel_style, "panel"); + BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, Tree, focus_style, "focus"); + + BIND_THEME_ITEM(Theme::DATA_TYPE_FONT, Tree, font); + BIND_THEME_ITEM(Theme::DATA_TYPE_FONT_SIZE, Tree, font_size); + BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_FONT, Tree, tb_font, "title_button_font"); + BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_FONT_SIZE, Tree, tb_font_size, "title_button_font_size"); + + BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, Tree, selected); + BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, Tree, selected_focus); + BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, Tree, cursor); + BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, Tree, cursor_unfocus, "cursor_unfocused"); + BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, Tree, button_pressed); + + BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, Tree, checked); + BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, Tree, unchecked); + BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, Tree, indeterminate); + BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, Tree, arrow); + BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, Tree, arrow_collapsed); + BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, Tree, arrow_collapsed_mirrored); + BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, Tree, select_arrow); + BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, Tree, updown); + + BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, Tree, custom_button); + BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, Tree, custom_button_hover); + BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, Tree, custom_button_pressed); + BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, Tree, custom_button_font_highlight); + + BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, Tree, font_color); + BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, Tree, font_selected_color); + BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, Tree, drop_position_color); + BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Tree, h_separation); + BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Tree, v_separation); + BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Tree, inner_item_margin_bottom); + BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Tree, inner_item_margin_left); + BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Tree, inner_item_margin_right); + BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Tree, inner_item_margin_top); + BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Tree, item_margin); + BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Tree, button_margin); + BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Tree, icon_max_width); + + BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, Tree, font_outline_color); + BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_CONSTANT, Tree, font_outline_size, "outline_size"); + + BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Tree, draw_guides); + BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, Tree, guide_color); + BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Tree, draw_relationship_lines); + BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Tree, relationship_line_width); + BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Tree, parent_hl_line_width); + BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Tree, children_hl_line_width); + BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Tree, parent_hl_line_margin); + BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, Tree, relationship_line_color); + BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, Tree, parent_hl_line_color); + BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, Tree, children_hl_line_color); + + BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Tree, scroll_border); + BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Tree, scroll_speed); + + BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Tree, scrollbar_margin_top); + BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Tree, scrollbar_margin_right); + BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Tree, scrollbar_margin_bottom); + BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Tree, scrollbar_margin_left); + BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Tree, scrollbar_h_separation); + BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Tree, scrollbar_v_separation); + + BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, Tree, title_button, "title_button_normal"); + BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, Tree, title_button_pressed); + BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, Tree, title_button_hover); + BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, Tree, title_button_color); } Tree::Tree() { |