ImGui: How to customize ObjectEditor for generic data types?

Continuing from the thread on Element, here my question again surrounding the ObjectEditor in the ImGui library in VL.

In the help patch for the object editor we can see how to create a custom interface for our own datatypes, but I am curious how I would customize something for one of the generic datatypes.

My example would be paths, which appear a few times in my settings that I want to use the Object editor for. Currently paths are just shown as labels and cannot be edited. I would want to add a button next to the path where you can pick a new path. I want to change it once for every instance of a path in the provided datatype. I usually use folder paths and not file paths, but I guess it would need to be able to do both.

Thanks for any hints on how to do that.

You can start from the help patch “Build a custom editor” and create an editor operating on Channel<Path>. The system should subsequently pick that editor up for any properties of type Path and use it in all instances of any ObjectEditor.

Should you need more control over when your custom editor for a built-in datatype should be used, you can also implement the IObjectEditorFactory interface and feed your own factory to the editor via its hidden Factory input. But I’d leave that exercise for when you really need it.

Attached is an example patch taking the straight forward approach.
PathEditor.vl (29.0 KB)

1 Like

Thanks @Elias, that’s genius and exactly what I was after. So the channel input in the CreateObjectEditor is the deciding factor for when this is being used?

Just a few more questions for my understanding:

  1. What would it look like if I want to have multiple different Editors? So say one custom one for path, but also still another custom one for another custom datatype?

  2. Does this also work for nested datatypes? Like say I have a custom datatype that also contains a path. What would it look like and is it possible?

  3. Lastly, What dictates the order in the UI. Is it sorted alphabetically? I noticed in your example pins 1 and 2 do not translate to the order in the UI.

Thanks for your insights!

  1. You’d just add more editors and register them by defining a new CreateObjectEditor operation taking the channel of your custom type, for example Channel<Path> or like in the help patch Channel<Person>. Basically you end up with multiple CreateObjectEditor overloads. Reason here is that the default editor factory makes use of VL’s adaptive node mechanism. If that sounds too magical for you, you could opt to the custom editor factory like I mentioned initially.
  2. Yes. Once an editor for Channel<Path> is registered, it will always be used for any property of type Path.
  3. Good point. It currently uses IVLTypeInfo.Properties which in turn orders them by name. We’d need to use/add an attribute (like DisplayAttribute) to define the order. We have a similar request already, will add this one there.
1 Like

There was a typo in my previous post - it was saying “any property of type Channel<Path>” while it should’ve said “any property of type Path”.