Add custom StyleBox to TreeItem
This commit is contained in:
@ -878,6 +878,17 @@ int TreeItem::get_custom_minimum_height() const {
|
||||
return custom_min_height;
|
||||
}
|
||||
|
||||
void TreeItem::set_custom_stylebox(int p_column, const Ref<StyleBox> &p_stylebox) {
|
||||
ERR_FAIL_INDEX(p_column, cells.size());
|
||||
cells.write[p_column].custom_stylebox = p_stylebox;
|
||||
_changed_notify(p_column);
|
||||
}
|
||||
|
||||
Ref<StyleBox> TreeItem::get_custom_stylebox(int p_column) const {
|
||||
ERR_FAIL_INDEX_V(p_column, cells.size(), Ref<StyleBox>());
|
||||
return cells[p_column].custom_stylebox;
|
||||
}
|
||||
|
||||
TreeItem *TreeItem::create_child(int p_index) {
|
||||
TreeItem *ti = memnew(TreeItem(tree));
|
||||
if (tree) {
|
||||
@ -1843,6 +1854,9 @@ void TreeItem::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_custom_draw_callback", "column", "callback"), &TreeItem::set_custom_draw_callback);
|
||||
ClassDB::bind_method(D_METHOD("get_custom_draw_callback", "column"), &TreeItem::get_custom_draw_callback);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_custom_stylebox", "column", "stylebox"), &TreeItem::set_custom_stylebox);
|
||||
ClassDB::bind_method(D_METHOD("get_custom_stylebox", "column"), &TreeItem::get_custom_stylebox);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_collapsed", "enable"), &TreeItem::set_collapsed);
|
||||
ClassDB::bind_method(D_METHOD("is_collapsed"), &TreeItem::is_collapsed);
|
||||
|
||||
@ -2436,6 +2450,16 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
|
||||
}
|
||||
}
|
||||
|
||||
if (p_item->cells[i].custom_stylebox.is_valid()) {
|
||||
Rect2 r = cell_rect;
|
||||
if (i == 0) {
|
||||
r.position.x = p_draw_ofs.x;
|
||||
r.size.x = item_width + ofs;
|
||||
}
|
||||
r = convert_rtl_rect(r);
|
||||
draw_style_box(p_item->cells[i].custom_stylebox, r);
|
||||
}
|
||||
|
||||
if (drop_mode_flags && drop_mode_over) {
|
||||
Rect2 r = convert_rtl_rect(cell_rect);
|
||||
if (drop_mode_over == p_item) {
|
||||
|
||||
@ -98,6 +98,7 @@ private:
|
||||
bool custom_button = false;
|
||||
bool expand_right = false;
|
||||
Color icon_color = Color(1, 1, 1);
|
||||
Ref<StyleBox> custom_stylebox;
|
||||
|
||||
Size2i cached_minimum_size;
|
||||
bool cached_minimum_size_dirty = true;
|
||||
@ -359,6 +360,9 @@ public:
|
||||
void set_custom_minimum_height(int p_height);
|
||||
int get_custom_minimum_height() const;
|
||||
|
||||
void set_custom_stylebox(int p_column, const Ref<StyleBox> &p_stylebox);
|
||||
Ref<StyleBox> get_custom_stylebox(int p_column) const;
|
||||
|
||||
void set_selectable(int p_column, bool p_selectable);
|
||||
bool is_selectable(int p_column) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user