Modern iced working

This commit is contained in:
Greg Shuflin 2024-10-01 01:29:15 -07:00
parent a5bf20005e
commit bbe05f64b8
2 changed files with 38 additions and 27 deletions

View File

@ -1,9 +1,26 @@
//use iced::{Application, Command, executor, Clipboard, Element, Text, Settings}; use iced::{
widget::{button, text},
Element,
};
pub fn iced_main() -> iced::Result { pub fn iced_main() -> iced::Result {
println!("Iced"); println!("Iced");
Ok(()) iced::run("A counter", update, view)
//Gamarjoba::run(Settings::default()) }
#[derive(Debug, Clone)]
enum Message {
Increment,
}
fn update(counter: &mut u64, message: Message) {
match message {
Message::Increment => *counter += 1,
}
}
fn view(counter: &u64) -> Element<Message> {
button(text(counter)).on_press(Message::Increment).into()
} }
/* /*

View File

@ -1,29 +1,25 @@
mod iced; mod iced;
use anyhow::{Result, anyhow}; use anyhow::{anyhow, Result};
fn main() -> Result<()> { fn main() -> Result<()> {
let args: Vec<String> = std::env::args().collect(); let args: Vec<String> = std::env::args().collect();
let framework = match args.get(1) { let framework = match args.get(1) {
Some(s) => s, Some(s) => s,
None => return Err(anyhow!("Specify a framework to use")) None => return Err(anyhow!("Specify a framework to use")),
}; };
match framework.as_str() { match framework.as_str() {
"iced" => { "iced" => iced::iced_main().map_err(|err| anyhow!(err)),
iced::iced_main().map_err(|err| anyhow!(err))
},
"druid" => druid_main(), "druid" => druid_main(),
"egui" => egui_main(), "egui" => egui_main(),
other => { other => Err(anyhow!(
Err(anyhow!(r#"You specified {other}, allowed values: "iced", "egui""#)) r#"You specified {other}, allowed values: "iced", "egui""#
} )),
} }
} }
fn druid_main() -> Result<()> { fn druid_main() -> Result<()> {
println!("druid"); println!("druid");
Ok(()) Ok(())
@ -33,5 +29,3 @@ fn egui_main() -> Result<()> {
println!("egui - not implemented yet"); println!("egui - not implemented yet");
Ok(()) Ok(())
} }