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 {
println!("Iced");
Ok(())
//Gamarjoba::run(Settings::default())
iced::run("A counter", update, view)
}
#[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,28 +1,24 @@
mod iced;
use anyhow::{Result, anyhow};
use anyhow::{anyhow, Result};
fn main() -> Result<()> {
let args: Vec<String> = std::env::args().collect();
let framework = match args.get(1) {
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() {
"iced" => {
iced::iced_main().map_err(|err| anyhow!(err))
},
"iced" => iced::iced_main().map_err(|err| anyhow!(err)),
"druid" => druid_main(),
"egui" => egui_main(),
other => {
Err(anyhow!(r#"You specified {other}, allowed values: "iced", "egui""#))
other => Err(anyhow!(
r#"You specified {other}, allowed values: "iced", "egui""#
)),
}
}
}
fn druid_main() -> Result<()> {
println!("druid");
@ -33,5 +29,3 @@ fn egui_main() -> Result<()> {
println!("egui - not implemented yet");
Ok(())
}