#gui #ui #widgets #bindings #graphics

bin+lib fl2rust

A fluid (fltk ui designer) file to Rust transpiler

23 releases

new 0.2.9 Jan 13, 2021
0.2.8 Jan 12, 2021
0.1.14 Jan 7, 2021

#318 in GUI

Download history 201/week @ 2021-01-01 166/week @ 2021-01-08

110 downloads per month

MIT license

39KB
842 lines

fl2rust

Usage

A fluid (fltk ui designer) file to Rust transpiler.

As an executable

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

As a library

To automate things through cargo, you can use fl2rust as a library by adding it to your build-dependencies:

# Cargo.toml
[dependencies]
fltk = "0.13"

[build-dependencies]
fl2rust = "0.2"
// 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)]
include!(concat!(env!("OUT_DIR"), "/myuifile.rs"));
// src/main.rs
use fltk::*;
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();
}

Known limitations

  • Adding arbitrary code or declaring global/member variables is unsupported.
  • Only constructor methods are supported.
  • fl2rust doesn't check the generated Rust code for correctness.
  • Supports fltk-rs >= 0.13.

Tutorial

No runtime deps