-
Notifications
You must be signed in to change notification settings - Fork 27
Render Criteria
Assigning a render criteria allows you to selectively choose when a block should be rendered or not. For example, you usually don't want to render an image block if there is no image, or body text block if there is no body text. In these cases, use render_criteria
.
Criteria | When This Criteria Is Present | Example |
---|---|---|
Summary |
When the notification has some summary text (should always be true). | |
Body |
When the notification has some body text (not all notifications have body text). | |
HintImage |
When the notification has a hint image (Spotify album artwork, Discord profile picture). | |
AppImage |
When the notification has an app image (program icon). | |
AppName(name) |
When the notification app name is the same as name . |
|
Progress |
When the notification has a progress hint. | |
Urgency(urgency) |
When the notification urgency is the same as urgency . Either "low" , "normal" or "critical"
|
Urgency("low") |
Tag(tag) |
When the notification has the tag tag . |
Tag("music-notification") |
Note(note) |
When the notification has the note note . |
Note("mute") |
ActionDefault |
When the notification has a default action. | |
ActionOther(idx) |
When the notification has another action of index idx . See ButtonBlock for more information. |
|
And([Criteria]) |
When all of the [Criteria] are present. |
And([Body, AppName("Pidgin")]) |
Or([Criteria]) |
When at least one of the [Criteria] are present. |
Or([AppName("Pidgin"), AppName("Telegram")]) |
A block will render as long as at least one of the render_criteria
criteria matches, or if there are no render criteria.
As an example, in the above demo, if we only wanted to render the image block when an app image actually existed, we would do something like the following, for that block:
...
(
name: "image",
parent: "root",
hook: Hook(parent_anchor: TL, self_anchor: TL),
offset: Vec2(x: 0.0, y: 0.0),
render_criteria: [AppImage], // Only render this block when an AppImage is present.
params: ImageBlock((
image_type: App,
padding: Padding(left: 20.0, right: 20.0, top: 20.0, bottom: 20.0),
...
)),
),
There is also render_anti_criteria
, which does the opposite of render_criteria
: it tells a block not to render if any of the criteria are present. A prime use case for this is creating different layouts which draw under different conditions. For example, a layout for when an image hint is present, and a layout for when one is not. See the default wired.ron
for a concrete example.