Add Content Struct.
This commit is contained in:
parent
774e5b38a0
commit
dd0034327b
60
hammond-gtk/src/content.rs
Normal file
60
hammond-gtk/src/content.rs
Normal file
@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -45,6 +45,7 @@ macro_rules! clone {
|
|||||||
mod views;
|
mod views;
|
||||||
mod widgets;
|
mod widgets;
|
||||||
mod headerbar;
|
mod headerbar;
|
||||||
|
mod content;
|
||||||
|
|
||||||
mod utils;
|
mod utils;
|
||||||
mod static_resource;
|
mod static_resource;
|
||||||
|
|||||||
@ -2,7 +2,7 @@ use gtk;
|
|||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct EmptyView {
|
pub struct EmptyView {
|
||||||
container: gtk::Box,
|
pub container: gtk::Box,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EmptyView {
|
impl EmptyView {
|
||||||
|
|||||||
@ -1 +1,2 @@
|
|||||||
pub mod podcasts;
|
pub mod podcasts;
|
||||||
|
pub mod empty;
|
||||||
|
|||||||
@ -11,7 +11,7 @@ use utils::get_pixbuf_from_path;
|
|||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct PopulatedView {
|
pub struct PopulatedView {
|
||||||
container: gtk::Box,
|
pub container: gtk::Box,
|
||||||
flowbox: gtk::FlowBox,
|
flowbox: gtk::FlowBox,
|
||||||
viewport: gtk::Viewport,
|
viewport: gtk::Viewport,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,8 +12,8 @@ use views::podcasts::update_podcasts_view;
|
|||||||
use utils::get_pixbuf_from_path;
|
use utils::get_pixbuf_from_path;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct PodcastWidget {
|
pub struct PodcastWidget {
|
||||||
container: gtk::Box,
|
pub container: gtk::Box,
|
||||||
cover: gtk::Image,
|
cover: gtk::Image,
|
||||||
title: gtk::Label,
|
title: gtk::Label,
|
||||||
description: gtk::TextView,
|
description: gtk::TextView,
|
||||||
@ -23,7 +23,7 @@ struct PodcastWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PodcastWidget {
|
impl PodcastWidget {
|
||||||
fn new() -> PodcastWidget {
|
pub fn new() -> PodcastWidget {
|
||||||
// Adapted from gnome-music AlbumWidget
|
// Adapted from gnome-music AlbumWidget
|
||||||
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/podcast_widget.ui");
|
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/podcast_widget.ui");
|
||||||
let container: gtk::Box = builder.get_object("podcast_widget").unwrap();
|
let container: gtk::Box = builder.get_object("podcast_widget").unwrap();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user