From 41b0a36b81d08be92e023656d8ed8c3895aa7758 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Thu, 7 Dec 2017 11:14:12 +0200 Subject: [PATCH] Implement Into ContentState types. --- hammond-gtk/src/content.rs | 57 ++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 33 deletions(-) diff --git a/hammond-gtk/src/content.rs b/hammond-gtk/src/content.rs index be858f0..d022c05 100644 --- a/hammond-gtk/src/content.rs +++ b/hammond-gtk/src/content.rs @@ -74,19 +74,20 @@ struct WidgetsView { content: Content } -impl Empty { - fn into_podcasts(self) -> Result { - if self.content.podcasts.flowbox.get_children().is_empty() { - return Err(self); - } +#[derive(Debug)] +pub enum ContentState { + empty(Empty), + pop(PodcastsView), + pd(WidgetsView), +} +impl Into for Empty { + fn into(self) -> PodcastsView { self.content.stack.set_visible_child_name("podcasts"); - Ok( - PodcastsView { - content: self.content - } - ) + PodcastsView { + content: self.content + } } } @@ -94,22 +95,17 @@ impl UpdateView for Empty { fn update(&mut self) {} } -impl PodcastsView { - fn into_empty(self) -> Result { - if !self.content.podcasts.flowbox.get_children().is_empty() { - return Err(self); - } - +impl Into for PodcastsView { + fn into(self) -> Empty { self.content.stack.set_visible_child_name("empty"); - - Ok( - Empty { - content: self.content - } - ) + Empty { + content: self.content + } } +} - fn into_widget(self) -> WidgetsView { +impl Into for PodcastsView { + fn into(self) -> WidgetsView { self.content.stack.set_visible_child_name("widget"); WidgetsView { @@ -125,15 +121,17 @@ impl UpdateView for PodcastsView { } } -impl WidgetsView { - fn into_podcasts(self) -> PodcastsView { +impl Into for WidgetsView { + fn into(self) -> PodcastsView { self.content.stack.set_visible_child_name("podcasts"); PodcastsView { content: self.content } } +} - fn into_empty(self) -> Empty { +impl Into for WidgetsView { + fn into(self) -> Empty { self.content.stack.set_visible_child_name("empty"); Empty { content: self.content @@ -152,13 +150,6 @@ impl UpdateView for WidgetsView { } } -#[derive(Debug)] -pub enum ContentState { - empty(Empty), - pop(PodcastsView), - pd(WidgetsView), -} - impl ContentState { pub fn new() -> ContentState { let content = Content::new();