#gui #ui #widgets #bindings #graphics

bin+lib fl2rust

A fluid (fltk ui designer) file to Rust transpiler

44 releases

0.4.17 Jan 17, 2022
0.4.15 Dec 17, 2021
0.4.12 Oct 21, 2021
0.4.5 Jul 31, 2021
0.3.2 Feb 19, 2021

#273 in GUI

Download history 116/week @ 2022-03-09 233/week @ 2022-03-16 189/week @ 2022-03-23 221/week @ 2022-03-30 121/week @ 2022-04-06 22/week @ 2022-04-13 21/week @ 2022-04-20 288/week @ 2022-04-27 216/week @ 2022-05-04 680/week @ 2022-05-11 195/week @ 2022-05-18 242/week @ 2022-05-25 369/week @ 2022-06-01 115/week @ 2022-06-08 25/week @ 2022-06-15 31/week @ 2022-06-22

542 downloads per month

MIT license

66KB
1.5K SLoC

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

(A template repo usable via cargo-generate can be found here)

To automate things through cargo, you can use fl2rust as a library by adding it to your 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();
}

Where you can get FLUID?

There are several options:

  • cargo install fltk-fluid
  • Through a package manager.
  • By building the fltk library yourself using cmake.
  • Fluid is built when building fltk-rs, where it'll be in the OUT_DIR.

i18n support

Version 0.4.4 adds i18n support via the tr! macro from the tr crate. To enable it:

  • In fluid, go to Edit->Project Settings...->Internationalization.
  • Change the dropdown to use GNU gettext (which the tr crate supports in both forms gettext-rs and gettext).
  • Add tr to you dependencies in you Cargo.toml.
  • Add to your 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 unsupported.
  • Only constructor methods are supported.
  • fl2rust doesn't check the generated Rust code for correctness.

Tutorial

Fltk Form

Use fltk-form to quickly build UI elements.

To test this feature: cargo run --example fltkform

See the source code for the example.

No runtime deps