Begin port of front end to ICED.
This commit is contained in:
parent
822b9009a6
commit
9cebfa128f
File diff suppressed because it is too large
Load Diff
|
|
@ -8,6 +8,7 @@ members = [
|
|||
"desktop/platform/mac",
|
||||
"desktop/platform/win",
|
||||
"editor",
|
||||
"frontend/iced",
|
||||
"frontend/wrapper",
|
||||
"libraries/dyn-any",
|
||||
"libraries/math-parser",
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
[package]
|
||||
name = "graphite-iced-frontend"
|
||||
description = "Pure-Rust GUI for Graphite built on iced"
|
||||
publish = false
|
||||
version.workspace = true
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
rust-version.workspace = true
|
||||
|
||||
[[bin]]
|
||||
name = "graphite-iced"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
graphite-editor = { workspace = true }
|
||||
|
||||
iced = { version = "0.14", default-features = false, features = ["wgpu", "tokio"] }
|
||||
rand = { workspace = true, features = ["thread_rng"] }
|
||||
tracing = { workspace = true }
|
||||
tracing-subscriber = { workspace = true }
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
use graphite_editor::application::{Editor, Environment, Host, Platform};
|
||||
use graphite_editor::messages::prelude::*;
|
||||
use iced::widget::{column, container, text};
|
||||
use iced::{Element, Length, Task, Theme};
|
||||
use rand::Rng;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
enum Message {
|
||||
Init,
|
||||
}
|
||||
|
||||
struct App {
|
||||
editor: Editor,
|
||||
last_frontend_count: usize,
|
||||
}
|
||||
|
||||
impl App {
|
||||
fn boot() -> (Self, Task<Message>) {
|
||||
let environment = Environment {
|
||||
platform: Platform::Desktop,
|
||||
host: detect_host(),
|
||||
};
|
||||
let seed = rand::rng().random();
|
||||
let editor = Editor::new(environment, seed);
|
||||
|
||||
(Self { editor, last_frontend_count: 0 }, Task::done(Message::Init))
|
||||
}
|
||||
|
||||
fn title(&self) -> String {
|
||||
String::from("Graphite")
|
||||
}
|
||||
|
||||
fn update(&mut self, message: Message) -> Task<Message> {
|
||||
match message {
|
||||
Message::Init => {
|
||||
let responses = self.editor.handle_message(PortfolioMessage::Init);
|
||||
self.last_frontend_count = responses.len();
|
||||
tracing::info!(count = responses.len(), "editor responded to PortfolioMessage::Init");
|
||||
for response in &responses {
|
||||
tracing::info!(kind = %response.to_discriminant().local_name(), "frontend message");
|
||||
}
|
||||
}
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
|
||||
fn view(&self) -> Element<'_, Message> {
|
||||
container(column![text("Graphite").size(40), text(format!("editor produced {} frontend messages at boot", self.last_frontend_count)).size(14),].spacing(8))
|
||||
.padding(24)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn theme(&self) -> Theme {
|
||||
Theme::Dark
|
||||
}
|
||||
}
|
||||
|
||||
fn detect_host() -> Host {
|
||||
if cfg!(target_os = "macos") {
|
||||
Host::Mac
|
||||
} else if cfg!(target_os = "windows") {
|
||||
Host::Windows
|
||||
} else {
|
||||
Host::Linux
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> iced::Result {
|
||||
tracing_subscriber::fmt().with_env_filter(tracing_subscriber::EnvFilter::from_default_env().add_directive(tracing::Level::INFO.into())).init();
|
||||
|
||||
iced::application(App::boot, App::update, App::view).title(App::title).theme(App::theme).run()
|
||||
}
|
||||
|
|
@ -12,6 +12,7 @@ pub enum Action {
|
|||
pub enum Target {
|
||||
Web,
|
||||
Desktop,
|
||||
Iced,
|
||||
Cli,
|
||||
}
|
||||
|
||||
|
|
@ -45,6 +46,7 @@ impl Task {
|
|||
let (target, args) = match args.first() {
|
||||
Some(&"desktop") => (Target::Desktop, &args[1..]),
|
||||
Some(&"web") => (Target::Web, &args[1..]),
|
||||
Some(&"iced") => (Target::Iced, &args[1..]),
|
||||
Some(&"cli") => (Target::Cli, &args[1..]),
|
||||
_ => (Target::Web, args),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ fn usage() {
|
|||
println!("COMMON USAGE:");
|
||||
println!(" cargo run Run the web app");
|
||||
println!(" cargo run desktop Run the desktop app");
|
||||
println!(" cargo run iced Run ICED frontend");
|
||||
println!();
|
||||
println!("OPTIONS:");
|
||||
println!("<command>:");
|
||||
|
|
@ -20,6 +21,7 @@ fn usage() {
|
|||
println!("<target>:");
|
||||
println!(" [web] Web app (default)");
|
||||
println!(" desktop Desktop app");
|
||||
println!(" iced ICED frontend");
|
||||
println!(" cli Graphene CLI");
|
||||
println!("<profile>:");
|
||||
println!(" [debug] Optimizations disabled (default for run)");
|
||||
|
|
@ -127,6 +129,12 @@ fn run_task(task: &Task) -> Result<(), Error> {
|
|||
(Action::Build, Target::Cli, Profile::Debug) => run("cargo build -p graphene-cli")?,
|
||||
(Action::Build, Target::Cli, Profile::Release | Profile::Default) => run("cargo build -r -p graphene-cli")?,
|
||||
|
||||
(Action::Run, Target::Iced, Profile::Debug | Profile::Default) => run(&format!("cargo run -p graphite-iced-frontend -- {}", task.args.join(" ")))?,
|
||||
(Action::Run, Target::Iced, Profile::Release) => run(&format!("cargo run -r -p graphite-iced-frontend -- {}", task.args.join(" ")))?,
|
||||
|
||||
(Action::Build, Target::Iced, Profile::Debug) => run("cargo build -p graphite-iced-frontend")?,
|
||||
(Action::Build, Target::Iced, Profile::Release | Profile::Default) => run("cargo build -r -p graphite-iced-frontend")?,
|
||||
|
||||
(Action::Explore(_), _, _) => unreachable!(),
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
|||
Loading…
Reference in New Issue