Crates.io | fl2rust-macro |
lib.rs | fl2rust-macro |
version | |
source | src |
created_at | 2022-11-22 07:30:44.837554+00 |
updated_at | 2025-02-22 15:13:09.20465+00 |
description | A fluid (fltk ui designer) file to Rust transpiler |
homepage | |
repository | https://github.com/fltk-rs/fl2rust |
max_upload_size | |
id | 720668 |
Cargo.toml error: | TOML parse error at line 19, column 1 | 19 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
A fluid (fltk ui designer) file to Rust transpiler.
The minimum supported Rust version for 0.7 is 1.63 and fltk-rs > 1.5.4
You can run fl2rust on the command-line by installing using cargo-install:
$ cargo install fl2rust
Then run:
$ fl2rust <fl file>.fl > <output file>.rs
(A template repo usable via cargo-generate can be found here) Add fl2rust-macro to your list of dependencies:
# Cargo.toml
[dependencies]
fltk = "1.5.4"
fl2rust-macro = "0.7"
The ui file that's generated by fluid, we'll name it myuifile.fl and keep it in our src directory:
# data file for the Fltk User Interface Designer (fluid)
version 1.0400
header_name {.h}
code_name {.cxx}
class UserInterface {open
} {
Function {make_window()} {open
} {
Fl_Window {} {open selected
xywh {138 161 440 355} type Double visible
} {
Fl_Button but {
label {Click me}
xywh {175 230 95 45}
}
}
}
}
In our main source file:
use fltk::{prelude::*, *};
mod ui {
fl2rust_macro::include_ui!("src/myuifile.fl");
}
fn main() {
let a = app::App::default();
let mut ui = ui::UserInterface::make_window();
ui.but.set_callback(|b| println!("Button clicked!"));
a.run().unwrap();
}
In our build.rs file:
fn main() {
println!("cargo:rerun-if-changed=src/myuifile.fl");
}
To automate things through cargo, you can use fl2rust as a library by adding it to your build-dependencies:
# Cargo.toml
[dependencies]
fltk = "1.5.4"
[build-dependencies]
fl2rust = "0.7"
// build.rs
fn main() {
use std::path::PathBuf;
use std::env;
println!("cargo:rerun-if-changed=src/myuifile.fl");
let g = fl2rust::Generator::default();
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
g.in_out("src/myuifile.fl", out_path.join("myuifile.rs").to_str().unwrap()).expect("Failed to generate rust from fl file!");
}
The ui file that's generated by fluid, we'll name it myuifile.fl and keep it in our src directory:
# data file for the Fltk User Interface Designer (fluid)
version 1.0400
header_name {.h}
code_name {.cxx}
class UserInterface {open
} {
Function {make_window()} {open
} {
Fl_Window {} {open selected
xywh {138 161 440 355} type Double visible
} {
Fl_Button but {
label {Click me}
xywh {175 230 95 45}
}
}
}
}
// src/myuifile.rs
#![allow(unused_variables)]
#![allow(unused_mut)]
#![allow(unused_imports)]
#![allow(dead_code)]
#![allow(clippy::needless_update)]
include!(concat!(env!("OUT_DIR"), "/myuifile.rs"));
// src/main.rs
use fltk::{prelude::*, *};
mod myuifile;
fn main() {
let app = app::App::default();
let mut ui = myuifile::UserInterface::make_window();
ui.but.set_callback(move |_| {
println!("Works!");
});
app.run().unwrap();
}
There are several options:
cargo install fltk-fluid
Version 0.4.4 adds i18n support via the tr!
macro from the tr crate.
To enable it:
#[macro_use]
extern crate tr;