From 36dc8675f5757c81d3b78da19d6f7bb4f34a555c Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 2 Dec 2021 19:57:16 +0100 Subject: Implement hello-world gui with iced Signed-off-by: Matthias Beyer --- src/cli.rs | 7 ++++++- src/gui/mod.rs | 32 ++++++++++++++++++++++++++++++++ src/main.rs | 17 ++++++++++++----- 3 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 src/gui/mod.rs (limited to 'src') diff --git a/src/cli.rs b/src/cli.rs index 8e912e0..3f74128 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -9,7 +9,6 @@ pub fn app<'a>() -> App<'a> { .version(crate_version!()) .about("Distributed social network") - .subcommand(App::new("profile") .author(crate_authors!()) .version(crate_version!()) @@ -51,4 +50,10 @@ pub fn app<'a>() -> App<'a> { ) ) ) + + .subcommand(App::new("gui") + .author(crate_authors!()) + .version(crate_version!()) + .about("Start the distrox gui") + ) } diff --git a/src/gui/mod.rs b/src/gui/mod.rs new file mode 100644 index 0000000..a7cc4ff --- /dev/null +++ b/src/gui/mod.rs @@ -0,0 +1,32 @@ +use anyhow::Result; +use iced::Application; + +#[derive(Debug)] +struct DistroxGui; + +impl Application for DistroxGui { + type Executor = iced::executor::Default; // tokio + type Message = (); + type Flags = (); + + fn new(_flags: ()) -> (Self, iced::Command) { + (DistroxGui, iced::Command::none()) + } + + fn title(&self) -> String { + String::from("distrox") + } + + fn update(&mut self, _message: Self::Message, _clipboard: &mut iced::Clipboard) -> iced::Command { + iced::Command::none() + } + + fn view(&mut self) -> iced::Element { + iced::Text::new("Hello, world!").into() + } + +} + +pub fn run() -> Result<()> { + DistroxGui::run(iced::Settings::default()).map_err(anyhow::Error::from) +} diff --git a/src/main.rs b/src/main.rs index 257847c..3caf1ae 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,17 +8,24 @@ pub mod consts; pub mod ipfs_client; pub mod profile; pub mod types; +mod gui; -#[tokio::main] -async fn main() -> Result<()> { +fn main() -> Result<()> { let _ = env_logger::try_init()?; let matches = crate::cli::app().get_matches(); match matches.subcommand() { Some(("profile", matches)) => crate::commands::profile(matches).await, - _ => unimplemented!() - } - + Some(("gui", _)) => crate::gui::run(), + Some((other, _)) => { + log::error!("No subcommand {} implemented", other); + Ok(()) + }, + _ => { + log::error!("Don't know what to do"); + Ok(()) + }, + } } -- cgit v1.2.3