+1 vote

Hi guys, i want to use CELL_MODE_CUSTOM in TreeItem but i dont know how to start customing. This is the docs about TreeItem http://docs.godotengine.org/en/stable/classes/class_treeitem.html

I've figure out how to use

CELL_MODE_STRING = 0
CELL_MODE_CHECK = 1
CELL_MODE_RANGE = 2
CELL_MODE_RANGE_EXPRESSION = 3
CELL_MODE_ICON = 4

but for CELLMODECUSTOM i just dont know, i need this mode.

in Engine by (35 points)

2 Answers

+2 votes

You mainly use them to display popups like for example a drop down menu or a position entry popup. You connect the custom_popup_edited signal, then in the signal handling function you can use get_edited() to check which TreeItem was clicked and get_custom_popup_rect() to position the popup that you want to display.

by (1,564 points)

Note that the cell itself needs to be set as editable item.set_editable(0, true) before the tree could emit custom_popup_edited signal.

0 votes

To use the custom mode you have to switch the column of the TreeItem to CELL_MODE_CUSTOM mode and provide a custom render callback by calling set_custom_draw for every TreeItem

var tree = Tree.new()
var item = tree.create_item()
item.set_cell_mode(0, CELL_MODE_CUSTOM)
item.set_custom_draw(0, callbackHolder, "customDraw")

# this method must be in the callbackHolder 
func customDraw(item, rect):
    tree.draw_rect(rect, Color.new(1,1,1))  # draws your color as cell's background

In this method you may use drawing methods from this tutorial.

https://docs.godotengine.org/en/stable/tutorials/2d/custom_drawing_in_2d.html

It is important to call the draw_something method on the Tree object, not on the callback holder itself. Any Godot's object may be used as a callbackHolder.

by (18 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.