Commit 8ad5bf6f authored by Jordan Petridis's avatar Jordan Petridis 🌱

ShowWidget: Retain vertical scrolling adjustment upon view refresh.

parent 112b61d3
......@@ -7,7 +7,8 @@
<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>
......
use gtk;
use gtk::Cast;
use gtk::prelude::*;
use hammond_data::Podcast;
......@@ -129,8 +130,30 @@ impl ShowStack {
}
pub fn replace_widget(&self, pd: &Podcast) {
let old = self.stack.get_child_by_name("widget").unwrap();
let old = self.stack
.get_child_by_name("widget")
// 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.
.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 new = ShowWidget::new(Arc::new(self.clone()), pd, self.sender.clone());
// Copy the vertical scrollbar adjustment from the old view into the new one.
scrolled_window
.get_vadjustment()
.map(|x| new.set_vadjustment(&x));
self.stack.remove(&old);
self.stack.add_named(&new.container, "widget");
......@@ -193,24 +216,27 @@ impl EpisodeStack {
}
pub fn update(&self) {
use gtk::Cast;
let old = self.stack
.get_child_by_name("episodes")
// 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.
.unwrap();
info!("Name: {:?}", WidgetExt::get_name(&old));
debug!("Name: {:?}", WidgetExt::get_name(&old));
let scrolled_window = old.get_children()
.first()
// This is guaranted to exist based on the episodes_view.ui file.
.unwrap()
.clone()
.downcast::<gtk::ScrolledWindow>()
// This is guaranted based on the episodes_view.ui file.
.unwrap();
info!("Name: {:?}", WidgetExt::get_name(&scrolled_window));
debug!("Name: {:?}", WidgetExt::get_name(&scrolled_window));
let eps = EpisodesView::new(self.sender.clone());
// Copy the vertical scrollbar adjustment from the old view into the new one.
scrolled_window
.get_vadjustment()
.map(|x| eps.set_vadjustment(&x));
......
......@@ -151,6 +151,7 @@ impl EpisodesView {
true
}
/// Set scrolled window vertical adjustment.
pub fn set_vadjustment(&self, vadjustment: &gtk::Adjustment) {
self.scrolled_window.set_vadjustment(vadjustment)
}
......
......@@ -21,6 +21,7 @@ use std::fs;
#[derive(Debug, Clone)]
pub struct ShowWidget {
pub container: gtk::Box,
scrolled_window: gtk::ScrolledWindow,
cover: gtk::Image,
description: gtk::Label,
link: gtk::Button,
......@@ -33,6 +34,7 @@ impl Default for ShowWidget {
fn default() -> Self {
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/show_widget.ui");
let container: gtk::Box = builder.get_object("container").unwrap();
let scrolled_window: gtk::ScrolledWindow = builder.get_object("scrolled_window").unwrap();
let episodes: gtk::Frame = builder.get_object("episodes").unwrap();
let cover: gtk::Image = builder.get_object("cover").unwrap();
......@@ -43,6 +45,7 @@ impl Default for ShowWidget {
ShowWidget {
container,
scrolled_window,
cover,
description,
unsub,
......@@ -104,6 +107,11 @@ impl ShowWidget {
let desc = dissolve::strip_html_tags(text).join(" ");
self.description.set_text(&replace_extra_spaces(&desc));
}
/// Set scrolled window vertical adjustment.
pub fn set_vadjustment(&self, vadjustment: &gtk::Adjustment) {
self.scrolled_window.set_vadjustment(vadjustment)
}
}
fn on_unsub_button_clicked(
......
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