summaryrefslogtreecommitdiff
path: root/scene/gui/tree.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui/tree.cpp')
-rw-r--r--scene/gui/tree.cpp54
1 files changed, 47 insertions, 7 deletions
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index 931dcfed91..749ff51f57 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -28,6 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "tree.h"
+#include <limits.h>
#include "os/input.h"
#include "os/keyboard.h"
@@ -154,8 +155,17 @@ void TreeItem::set_text(int p_column, String p_text) {
if (cells[p_column].mode == TreeItem::CELL_MODE_RANGE || cells[p_column].mode == TreeItem::CELL_MODE_RANGE_EXPRESSION) {
- cells[p_column].min = 0;
- cells[p_column].max = p_text.get_slice_count(",");
+ Vector<String> strings = p_text.split(",");
+ cells[p_column].min = INT_MAX;
+ cells[p_column].max = INT_MIN;
+ for (int i = 0; i < strings.size(); i++) {
+ int value = i;
+ if (!strings[i].get_slicec(':', 1).empty()) {
+ value = strings[i].get_slicec(':', 1).to_int();
+ }
+ cells[p_column].min = MIN(cells[p_column].min, value);
+ cells[p_column].max = MAX(cells[p_column].max, value);
+ }
cells[p_column].step = 0;
}
_changed_notify(p_column);
@@ -1126,7 +1136,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
if (p_item->cells[i].selected && select_mode != SELECT_ROW) {
- Rect2i r(item_rect.position, item_rect.size);
+ Rect2i r(cell_rect.position, cell_rect.size);
if (p_item->cells[i].text.size() > 0) {
float icon_width = p_item->cells[i].get_icon_size().width;
r.position.x += icon_width;
@@ -1231,8 +1241,18 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
int option = (int)p_item->cells[i].val;
- String s = p_item->cells[i].text;
- s = s.get_slicec(',', option);
+ String s = RTR("(Other)");
+ Vector<String> strings = p_item->cells[i].text.split(",");
+ for (int i = 0; i < strings.size(); i++) {
+ int value = i;
+ if (!strings[i].get_slicec(':', 1).empty()) {
+ value = strings[i].get_slicec(':', 1).to_int();
+ }
+ if (option == value) {
+ s = strings[i].get_slicec(':', 0);
+ break;
+ }
+ }
if (p_item->cells[i].suffix != String())
s += " " + p_item->cells[i].suffix;
@@ -1776,7 +1796,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
for (int i = 0; i < c.text.get_slice_count(","); i++) {
String s = c.text.get_slicec(',', i);
- popup_menu->add_item(s, i);
+ popup_menu->add_item(s.get_slicec(':', 0), s.get_slicec(':', 1).empty() ? i : s.get_slicec(':', 1).to_int());
}
popup_menu->set_size(Size2(col_width, 0));
@@ -2634,7 +2654,7 @@ bool Tree::edit_selected() {
for (int i = 0; i < c.text.get_slice_count(","); i++) {
String s = c.text.get_slicec(',', i);
- popup_menu->add_item(s, i);
+ popup_menu->add_item(s.get_slicec(':', 0), s.get_slicec(':', 1).empty() ? i : s.get_slicec(':', 1).to_int());
}
popup_menu->set_size(Size2(rect.size.width, 0));
@@ -3332,6 +3352,26 @@ Point2 Tree::get_scroll() const {
return ofs;
}
+void Tree::scroll_to_item(TreeItem *p_item) {
+
+ if (!is_visible_in_tree()) {
+
+ // hack to work around crash in get_item_rect() if Tree is not in tree.
+ return;
+ }
+
+ // make sure the scrollbar min and max are up to date with latest changes.
+ update_scrollbars();
+
+ const Rect2 r = get_item_rect(p_item);
+
+ if (r.position.y < v_scroll->get_value()) {
+ v_scroll->set_value(r.position.y);
+ } else if (r.position.y + r.size.y + 2 * cache.vseparation > v_scroll->get_value() + get_size().y) {
+ v_scroll->set_value(r.position.y + r.size.y + 2 * cache.vseparation - get_size().y);
+ }
+}
+
TreeItem *Tree::_search_item_text(TreeItem *p_at, const String &p_find, int *r_col, bool p_selectable, bool p_backwards) {
while (p_at) {