2024-09-22 20:23:57 发布
网友
我最近在杂乱中发现了constraints,但是,我找不到关于如何按比例约束actor大小的信息。例如,我希望一个演员的宽度保持在另一个演员的1/2,比如说它是父演员。它似乎只能强制宽度与源缩放100%。你知道吗
Clutter.BindConstraint匹配源参与者的位置和/或维度属性。对于分数定位,可以使用Clutter.AlignConstraint,但是没有Clutter.Constraint类允许您设置分数维属性。您可以通过子类化Clutter.Constraint并重写Clutter.Constraint.do_update_allocation()虚函数来实现自己的ClutterConstraint,该虚函数传递应该由约束修改的参与者的分配。类似于此(未经测试)代码的内容应该可以工作:
Clutter.BindConstraint
Clutter.AlignConstraint
Clutter.Constraint
Clutter.Constraint.do_update_allocation()
ClutterConstraint
class MyConstraint (Clutter.Constraint): def __init__(self, source, width_fraction=1.0, height_fraction=1.0): Clutter.Constraint.__init__(self) self._source = source self._widthf = width_fraction self._heightf = height_fraction def do_update_allocation(self, actor, allocation): source_alloc = self._source.get_allocation() width = source_alloc.get_width() * self._widthf height = source_alloc.get_height() * self._heightf allocation.x2 = allocation.x1 + width allocation.y2 = allocation.y1 + height
这应该说明Clutter.Constraint用来修改参与者分配的机制。你知道吗
Clutter.BindConstraint
匹配源参与者的位置和/或维度属性。对于分数定位,可以使用Clutter.AlignConstraint
,但是没有Clutter.Constraint
类允许您设置分数维属性。您可以通过子类化Clutter.Constraint
并重写Clutter.Constraint.do_update_allocation()
虚函数来实现自己的ClutterConstraint
,该虚函数传递应该由约束修改的参与者的分配。类似于此(未经测试)代码的内容应该可以工作:这应该说明
Clutter.Constraint
用来修改参与者分配的机制。你知道吗相关问题 更多 >
编程相关推荐