38 lines
No EOL
924 B
Python
38 lines
No EOL
924 B
Python
from typing import Any
|
|
import bpy
|
|
|
|
class DrawCollectionMixin():
|
|
items: Any = None
|
|
|
|
def draw_collection(self, items, layout):
|
|
col = layout.column(align=True)
|
|
for item in items:
|
|
item.draw_item(col)
|
|
|
|
def _draw_prop(self, text, layout):
|
|
self.draw_collection(self.items, layout)
|
|
|
|
def update_collection(items: Any) -> None:
|
|
if len(items) == 0:
|
|
items.add()
|
|
|
|
if items[-1].is_active:
|
|
items.add()
|
|
|
|
while len(items) >= 2:
|
|
if not items[-1].is_active and not items[-2].is_active:
|
|
items.remove(len(items) - 1)
|
|
else:
|
|
break
|
|
|
|
class UpdateCollectionMixin():
|
|
items: Any = None
|
|
|
|
def __init__(self, *args, **kwargs) -> None:
|
|
super().__init__(*args, **kwargs)
|
|
self.update()
|
|
|
|
def update(self):
|
|
update_collection(self.items)
|
|
|
|
class CollectionMixin(DrawCollectionMixin, UpdateCollectionMixin): ... |