Indeed, if you do position the handle and the content to overlap, they will overlap and the content would be rendered on top. I would hardly call that “by default” anymore.
With the styling I provided and adjusting the color of the row (normal and alternate and hover) to match the color of the item, I was able to get something matching what seemed to be your desired hover behaviour without needing to write code. If that was enough, it would be preferable than writing code to achieve the same thing. It seems it’s not enough for your use-case, my apologies.
Documentation says that if bindItem
and makeItem
are not set, Unity will try to bind to a SerializedProperty if bound, or simply set text in the created Label.
Given the snippet you provided:
// in CreateInspectorGUI
listView.bindItem += SendParentToBack;
// outside of CreateInspectorGUI
void SendParentToBack(VisualElement ele, int i)
{
ele.parent.SendToBack();
}
What happens here is that you set a binding behaviour, so the default inspector implementation assumes that you are taking charge and will not add a default one. So, essentially, your implementation is missing the actual binding code. Assuming that the element ele
is a PropertyField
in your snippet, you could do something like:
var property = serializedObject.FindProperty("yourPropertyPathHere").GetArrayElementAtIndex(i);
(ele as PropertyField).BindProperty(property);
Note that depending on the Unity version you are using, you might need to also implement the makeItem
callback for it to work. The default implementation returns a new PropertyField
. The documentation for the makeItem
is located here.
Now to answer your original question. If you take a look at the hierarchy that is created for a list view item, you will get:
#unity-list-view__reorderable-item
#unity-list-view__reorderable-handle
#unity-list-view__reorderable-item__container
#Your element is here
So, to get the reorderable item’s handle in code, you would need to do the equivalent of:
var handle = ele.parent.parent.Q(className:"unity-list-view__reorderable-handle);
This generated hierarchy for a list row is subject to change in the future, so you may want to look for a parent with the .unity-list-view__reorderable-item
class on it instead of simply doing parent.parent
Now, I would not advise you to do this, because it’s like turning right three times instead of turning left. With makeItem
and bindItem
properly implemented, ele.parent.SendToBack();
should be enough (and again here, the generated hierarchy is subject to change in the future).
Cheers!