Use Default trait for creating Widget's that don't need arguments.
This commit is contained in:
parent
440badf1eb
commit
75fe0f8ff5
@ -60,8 +60,8 @@ impl ShowStack {
|
|||||||
header: header.clone(),
|
header: header.clone(),
|
||||||
});
|
});
|
||||||
|
|
||||||
let pop = ShowsPopulated::new_initialized(show.clone(), header);
|
let pop = ShowsPopulated::new(show.clone(), header);
|
||||||
let widget = ShowWidget::new();
|
let widget = ShowWidget::default();
|
||||||
let empty = EmptyView::new();
|
let empty = EmptyView::new();
|
||||||
|
|
||||||
show.stack.add_named(&pop.container, "podcasts");
|
show.stack.add_named(&pop.container, "podcasts");
|
||||||
@ -90,7 +90,7 @@ impl ShowStack {
|
|||||||
let vis = self.stack.get_visible_child_name().unwrap();
|
let vis = self.stack.get_visible_child_name().unwrap();
|
||||||
let old = self.stack.get_child_by_name("podcasts").unwrap();
|
let old = self.stack.get_child_by_name("podcasts").unwrap();
|
||||||
|
|
||||||
let pop = ShowsPopulated::new();
|
let pop = ShowsPopulated::default();
|
||||||
pop.init(Rc::new(self.clone()), self.header.clone());
|
pop.init(Rc::new(self.clone()), self.header.clone());
|
||||||
|
|
||||||
self.stack.remove(&old);
|
self.stack.remove(&old);
|
||||||
@ -109,7 +109,7 @@ impl ShowStack {
|
|||||||
|
|
||||||
pub fn replace_widget(&self, pd: &Podcast) {
|
pub fn replace_widget(&self, pd: &Podcast) {
|
||||||
let old = self.stack.get_child_by_name("widget").unwrap();
|
let old = self.stack.get_child_by_name("widget").unwrap();
|
||||||
let new = ShowWidget::new_initialized(Rc::new(self.clone()), self.header.clone(), pd);
|
let new = ShowWidget::new(Rc::new(self.clone()), self.header.clone(), pd);
|
||||||
|
|
||||||
self.stack.remove(&old);
|
self.stack.remove(&old);
|
||||||
self.stack.add_named(&new.container, "widget");
|
self.stack.add_named(&new.container, "widget");
|
||||||
|
|||||||
@ -19,8 +19,8 @@ pub struct Header {
|
|||||||
show_title: gtk::Label,
|
show_title: gtk::Label,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Header {
|
impl Default for Header {
|
||||||
pub fn new() -> Rc<Header> {
|
fn default() -> Header {
|
||||||
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/headerbar.ui");
|
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/headerbar.ui");
|
||||||
|
|
||||||
let header: gtk::HeaderBar = builder.get_object("headerbar").unwrap();
|
let header: gtk::HeaderBar = builder.get_object("headerbar").unwrap();
|
||||||
@ -33,14 +33,23 @@ impl Header {
|
|||||||
switch.set_halign(gtk::Align::Center);
|
switch.set_halign(gtk::Align::Center);
|
||||||
switch.show();
|
switch.show();
|
||||||
|
|
||||||
Rc::new(Header {
|
Header {
|
||||||
container: header,
|
container: header,
|
||||||
refresh,
|
refresh,
|
||||||
add_toggle,
|
add_toggle,
|
||||||
switch,
|
switch,
|
||||||
back_button,
|
back_button,
|
||||||
show_title,
|
show_title,
|
||||||
})
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Header {
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn new(content: Rc<Content>) -> Rc<Header> {
|
||||||
|
let h = Header::default();
|
||||||
|
h.init(content);
|
||||||
|
Rc::new(h)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init(&self, content: Rc<Content>) {
|
pub fn init(&self, content: Rc<Content>) {
|
||||||
|
|||||||
@ -24,6 +24,7 @@ use hammond_data::utils::checkup;
|
|||||||
|
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use gio::{ActionMapExt, ApplicationExt, MenuExt, SimpleActionExt};
|
use gio::{ActionMapExt, ApplicationExt, MenuExt, SimpleActionExt};
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
// http://gtk-rs.org/tuto/closures
|
// http://gtk-rs.org/tuto/closures
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
@ -52,8 +53,6 @@ mod content;
|
|||||||
mod utils;
|
mod utils;
|
||||||
mod static_resource;
|
mod static_resource;
|
||||||
|
|
||||||
// THIS IS STILL A PROTOTYPE.
|
|
||||||
|
|
||||||
fn build_ui(app: >k::Application) {
|
fn build_ui(app: >k::Application) {
|
||||||
let menu = gio::Menu::new();
|
let menu = gio::Menu::new();
|
||||||
menu.append("Quit", "app.quit");
|
menu.append("Quit", "app.quit");
|
||||||
@ -64,14 +63,8 @@ fn build_ui(app: >k::Application) {
|
|||||||
let window = gtk::ApplicationWindow::new(app);
|
let window = gtk::ApplicationWindow::new(app);
|
||||||
window.set_default_size(1150, 650);
|
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::Content::new_initialized();
|
|
||||||
|
|
||||||
// Get the headerbar
|
// Get the headerbar
|
||||||
let header = headerbar::Header::new();
|
let header = Rc::new(headerbar::Header::default());
|
||||||
let ct = content::Content::new(header.clone());
|
let ct = content::Content::new(header.clone());
|
||||||
header.init(ct.clone());
|
header.init(ct.clone());
|
||||||
window.set_titlebar(&header.container);
|
window.set_titlebar(&header.container);
|
||||||
|
|||||||
@ -5,11 +5,17 @@ pub struct EmptyView {
|
|||||||
pub container: gtk::Box,
|
pub container: gtk::Box,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EmptyView {
|
impl Default for EmptyView {
|
||||||
pub fn new() -> EmptyView {
|
fn default() -> Self {
|
||||||
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/empty_view.ui");
|
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/empty_view.ui");
|
||||||
let view: gtk::Box = builder.get_object("empty_view").unwrap();
|
let view: gtk::Box = builder.get_object("empty_view").unwrap();
|
||||||
|
|
||||||
EmptyView { container: view }
|
EmptyView { container: view }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl EmptyView {
|
||||||
|
pub fn new() -> EmptyView {
|
||||||
|
EmptyView::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -19,18 +19,8 @@ pub struct ShowsPopulated {
|
|||||||
viewport: gtk::Viewport,
|
viewport: gtk::Viewport,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
impl Default for ShowsPopulated {
|
||||||
struct ShowsChild {
|
fn default() -> Self {
|
||||||
container: gtk::Box,
|
|
||||||
title: gtk::Label,
|
|
||||||
cover: gtk::Image,
|
|
||||||
banner: gtk::Image,
|
|
||||||
number: gtk::Label,
|
|
||||||
child: gtk::FlowBoxChild,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ShowsPopulated {
|
|
||||||
pub fn new() -> ShowsPopulated {
|
|
||||||
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/shows_view.ui");
|
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/shows_view.ui");
|
||||||
let container: gtk::Box = builder.get_object("fb_parent").unwrap();
|
let container: gtk::Box = builder.get_object("fb_parent").unwrap();
|
||||||
let flowbox: gtk::FlowBox = builder.get_object("flowbox").unwrap();
|
let flowbox: gtk::FlowBox = builder.get_object("flowbox").unwrap();
|
||||||
@ -42,10 +32,11 @@ impl ShowsPopulated {
|
|||||||
viewport,
|
viewport,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
impl ShowsPopulated {
|
||||||
pub fn new_initialized(show: Rc<ShowStack>, header: Rc<Header>) -> ShowsPopulated {
|
pub fn new(show: Rc<ShowStack>, header: Rc<Header>) -> ShowsPopulated {
|
||||||
let pop = ShowsPopulated::new();
|
let pop = ShowsPopulated::default();
|
||||||
pop.init(show, header);
|
pop.init(show, header);
|
||||||
pop
|
pop
|
||||||
}
|
}
|
||||||
@ -74,7 +65,7 @@ impl ShowsPopulated {
|
|||||||
|
|
||||||
if let Ok(pds) = podcasts {
|
if let Ok(pds) = podcasts {
|
||||||
pds.iter().for_each(|parent| {
|
pds.iter().for_each(|parent| {
|
||||||
let flowbox_child = ShowsChild::new_initialized(parent);
|
let flowbox_child = ShowsChild::new(parent);
|
||||||
self.flowbox.add(&flowbox_child.child);
|
self.flowbox.add(&flowbox_child.child);
|
||||||
});
|
});
|
||||||
self.flowbox.show_all();
|
self.flowbox.show_all();
|
||||||
@ -86,11 +77,20 @@ impl ShowsPopulated {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ShowsChild {
|
#[derive(Debug)]
|
||||||
fn new() -> ShowsChild {
|
struct ShowsChild {
|
||||||
|
container: gtk::Box,
|
||||||
|
title: gtk::Label,
|
||||||
|
cover: gtk::Image,
|
||||||
|
banner: gtk::Image,
|
||||||
|
number: gtk::Label,
|
||||||
|
child: gtk::FlowBoxChild,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for ShowsChild {
|
||||||
|
fn default() -> Self {
|
||||||
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/shows_child.ui");
|
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/shows_child.ui");
|
||||||
|
|
||||||
// Copy of gnome-music AlbumWidget
|
|
||||||
let container: gtk::Box = builder.get_object("fb_child").unwrap();
|
let container: gtk::Box = builder.get_object("fb_child").unwrap();
|
||||||
let title: gtk::Label = builder.get_object("pd_title").unwrap();
|
let title: gtk::Label = builder.get_object("pd_title").unwrap();
|
||||||
let cover: gtk::Image = builder.get_object("pd_cover").unwrap();
|
let cover: gtk::Image = builder.get_object("pd_cover").unwrap();
|
||||||
@ -109,6 +109,15 @@ impl ShowsChild {
|
|||||||
child,
|
child,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ShowsChild {
|
||||||
|
pub fn new(pd: &Podcast) -> ShowsChild {
|
||||||
|
let child = ShowsChild::default();
|
||||||
|
child.init(pd);
|
||||||
|
|
||||||
|
child
|
||||||
|
}
|
||||||
|
|
||||||
fn init(&self, pd: &Podcast) {
|
fn init(&self, pd: &Podcast) {
|
||||||
self.title.set_text(pd.title());
|
self.title.set_text(pd.title());
|
||||||
@ -122,13 +131,6 @@ impl ShowsChild {
|
|||||||
self.configure_banner(pd);
|
self.configure_banner(pd);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_initialized(pd: &Podcast) -> ShowsChild {
|
|
||||||
let child = ShowsChild::new();
|
|
||||||
child.init(pd);
|
|
||||||
|
|
||||||
child
|
|
||||||
}
|
|
||||||
|
|
||||||
fn configure_banner(&self, pd: &Podcast) {
|
fn configure_banner(&self, pd: &Podcast) {
|
||||||
let bann =
|
let bann =
|
||||||
Pixbuf::new_from_resource_at_scale("/org/gnome/hammond/banner.png", 256, 256, true);
|
Pixbuf::new_from_resource_at_scale("/org/gnome/hammond/banner.png", 256, 256, true);
|
||||||
|
|||||||
@ -47,8 +47,8 @@ struct EpisodeWidget {
|
|||||||
progress_label: gtk::Label,
|
progress_label: gtk::Label,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EpisodeWidget {
|
impl Default for EpisodeWidget {
|
||||||
fn new() -> EpisodeWidget {
|
fn default() -> Self {
|
||||||
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/episode_widget.ui");
|
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/episode_widget.ui");
|
||||||
|
|
||||||
let container: gtk::Box = builder.get_object("episode_container").unwrap();
|
let container: gtk::Box = builder.get_object("episode_container").unwrap();
|
||||||
@ -95,9 +95,11 @@ impl EpisodeWidget {
|
|||||||
progress_label,
|
progress_label,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn new_initialized(episode: &mut EpisodeWidgetQuery, pd: &Podcast) -> EpisodeWidget {
|
impl EpisodeWidget {
|
||||||
let widget = EpisodeWidget::new();
|
pub fn new(episode: &mut EpisodeWidgetQuery, pd: &Podcast) -> EpisodeWidget {
|
||||||
|
let widget = EpisodeWidget::default();
|
||||||
widget.init(episode, pd);
|
widget.init(episode, pd);
|
||||||
widget
|
widget
|
||||||
}
|
}
|
||||||
@ -284,7 +286,7 @@ pub fn episodes_listbox(pd: &Podcast) -> Result<gtk::ListBox> {
|
|||||||
let list = gtk::ListBox::new();
|
let list = gtk::ListBox::new();
|
||||||
|
|
||||||
episodes.into_iter().for_each(|mut ep| {
|
episodes.into_iter().for_each(|mut ep| {
|
||||||
let widget = EpisodeWidget::new_initialized(&mut ep, pd);
|
let widget = EpisodeWidget::new(&mut ep, pd);
|
||||||
list.add(&widget.container);
|
list.add(&widget.container);
|
||||||
|
|
||||||
let sep = gtk::Separator::new(gtk::Orientation::Vertical);
|
let sep = gtk::Separator::new(gtk::Orientation::Vertical);
|
||||||
|
|||||||
@ -28,8 +28,8 @@ pub struct ShowWidget {
|
|||||||
episodes: gtk::Frame,
|
episodes: gtk::Frame,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ShowWidget {
|
impl Default for ShowWidget {
|
||||||
pub fn new() -> ShowWidget {
|
fn default() -> Self {
|
||||||
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/show_widget.ui");
|
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/show_widget.ui");
|
||||||
let container: gtk::Box = builder.get_object("container").unwrap();
|
let container: gtk::Box = builder.get_object("container").unwrap();
|
||||||
let episodes: gtk::Frame = builder.get_object("episodes").unwrap();
|
let episodes: gtk::Frame = builder.get_object("episodes").unwrap();
|
||||||
@ -54,9 +54,11 @@ impl ShowWidget {
|
|||||||
episodes,
|
episodes,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn new_initialized(shows: Rc<ShowStack>, header: Rc<Header>, pd: &Podcast) -> ShowWidget {
|
impl ShowWidget {
|
||||||
let pdw = ShowWidget::new();
|
pub fn new(shows: Rc<ShowStack>, header: Rc<Header>, pd: &Podcast) -> ShowWidget {
|
||||||
|
let pdw = ShowWidget::default();
|
||||||
pdw.init(shows, header, pd);
|
pdw.init(shows, header, pd);
|
||||||
pdw
|
pdw
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user