@kasdeya i’m trying to make a custom ui element which accepts a list of arbitrary data, then binds that data to templates at runtime
its kinda like this (sorry if this is fucked up or doesnt make sense)
# a protocol defining some thing which can be bound to some property
class Bindable(Protocol):
def bind(value):
raise NotImplementedError
# data that can be bound to a bindable object
class Property(Protocol):
@property
def value(self):
raise NotImplementedError
def has_updated() -> bool:
return True
# some ui element which can be cloned/instantiated to make copies
class Template(Protocol):
def instantiate() -> Bindable:
raise NotImplementedError
class ListUi:
_data_source: list[Property]
_template: Template
_ui_elements: list[Bindable]
_capacity: int
_index: int
@property
def data_source(self):
return self._data_source
@property.setter
def data_source(self, value):
this._data_source = value
self.rebind_items()
def bind_items(self):
visible = self._data_source[index:self._capacity]
iter = zip(self._ui_elements, visible)
for element, item in iter:
element.bind(item.value)
basically i just want to have a list of properties that will update their respective bound template when they change. unity has a pretty featureful system for handling this but Got Damb its complicated
@rowan ohh I think I get it! so Bindable is a single item in the ListUi and it’s basically just a slot that you can put data into. and then Property is a class that abstracts the task of getting data and deciding if the UI needs to change (because the source that Property is pulling from changed)
but you have to do this using Unity’s UI library, so the task isn’t going to be anywhere near as simple as this example