Skip to content

Commit dfc8cb9

Browse files
authored
Merge pull request #882 from Video-Nomad/chore/css-animations-docs
chore(docs): css engine styling docs update
2 parents 5cc194c + a7b1c65 commit dfc8cb9

1 file changed

Lines changed: 85 additions & 1 deletion

File tree

docs/Styling.md

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,92 @@ Example how to target widget container
7979
```
8080

8181
> **Note:**
82-
> Keep in mind that YASB is written in Python and styled with very limited CSS. You can't use CSS3 or any other advanced CSS features.
82+
> Keep in mind that YASB is written in Python using Qt framework and utilizes a custom CSS engine, so styling might be different from regular CSS3.
8383

84+
## Animations
85+
Animations can be added to widgets using [transition](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/transition) property. It follows the same syntax as CSS transitions, but uses custom [animation engine](https://github.com/Video-Nomad/qt-css-engine) for PyQt6/PySide6.
86+
87+
Example of simple color transition on hover:
88+
```css
89+
.glazewm-workspaces .ws-btn {
90+
/* other properties... */
91+
background: transparent;
92+
transition: background 200ms ease-in-out;
93+
}
94+
95+
.glazewm-workspaces .ws-btn:hover {
96+
/* This will be animated on mouse hover */
97+
background: gray;
98+
}
99+
```
100+
Example of widget size and background transition on class change using `all` keyword and padding:
101+
```css
102+
.glazewm-workspaces .ws-btn {
103+
/* other properties... */
104+
padding: 1px 4px;
105+
transition: all 200ms ease-out;
106+
}
107+
108+
.glazewm-workspaces .ws-btn.focused_populated,
109+
.glazewm-workspaces .ws-btn.focused_empty {
110+
/* These two properties be animated on workspace change */
111+
pading: 1px 50px;
112+
background: gray;
113+
}
114+
```
115+
Same can be done with `width` and `height` properties, or `min/max-width` and `min/max-height` if widget requires that (usually when nested widgets are involved, like GlazeWM with icons):
116+
```css
117+
.glazewm-workspaces .ws-btn {
118+
/* other properties */
119+
transition: all 200ms ease-out;
120+
}
121+
122+
.glazewm-workspaces .ws-btn.focused_populated,
123+
.glazewm-workspaces .ws-btn.focused_empty {
124+
/* Size will be animated from the default to the min/max values*/
125+
min-width: 50px;
126+
max-width: 50px;
127+
}
128+
```
129+
Global opacity transition for all widget containers to add subtle fade effect on click:
130+
```css
131+
.widget-container {
132+
opacity: 1.0;
133+
transition: opacity 80ms;
134+
}
135+
136+
.widget-container:clicked,
137+
.widget-container:pressed {
138+
opacity: 0.5;
139+
}
140+
```
141+
A `delay` can also be added to the transition as second time variable `transition: all 200ms 50ms ease-out`. Negative delay will result in animation starting instantly, but as if it was playing for the time of the delay.
142+
143+
Easing functions can be used as well, for example `ease-in-out` or `cubic-bezier(0.5, 0.2, 0.3, 0.9)`. Check this tool for [cubic-bezier](https://cubic-bezier.com) visualization.
144+
145+
[Steps](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/easing-function/steps) function is also supported.
146+
147+
## Animation-supported pseudo-classes
148+
- `:hover`
149+
- `:focus`
150+
- `:active` (Window focus pseudo. Not the same as `:active` in regular CSS)
151+
- `:pressed` (Equivalent to `:active` in regular CSS)
152+
- `:checked`
153+
- `:clicked` (Special case. Will play the full animation on click)
154+
155+
## Additional supported CSS properties
156+
- `opacity`
157+
- `box-shadow`
158+
- `text-shadow`
159+
- `cursor` (not animatable)
160+
161+
## Animation limitations
162+
Animations can't be added to sub-controls, for example `::item` or `::chunk` or others. Only regular QtCSS styling is available for those.
163+
164+
## Supported color functions (not animatable)
165+
- `linear-gradient()`
166+
- `radial-gradient()`
167+
- `conic-gradient()`
84168

85169
## Follow OS Theme
86170
YASB can follow the OS theme, if you have OS dark style YASB will add class `.dark` on the root element, if you want to have different light and dark themes you can use the following CSS to achieve this.

0 commit comments

Comments
 (0)