Last active
June 25, 2020 09:57
-
-
Save andrew-wilkes/e49cde5fa18db6e25ecd6771ab311fa0 to your computer and use it in GitHub Desktop.
Godot TreeItem Highlight Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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;
}`