Properties
A group of settings in a layer's properties.
Each field sets the layer's value of the same key: one of the program's own (w, h, radius, color, opacity…) or one of the plugin's. kinds are the layers it shows for: paint, image, text, shape, group. The function is told of each change.
const SIZES: Record<string, number[]> = { Small: [80, 80], Medium: [200, 200], Large: [480, 480] };
// ...in the plugin:
properties: [{
key: 'quick', title: 'Quick size', kinds: ['shape'],
fields: [{ key: 'quick_size', label: 'Size', choices: Object.keys(SIZES), usual: 'Medium' }],
changed(api, id, key, value) {
const [w, h] = SIZES[String(value)] ?? SIZES.Medium;
api.project.set(id, { w, h }, false);
},
}],
from rassam import choice, slider
SIZES = {'Small': (80, 80), 'Medium': (200, 200), 'Large': (480, 480), 'Wide': (640, 160)}
@plugin.properties('Quick shape', kinds=['shape'],
fields=[choice('quick_size', 'Size', list(SIZES), 'Medium'), slider('radius', 'Corners', 0, 200, 0)])
def reshaped(app, id, key, value):
if key == 'quick_size':
w, h = SIZES[value]
app.set(id, undo=False, w=w, h=h)
A field whose key is one of the layer's own values needs no function at all: the group alone is enough.