Rule Definitions
Rule definitions for the Plasma SVG input are YAML files that describe how the SVGs from the Plasma style relate to Union style rules. Most importantly, they define what Selectors are used and what properties are set for the rules.
Rule definition files are located in the src/input/plasmasvg/definitions
directory. They are bundled into the Plasma SVG input plugin at build time. Each definition file should contain a mapping defining a set of style rules. The keys of this top-level mapping are not used but help with identifying separate rules when reading the files.
Each style rule is a mapping containing a key selectors
which contains a list of selectors for this style rule. It should also contain several property keys that define what value these properties have.
For example, the following defines two style rules, button
and button-hovered
. The first applies to any element that has a type of Button
. The second applies to any element that has a type of Button
and has the state Hovered
set. The button
rule sets the properties width
and height
of the layout
group to 50
. It also sets the background color to green
. The button-hovered
only sets the background color to blue
. Note that, at runtime, when hovering over a button, both rules will apply to the button. The end result will be that the button will be 50 by 50 pixels in size with a blue background color.
button: selectors: - type: Button layout: width: 50 height: 50 background: color: "green" button-hovered: selectors: - type: Button state: Hovered background: color: "blue"
Selectors
Selectors are defined as a list, with each element being a mapping. Each entry in this list creates a separate style rule. Each mapping in the list should contain keys that match certain element properties, such as type
. All the keys in the mapping must match an element for the rule to match.
The following keys are recognised:
- type A string that will match an element's type.
- id A string that will match an element's ID.
- state Either a string or a list of strings. Each string should be the name of a state in the State enum that will be matched to the state of an element. If multiple states are defined they all need to match.
- attributes A mapping containing key-value pairs that are matched to attributes of an element. If multiple pairs are defined they all need to match.
- child A mapping containing another rule definition mapping. The rule will only match elements that have a child that matches the child block of this selector.