Commit 299d2e8d authored by Jordan Petridis's avatar Jordan Petridis 🌱

ShowsView: Retain vertical scrolling adjustment upon view refresh.

parent 8ad5bf6f
Pipeline #1823 passed with stages
......@@ -3,16 +3,18 @@
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkBox" id="fb_parent">
<property name="name">fb_parent</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkScrolledWindow">
<object class="GtkScrolledWindow" id="scrolled_window">
<property name="name">scrolled_window</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkViewport" id="viewport">
<object class="GtkViewport">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
......
......@@ -111,9 +111,31 @@ impl ShowStack {
pub fn update_podcasts(&self) {
let vis = self.stack.get_visible_child_name().unwrap();
let old = self.stack.get_child_by_name("podcasts").unwrap();
let old = self.stack
.get_child_by_name("podcasts")
// This is guaranted to exists, based on `ShowStack::new()`.
.unwrap()
.downcast::<gtk::Box>()
// This is guaranted to be a Box based on the `ShowsPopulated` impl.
.unwrap();
debug!("Name: {:?}", WidgetExt::get_name(&old));
let scrolled_window = old.get_children()
.first()
// This is guaranted to exist based on the show_widget.ui file.
.unwrap()
.clone()
.downcast::<gtk::ScrolledWindow>()
// This is guaranted based on the show_widget.ui file.
.unwrap();
debug!("Name: {:?}", WidgetExt::get_name(&scrolled_window));
let pop = ShowsPopulated::new(Arc::new(self.clone()), self.sender.clone());
// Copy the vertical scrollbar adjustment from the old view into the new one.
scrolled_window
.get_vadjustment()
.map(|x| pop.set_vadjustment(&x));
self.stack.remove(&old);
self.stack.add_named(&pop.container, "podcasts");
......@@ -132,10 +154,10 @@ impl ShowStack {
pub fn replace_widget(&self, pd: &Podcast) {
let old = self.stack
.get_child_by_name("widget")
// This is guaranted to exists, based on ShowStack::new().
// This is guaranted to exists, based on `ShowStack::new()`.
.unwrap()
.downcast::<gtk::Box>()
// This is guaranted to be a Box based on the ShowWidget impl.
// This is guaranted to be a Box based on the `ShowWidget` impl.
.unwrap();
debug!("Name: {:?}", WidgetExt::get_name(&old));
......@@ -218,10 +240,10 @@ impl EpisodeStack {
pub fn update(&self) {
let old = self.stack
.get_child_by_name("episodes")
// This is guaranted to exists, based on EpisodeStack::new().
// This is guaranted to exists, based on `EpisodeStack::new()`.
.unwrap()
.downcast::<gtk::Box>()
// This is guaranted to be a Box based on the EpisodesView impl.
// This is guaranted to be a Box based on the `EpisodesView` impl.
.unwrap();
debug!("Name: {:?}", WidgetExt::get_name(&old));
......
......@@ -15,21 +15,21 @@ use std::sync::Arc;
#[derive(Debug, Clone)]
pub struct ShowsPopulated {
pub container: gtk::Box,
scrolled_window: gtk::ScrolledWindow,
flowbox: gtk::FlowBox,
viewport: gtk::Viewport,
}
impl Default for ShowsPopulated {
fn default() -> Self {
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/shows_view.ui");
let container: gtk::Box = builder.get_object("fb_parent").unwrap();
let scrolled_window: gtk::ScrolledWindow = builder.get_object("scrolled_window").unwrap();
let flowbox: gtk::FlowBox = builder.get_object("flowbox").unwrap();
let viewport: gtk::Viewport = builder.get_object("viewport").unwrap();
ShowsPopulated {
container,
scrolled_window,
flowbox,
viewport,
}
}
}
......@@ -74,6 +74,11 @@ impl ShowsPopulated {
pub fn is_empty(&self) -> bool {
self.flowbox.get_children().is_empty()
}
/// Set scrolled window vertical adjustment.
pub fn set_vadjustment(&self, vadjustment: &gtk::Adjustment) {
self.scrolled_window.set_vadjustment(vadjustment)
}
}
#[derive(Debug)]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment