fl2rust
usage
$ cargo install fl2rust
Then run:
$ fl2rust <fl file>.fl > <output file>.rs
To automate this with cargo, we can use fl2rust as a library by adding it to our build dependencies:
# Cargo.toml
[dependencies]
fltk = "1"
[build-dependencies]
fl2rust = "0.4"
// 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!");
}
# src/myuifile.fl -> generated via fluid
# 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(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();
}
Several ways to obtain FLUID:
cargo install fltk-fluid
- via package manager.
- Build the fltk library yourself by using cmake.
- Fluid is built when fltk-rs is built, it will be located in OUT_DIR.
- archLinux install fluid (sudo pacman -S fltk)
i18n support
tr!
Version 0.4.4 added i18n support via macros in the tr crate. To enable it:
- In
fluid
, Edit->Project Settings...->Internationalization.. - Change the dropdown menu to use GNU gettext (the tr crate supports both gettext-rs and gettext flavors).
- Add tr to dependencies in Cargo.toml.
- Add to our main.rs file:
#[macro_use]
extern crate tr;
- Initialize tr as described in the tr crate's documentation.
known limitations
- Adding arbitrary code or declaring global/member variables is not supported.
- Only constructor methods are supported.
- fl2rust does not check the correctness of the generated Rust code.
tutorial
- Using FLUID (RAD tool) with Rust