carousel: Does not scroll to other child if first child is shown
Might be very well a duplicate of #457 (closed)
scroll_to()
does not work if the first page is active. However, it actually works if it is delayed to adding the child:
carousel.append(&label);
// THIS ONE DOES NOT WORK
carousel.scroll_to(&label, true);
let carousel = carousel.clone();
// THIS ONE DOES WORK
adw::glib::timeout_add_local_once(std::time::Duration::from_secs(1), move || {
carousel.scroll_to(&label, true)
});
Complete reproducer
use adw::prelude::*;
fn main() {
let application = adw::Application::builder()
.application_id("com.example.CarouselTest")
.build();
application.connect_activate(|app| {
let content = gtk::Box::new(gtk::Orientation::Vertical, 0);
content.append(&adw::HeaderBar::new());
let carousel = adw::Carousel::new();
carousel.append(>k::Label::builder().label("1").hexpand(true).build());
content.append(&carousel);
let button1 = gtk::Button::builder().label("Add and Scroll").build();
button1.connect_clicked(move |_| {
let label = gtk::Label::builder().label("2").hexpand(true).build();
carousel.append(&label);
// THIS ONE DOES NOT WORK
carousel.scroll_to(&label, true);
let carousel = carousel.clone();
// THIS ONE DOES WORK
adw::glib::timeout_add_local_once(std::time::Duration::from_secs(1), move || {
carousel.scroll_to(&label, true)
});
});
content.append(&button1);
let window = adw::ApplicationWindow::builder()
.application(app)
.title("Carousel Test")
.content(&content)
.build();
window.show();
});
application.run();
}