Ignore the stack state machine until TryInto trait is stabilized.

This commit is contained in:
Jordan Petridis 2017-12-08 10:00:21 +02:00
parent 48e61c6377
commit 5b19274e6a
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
2 changed files with 26 additions and 11 deletions

View File

@ -17,7 +17,7 @@ pub struct Content {
}
impl Content {
fn new() -> Content {
pub fn new() -> Content {
let stack = gtk::Stack::new();
let widget = PodcastWidget::new();
@ -36,6 +36,22 @@ impl Content {
}
}
pub fn new_initialized() -> Content {
let ct = Content::new();
ct.init();
ct
}
pub fn init(&self) {
self.podcasts.init(&self.stack);
if self.podcasts.flowbox.get_children().is_empty() {
self.stack.set_visible_child_name("empty");
return
}
self.stack.set_visible_child_name("podcasts");
}
fn replace_widget(&mut self, pdw: PodcastWidget) {
let vis = self.stack.get_visible_child_name().unwrap();
let old = self.stack.get_child_by_name("widget").unwrap();
@ -60,6 +76,8 @@ impl Content {
}
#[derive(Debug)]
// Experiementing with Wrapping gtk::Stack into a State machine.
// Gonna revist it when TryInto trais is stabilized.
pub struct ContentState<S> {
content: Content,
state: S,
@ -153,6 +171,7 @@ impl UpdateView for ContentState<WidgetsView> {
}
impl ContentState<PodcastsView> {
#[allow(dead_code)]
pub fn new() -> Result<ContentState<PodcastsView>, ContentState<Empty>> {
let content = Content::new();
@ -173,6 +192,7 @@ impl ContentState<PodcastsView> {
})
}
#[allow(dead_code)]
pub fn get_stack(&self) -> gtk::Stack {
self.content.stack.clone()
}
@ -192,14 +212,6 @@ fn replace_podcasts(stack: &gtk::Stack, pop: &PopulatedView) {
old.destroy();
}
// This won't ever be needed probably
// pub fn replace_empty(stack: &gtk::Stack, emp: &EmptyView ) {
// let old = stack.get_child_by_name("empty").unwrap();
// stack.remove(&old);
// stack.add_named(&emp.container, "empty");
// old.destroy();
// }
#[allow(dead_code)]
pub fn show_widget(stack: &gtk::Stack) {
stack.set_visible_child_name("widget")

View File

@ -64,8 +64,11 @@ fn build_ui(app: &gtk::Application) {
window.set_default_size(1150, 650);
// TODO: this will blow horribly
let ct = content::ContentState::new().unwrap();
let stack = ct.get_stack();
// let ct = content::ContentState::new().unwrap();
// let stack = ct.get_stack();
let ct = content::Content::new_initialized();
let stack = ct.stack;
window.add(&stack);
window.connect_delete_event(|w, _| {