diff --git a/hammond-gtk/src/content.rs b/hammond-gtk/src/content.rs new file mode 100644 index 0000000..85cd98f --- /dev/null +++ b/hammond-gtk/src/content.rs @@ -0,0 +1,60 @@ +use gtk; +use gtk::prelude::*; +// use gdk_pixbuf::Pixbuf; + +// use diesel::Identifiable; + +// use hammond_data::dbqueries; +// use hammond_data::Podcast; + +use widgets::podcast::PodcastWidget; +use views::podcasts::PopulatedView; +use views::empty::EmptyView; + +#[derive(Debug)] +pub struct Content { + pub stack: gtk::Stack, + pub state: ContentState, + widget: PodcastWidget, + podcasts: PopulatedView, + empty: EmptyView, +} + +#[derive(Debug)] +pub enum ContentState { + Widget(PodcastWidget), + Empty(EmptyView), + Populated(PopulatedView), +} + +impl Content { + pub fn new() -> Content { + let stack = gtk::Stack::new(); + let widget = PodcastWidget::new(); + let pop = PopulatedView::new(); + let empty = EmptyView::new(); + // TODO: Avoid cloning + let state = ContentState::Populated(pop.clone()); + + let content = Content { + stack, + state, + widget, + empty, + podcasts: pop, + }; + + content.setup_stack(); + content.podcasts.init(&content.stack); + content + } + + fn setup_stack(&self) { + self.stack + .set_transition_type(gtk::StackTransitionType::SlideLeftRight); + + self.stack.add_named(&self.widget.container, "pdw"); // Rename into "widget" + self.stack.add_named(&self.podcasts.container, "fb_parent"); // Rename into "podcasts" + self.stack.add_named(&self.empty.container, "empty"); // Rename into "empty" + } +} diff --git a/hammond-gtk/src/main.rs b/hammond-gtk/src/main.rs index 15dfb31..56e089a 100644 --- a/hammond-gtk/src/main.rs +++ b/hammond-gtk/src/main.rs @@ -45,6 +45,7 @@ macro_rules! clone { mod views; mod widgets; mod headerbar; +mod content; mod utils; mod static_resource; diff --git a/hammond-gtk/src/views/empty.rs b/hammond-gtk/src/views/empty.rs index c45ef47..1c93da7 100644 --- a/hammond-gtk/src/views/empty.rs +++ b/hammond-gtk/src/views/empty.rs @@ -2,7 +2,7 @@ use gtk; #[derive(Debug, Clone)] pub struct EmptyView { - container: gtk::Box, + pub container: gtk::Box, } impl EmptyView { diff --git a/hammond-gtk/src/views/mod.rs b/hammond-gtk/src/views/mod.rs index 398798f..9c47e7d 100644 --- a/hammond-gtk/src/views/mod.rs +++ b/hammond-gtk/src/views/mod.rs @@ -1 +1,2 @@ pub mod podcasts; +pub mod empty; diff --git a/hammond-gtk/src/views/podcasts.rs b/hammond-gtk/src/views/podcasts.rs index a3de458..fee922a 100644 --- a/hammond-gtk/src/views/podcasts.rs +++ b/hammond-gtk/src/views/podcasts.rs @@ -11,7 +11,7 @@ use utils::get_pixbuf_from_path; #[derive(Debug, Clone)] pub struct PopulatedView { - container: gtk::Box, + pub container: gtk::Box, flowbox: gtk::FlowBox, viewport: gtk::Viewport, } diff --git a/hammond-gtk/src/widgets/podcast.rs b/hammond-gtk/src/widgets/podcast.rs index f40bea2..68a940e 100644 --- a/hammond-gtk/src/widgets/podcast.rs +++ b/hammond-gtk/src/widgets/podcast.rs @@ -12,8 +12,8 @@ use views::podcasts::update_podcasts_view; use utils::get_pixbuf_from_path; #[derive(Debug)] -struct PodcastWidget { - container: gtk::Box, +pub struct PodcastWidget { + pub container: gtk::Box, cover: gtk::Image, title: gtk::Label, description: gtk::TextView, @@ -23,7 +23,7 @@ struct PodcastWidget { } impl PodcastWidget { - fn new() -> PodcastWidget { + pub fn new() -> PodcastWidget { // Adapted from gnome-music AlbumWidget let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/podcast_widget.ui"); let container: gtk::Box = builder.get_object("podcast_widget").unwrap();