Skip to content

Conversation

@DeeJayLSP
Copy link
Contributor

@DeeJayLSP DeeJayLSP commented Nov 4, 2025

Allows setting a custom StyleBox in TreeItem cells in a similar way you would set a custom BG color, text or icon:

const MY_STYLEBOX = preload("res://path/to/my_stylebox.tres")

func _ready():
var tree = Tree.new()
var root = tree.create_item()
var child = tree.create_item(root)
child.set_custom_stylebox(0, MY_STYLEBOX)

Draw order should be:

  1. Custom BG color
  2. Custom StyleBox
  3. The rest of the components (including StyleBoxes drawn through the custom draw callback)

This could have the potential to deprecate the custom BG color, but I'm leaving it as it is as they can coexist.

Weird demonstration I made for testing, with 4 different StyleBoxes (start, middle, end, full, and all cell types in each row):
image

This should allow implementing #112360 and reimplementing #112233 without having to do workarounds (not part of this PR):
image

Copy link
Member

@YeldhamDev YeldhamDev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, and while this doesn't allow to fully match the way that the classic theme does it (covering the drop-arrows), it's not a deal breaker.

@DeeJayLSP
Copy link
Contributor Author

DeeJayLSP commented Nov 5, 2025

Added to the docs that the custom stylebox is drawn on top of the background color.

Also,

Looks good, and while this doesn't allow to fully match the way that the classic theme does it (covering the drop-arrows), it's not a deal breaker.

The logic for matching the rects exactly has been implemented (it was basically a copypaste). Screenshots updated. Like I said in the description however, I want to keep this feature implementation and the update on the theme separate.

@DeeJayLSP DeeJayLSP requested a review from YeldhamDev November 5, 2025 02:02
@DeeJayLSP
Copy link
Contributor Author

PR that actually implements the style in the Action Map editor mentioned above.

@Mickeon Mickeon modified the milestones: 4.x, 4.6 Nov 5, 2025
@Repiteo Repiteo merged commit 6539819 into godotengine:master Nov 5, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Nov 5, 2025

Thanks!

@DeeJayLSP DeeJayLSP deleted the treeitem-stylebox branch November 5, 2025 19:09

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be checking whether the new stylebox is different, but seems like such checks are not done consistently in TreeItem anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants