diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2021-12-02 19:57:16 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2021-12-08 18:43:34 +0100 |
commit | 36dc8675f5757c81d3b78da19d6f7bb4f34a555c (patch) | |
tree | 5bd5a417fce1ab40198f72663ffb6ecaec8047a0 | |
parent | 969de98ddad7311fbcd74f93910444af8fdb7882 (diff) |
Implement hello-world gui with iced
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r-- | Cargo.toml | 6 | ||||
-rw-r--r-- | src/cli.rs | 7 | ||||
-rw-r--r-- | src/gui/mod.rs | 32 | ||||
-rw-r--r-- | src/main.rs | 17 |
4 files changed, 56 insertions, 6 deletions
@@ -39,10 +39,16 @@ libp2p = "0.39.1" tracing = "0.1" ctrlc = "3.2" +iced_native = "0.4.0" +iced_wgpu = "0.4.0" + [dependencies.ipfs] git = "https://github.com/rs-ipfs/rust-ipfs/" rev = "ad3ab49b4d9236363969b0f74f14aabc7c906b3b" +[dependencies.iced] +version = "0.3.0" +features = ["glow", "tokio", "debug"] [dev-dependencies] multibase = "0.8" @@ -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<Self::Message>) { + (DistroxGui, iced::Command::none()) + } + + fn title(&self) -> String { + String::from("distrox") + } + + fn update(&mut self, _message: Self::Message, _clipboard: &mut iced::Clipboard) -> iced::Command<Self::Message> { + iced::Command::none() + } + + fn view(&mut self) -> iced::Element<Self::Message> { + 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(()) + }, + } } |