Developer Wiki

In-depth guide for developers to create stencils and templates

Tips and Tricks

1. Visibility and Transform

There are two universal behaviors in Pencil that can be applied to any type of objects:


<Visibility>...</Visibility>
<Transform>...</Transform>

2. Forced dependencies

Upon changes of a specific property, all elements that has at least one behavior refers to that property will be invalidated and the behavior code will be executed. In some special case, you may want a specific behavior to be executed when a specific property changes even when that property is not explicitly referenced. In this case, adding a comment in the syntax of //depends $propertyName will help.


<For ref="text">
  <TextContent>new PlainText("Hello World")</TextContent>
  <Fill>Color.fromString("#000000ff")</Fill>
  <Font>new Font()</Font>
  <BoxFit>
    <Arg>new Bound(0, 0, 100, 12) //depends $textColor</Arg>
    <Arg>new Alignment(0, 1)</Arg>
  </BoxFit>
</For>