Skip to content

Commit ed77c59

Browse files
committed
Animate warning icon
1 parent 8497451 commit ed77c59

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/application.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,23 @@ mod imp {
136136
font-size: 0.8em;
137137
padding: 0.2em 0.2em;
138138
}}
139+
140+
@keyframes pop-warning {{
141+
0% {{
142+
transform: scale(1.0);
143+
}}
144+
30% {{
145+
transform: scale(1.2) rotateZ(20deg);
146+
}}
147+
70% {{
148+
transform: scale(1.4) rotateZ(-15deg);
149+
}}
150+
}}
151+
152+
.task-warning {{
153+
animation: pop-warning 1s;
154+
animation-iteration-count: 3;
155+
}}
139156
"));
140157
// We give the CssProvided to the default screen so the CSS rules we added
141158
// can be applied to our window.

src/tasks_button.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use gtk::{
88
glib::{self},
99
};
1010
use std::cell::RefCell;
11+
use std::time::Duration;
1112

1213
use glib::clone;
1314

@@ -81,7 +82,7 @@ mod imp {
8182
break;
8283
}
8384
}
84-
this_clone.imp().warning_icon.set_visible(has_warning);
85+
this_clone.set_has_warning(has_warning);
8586

8687
// Listen when a new task will fail
8788
for i in position..position + added {
@@ -91,7 +92,7 @@ mod imp {
9192
let this_clone = this_clone.clone();
9293
item.connect_status_notify(move |item| {
9394
if item.is_failed() {
94-
this_clone.imp().warning_icon.set_visible(true);
95+
this_clone.set_has_warning(true);
9596
}
9697
});
9798
}
@@ -117,4 +118,14 @@ impl TasksButton {
117118
.property("root-store", root_store)
118119
.build()
119120
}
121+
pub fn set_has_warning(&self, has_warning: bool) {
122+
self.imp().warning_icon.set_visible(has_warning);
123+
// trigger the animation
124+
self.imp().warning_icon.remove_css_class("task-warning");
125+
let this = self.clone();
126+
glib::timeout_add_local_full(Duration::from_millis(100), glib::Priority::LOW, move || {
127+
this.imp().warning_icon.remove_css_class("task-warning");
128+
glib::ControlFlow::Break
129+
});
130+
}
120131
}

0 commit comments

Comments
 (0)