Itās at least ā¦ unusual and a matter of opinion. I donāt even know if it would work at all but I can do some tests in the next days. A feature request is also a good idea, maybe there even exists one already (I also plan on contacting the author of the Scattering addon to maybe get some insight about how the preference editor thing works, maybe it uses a similar solution).
Sorry, there is again a big wall of text coming (beware of the two meanings of property as in āProperties Editorā and ācustom propertyā):
Because I left out many details: UI drawing methods like layout.prop()
require a property that is āsynchronizedā with the drawing. Blenderās data system only allows properties for ID blocks and some hand-picked other types like the addonās preferences. So the value of the property belongs to the instance that actually holds the property, it can be an object for example or the entire window manager (like a global instance, but it isnāt saved. Thatās why we have the āArmā world). When drawing the property, you always need to pass that instance as well (like instance.value
as in any programming language).
Because areas/regions canāt hold properties, we either need one instance of some type for any open properties editor or we need to have as many enum properties (all the tabs are stored in an enum) in the window manager instance as we have editors. I would go for the latter because we then donāt have to deal with data blocks the user can edit by accident. It is possible to hide text blocks (I used it a few years ago), so that could work as well. Maybe we can even replace the āArmā world with that and add a small API for it for easier access.
Then, we need a way to identify each editor and give it a unique id (via pointer or hash()
) and map each properties editor to a enum property that holds the current tab for that editor. The mapping should be calculated fast because it must be calculated in each drawing of the editor because we need to tell the draw functions which enum we wanāt to draw. The same goes for the poll()
functions, so that the correct panels show up depending on the current editor context.
The most difficult part I guess is to react to new/closed editors and to create the enum property accordingly. I donāt know if this is possible with the msgbus
module but I donāt think so, there is no logging in the info editor when opening a new editor. So again, a workaround is required. You could add some lines to the poll function of each property editorās draw function that checks if the editor is āregisteredā/mapped yet to fake a listener and if not, create a property for it. But what to do with closing properties editors? It will create more properties and requires more and more memory until you close Blender if we donāt cleanup after a properties editor is closed. So we need yet another workaround here. But I didnāt research yet if somebody already found a solution for this, maybe weāre lucky and it is possible
So yeah, this is a bunch of code that has to be well-documented and I have no idea if it works and if it is fast. But the idea of having an own editor panel and being the first addon which does this is quite tempting of course
Edit: You could probably listen to changes in the length of the areas
or regions
attribute of the current screen (I always confuse area
with region
, sorry^^). But I donāt think it works as changing the length of a collection does not really update the attribute value (the collection object remains the same). Letās test that.