Skip to content

Instantly share code, notes, and snippets.

@andrew-wilkes
Last active June 25, 2020 09:57
Show Gist options
  • Select an option

  • Save andrew-wilkes/e49cde5fa18db6e25ecd6771ab311fa0 to your computer and use it in GitHub Desktop.

Select an option

Save andrew-wilkes/e49cde5fa18db6e25ecd6771ab311fa0 to your computer and use it in GitHub Desktop.
Godot TreeItem Highlight Code
func _on_Tree_gui_input(event):
if event is InputEventMouseMotion:
$Bar.rect_position = Vector2(2, get_y(event.position.y))
$Bar.rect_size = Vector2(rect_size.x - 12, 17)
func get_y(y):
var step = 22
var dy = tree.get_scroll().y
return floor(y / step) * step + 7 - dy + step * floor(dy / step)
func _on_Tree_mouse_exited():
$Bar.hide()
func _on_Tree_mouse_entered():
$Bar.show()
@andrew-wilkes

Copy link
Copy Markdown
Author

The Bar is a ColorRect with a material shader that makes the background area brighter.

`shader_type canvas_item;

void fragment() {
vec3 c = textureLod(SCREEN_TEXTURE, SCREEN_UV, 0.0).rgb;
if (c.r < 0.3 || c.g < 0.3 || c.b < 0.3) c *= 1.2;
COLOR.rgb = c;
}`

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