implement those two button s

This commit is contained in:
Erica Z 2024-12-03 22:27:48 +01:00
parent f72f3044c1
commit 24af7ff484

View file

@ -37,11 +37,11 @@ mod imp {
r#type: Cell<Type>,
client: RefCell<Option<crate::wrappers::Client>>,
refresh_button_inactive: Cell<bool>,
update_handle: Cell<Option<glib::JoinHandle<()>>>,
#[template_child]
scrolled: TemplateChild<gtk::ScrolledWindow>,
scroll_animation: OnceCell<adw::TimedAnimation>,
}
#[glib::object_subclass]
@ -115,6 +115,7 @@ mod imp {
}
pub fn update_model(&self) {
self.scroll_animation().pause();
self.model().remove_all();
let api = self.client.borrow();
@ -183,13 +184,35 @@ mod imp {
#[template_callback]
fn on_scroll_left_clicked(&self) {
let adj = self.scrolled.hadjustment();
adj.set_value(adj.value() - adj.page_size());
self.scroll_animation().pause();
self.scroll_animation().set_value_from(adj.value());
self.scroll_animation()
.set_value_to(adj.value() - adj.page_size());
self.scroll_animation().play();
}
#[template_callback]
fn on_scroll_right_clicked(&self) {
let adj = self.scrolled.hadjustment();
adj.set_value(adj.value() + adj.page_size());
self.scroll_animation().pause();
self.scroll_animation().set_value_from(adj.value());
self.scroll_animation()
.set_value_to(adj.value() + adj.page_size());
self.scroll_animation().play();
}
fn scroll_animation(&self) -> &adw::TimedAnimation {
self.scroll_animation.get_or_init(|| {
let adj = self.scrolled.hadjustment();
let target = adw::PropertyAnimationTarget::new(&adj, "value");
adw::TimedAnimation::new(
self.obj().as_ref(),
0.0,
0.0,
500, // ms
target,
)
})
}
}