component¶
警告
这部分内容涉及 JAnim 实现原理,可能较为复杂,若没有研究源码的需求,你应酌情阅读
- class janim.components.component.Component¶
基类:
Refreshable,Generic- class BindInfo(decl_cls: type[Item], at_item: Item, key: str)¶
基类:
object对组件定义信息的封装
decl_cls: 以xxx = CmptInfo(...)的形式被声明在哪个类中; 如果一个类及其父类都有xxx = CmptInfo(...),那么decl_cls是父类at_item: 这个组件对象是属于哪个物件对象的key: 这个组件对象的变量名
例:
class MyCmpt(Component): ... class MyItem(Item): cmpt1 = CmptInfo(MyCmpt[Self]) cmpt2 = CmptInfo(MyCmpt[Self]) class MyItem2(MyItem): cmpt3 = CmptInfo(MyCmpt[Self]) item = MyItem() # item.cmpt1.bind_info 与 BindInfo(MyItem, item, 'cmpt1') 一致 # item.cmpt2.bind_info 与 BindInfo(MyItem, item, 'cmpt2') 一致 item2 = MyItem2() # item2.cmpt1.bind_info 与 BindInfo(MyItem, item2, 'cmpt1') 一致 # item2.cmpt3.bind_info 与 BindInfo(MyItem2, item2, 'cmpt3') 一致
- key: str¶
- fallback_check() bool¶
- mark_refresh(func: Callable | str, *, recurse_up=False, recurse_down=False) Self¶
- copy() Self¶
- become(other) Self¶
- not_changed(other) bool¶
- walk_same_cmpt_of_self_and_descendants_without_mock(root_only: bool = False, *, timed: bool = False) Generator[Self, None, None]¶
- walk_same_cmpt_of_descendants_without_mock(*, timed: bool = False) Generator[Self, None, None]¶
- property r: ItemT¶
所位于的物件,便于链式调用同物件下其它的组件
- classmethod align_for_interpolate(cmpt1, cmpt2) AlignedData[Self]¶
- interpolate(cmpt1, cmpt2, alpha: float, *, path_func=None) None¶
- class janim.components.component.CmptInfo(cls: type[T], *args, **kwargs)¶
基类:
Generic在类中定义组件需要使用该类
例:
class MyItem(Item): # Wrong! # cmpt1 = MyCmpt() # Right cmpt1 = CmptInfo(MyCmpt[Self]) # Wrong! # cmpt2 = MyCmptWithArgs(1) # Right cmpt2 = CmptInfo(MyCmptWithArgs[Self], 1)
- janim.components.component.CmptGroup(*cmpt_info_list: CmptInfo) CmptInfo¶
用于将多个组件打包,使得可以同时调用
例:
class MyItem(Item): stroke = CmptInfo(Cmpt_Rgbas[Self]) fill = CmptInfo(Cmpt_Rgbas[Self]) color = CmptGroup(stroke, fill) item = MyItem() item.stroke.set(...) # 只有 stroke 的被调用 | Only the method of stroke be called item.color.set(...) # stroke 和 fill 的都被调用了 | the methods of stroke and fill are both called