diff --git a/data/resources/ui/feed_list.ui b/data/resources/ui/feed_list.ui index 381aa36..a9b3830 100644 --- a/data/resources/ui/feed_list.ui +++ b/data/resources/ui/feed_list.ui @@ -9,51 +9,28 @@ True GTK_ALIGN_FILL - + GTK_POLICY_NEVER + + - + - - vertical + + + 5 + 5 + 5 + 5 + True - GTK_ALIGN_FILL + GTK_ALIGN_START True GTK_ALIGN_FILL - - - - 5 - 5 - 5 - 5 - - True - GTK_ALIGN_START - True - GTK_ALIGN_FILL - - visible - - - - - - - - - Load more - False - GTK_ALIGN_FILL - True - GTK_ALIGN_FILL - feed.more - - diff --git a/src/gui/feed/feed_list.rs b/src/gui/feed/feed_list.rs index e29fde8..9dee48e 100644 --- a/src/gui/feed/feed_list.rs +++ b/src/gui/feed/feed_list.rs @@ -22,11 +22,15 @@ use std::cmp::min; use gdk::{ gio::{SimpleAction, SimpleActionGroup}, + glib, glib::clone, prelude::{ActionMapExt, ListModelExt, ObjectExt, ToValue}, subclass::prelude::ObjectSubclassIsExt, }; -use gtk::traits::WidgetExt; +use gtk::{ + traits::{AdjustmentExt, WidgetExt}, + Adjustment, +}; use tf_join::AnyVideo; use tf_playlist::PlaylistManager; @@ -64,6 +68,20 @@ impl FeedList { actions.add_action(&action_more); } + fn setup_autoload(&self) { + let adj = self.imp().scrolled_window.vadjustment(); + adj.connect_changed(clone!(@weak self as s => move |adj| { + s.load_if_screen_not_filled(adj); + })); + } + + fn load_if_screen_not_filled(&self, adj: &Adjustment) { + if self.property("more-available") && adj.upper() <= adj.page_size() { + // The screen is not yet filled. + let _ = self.activate_action("feed.more", None); + } + } + pub fn set_items(&self, new_items: Vec) { let imp = self.imp(); let items = &imp.items; @@ -142,6 +160,7 @@ pub mod imp { use gtk::glib; use gtk::prelude::*; use gtk::subclass::prelude::*; + use gtk::PositionType; use gtk::SignalListItemFactory; use gtk::Widget; @@ -159,7 +178,7 @@ pub mod imp { #[template_child] pub(super) feed_list: TemplateChild, #[template_child] - load_more: TemplateChild, + pub(super) scrolled_window: TemplateChild, pub(super) items: RefCell>, pub(super) model: RefCell, @@ -205,6 +224,18 @@ pub mod imp { video_object.play(); }); + + self.instance().setup_autoload(); + } + } + + #[gtk::template_callbacks] + impl FeedList { + #[template_callback] + fn edge_reached(&self, pos: PositionType) { + if pos == PositionType::Bottom { + let _ = WidgetExt::activate_action(&self.instance(), "feed.more", None); + } } } @@ -216,6 +247,7 @@ pub mod imp { fn class_init(klass: &mut Self::Class) { Self::bind_template(klass); + Self::bind_template_callbacks(klass); } fn instance_init(obj: &InitializingObject) {