Add MinItems and MaxItems properties to ListDrawerSettingsAttribute
It would be really helpful if one could specify the min and max number of elements allowed for a list. To make this general, I would think ListDrawerSettingsAttribute
should expose new MinItems
and MaxItems
properties. I tried making this work with the current APIs (v3.0.12.0 on Windows 11 Pro) via CustomAddFunction
and CustomRemoveFunction
, but these properties are poorly documented so I wasn’t really sure how to use them, and I think I’m running into issue #437 anyway.
Comments (3)
-
-
reporter Antonio, thanks for description, that was very helpful! All of this seems like information that should be in the docs….maybe I missed it. Is there a page other than this one that already had this info?
-
The documentation around resolvers is a bit lacking right now, but there are a few things that can help with them.
- You always have access to the InspectorProperty and the value so those are fixed. That information is listed here: https://odininspector.com/tutorials/value-and-action-resolvers/named-values
- You can define a parameter that you know/think is not part of the named values and then you will get an error message in the inspector that shows you all possible values and their types.
I understand that this is by no means perfect, but other things kind of took the attention If you have questions about something then the discord is a great place to ask as it’s usuall easier to see and answer there.
I’ve written down all your suggestions from this and the other ticket and I’m going to write down something for the docs that will then hopefully be available there.
- Log in to comment
If you’re using the TableList attribute, then yes, you won’t be able to use the ListDrawerSettings attribute since they’re not compatible.
The CustomAddFunction and CustomRemoveElementFunction / CustomRemoveIndexFunction work like this:
When Odin detects that you want to add or remove an element, it will call the respective function and pass it the arguments that you’ve specified. Valid arguments are:
InspectorProperty property
,List<T> list
where T will be the type your list holds.InspectorProperty property
,List<T> list
,int index
where T will be the type your list holds.InspectorProperty property
,List<T> list
,T elementToBeRemoved
where T will be the type your list holds.Example: