Add Content Struct.

This commit is contained in:
Jordan Petridis 2017-12-01 01:12:25 +02:00
parent 774e5b38a0
commit dd0034327b
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
6 changed files with 67 additions and 5 deletions

View 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"
}
}

View File

@ -45,6 +45,7 @@ macro_rules! clone {
mod views;
mod widgets;
mod headerbar;
mod content;
mod utils;
mod static_resource;

View File

@ -2,7 +2,7 @@ use gtk;
#[derive(Debug, Clone)]
pub struct EmptyView {
container: gtk::Box,
pub container: gtk::Box,
}
impl EmptyView {

View File

@ -1 +1,2 @@
pub mod podcasts;
pub mod empty;

View File

@ -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,
}

View File

@ -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();