Simplify generating an fltk gui from a data structure

Related tags

GUI fltk-form
Overview

fltk-form

This crate aims to simplify generating gui from a data structure.

Usage

[dependencies]
fltk = "1.2.16"
fltk-form = "0.1"
fltk-form-derive = "0.1"

You can also git clone the repo and run the example directly:

$ cargo run --example basic

Example

<-- get a single property assert_eq!(v, Some("3.0".to_owned())); btn.set_callback(move |_| { println!("{:?}", form.get_props()); // <-- get a HashMap of the properties }); a.run().unwrap(); } ">
#[macro_use]
extern crate fltk_form_derive;

use fltk::{prelude::*, *};
use fltk_form::{FltkForm, HasProps};

#[derive(Copy, Debug, Clone, FltkForm)]
pub enum MyEnum {
    A,
    B,
    C,
}

#[derive(Debug, Clone, FltkForm)]
pub struct MyStruct {
    a: f64,
    b: f64,
    c: String,
    d: MyEnum,
    e: bool,
}

impl MyStruct {
    pub fn default() -> Self {
        Self {
            a: 0.0,
            b: 3.0,
            c: String::new(),
            d: MyEnum::A,
            e: true,
        }
    }
}

fn main() {
    let my_struct = MyStruct::default(); // <-- instantiate your struct

    let a = app::App::default().with_scheme(app::Scheme::Gtk);
    app::set_background_color(222, 222, 222);

    let mut win = window::Window::default().with_size(400, 300);
    let mut grp = group::Group::default()
        .with_size(300, 200)
        .center_of_parent();

    let form = my_struct.generate(); // <-- generate the form
    
    grp.end();
    let mut btn = button::Button::default()
        .with_label("print")
        .with_size(80, 30)
        .below_of(&grp, 5)
        .center_x(&grp);
    grp.set_frame(enums::FrameType::EngravedFrame);
    win.end();
    win.show();

    let v = form.get_prop("b"); // <-- get a single property
    assert_eq!(v, Some("3.0".to_owned()));

    btn.set_callback(move |_| {
        println!("{:?}", form.get_props()); // <-- get a HashMap of the properties
    });

    a.run().unwrap();
}

alt_test

alt_test

You might also like...
Clear Coat is a Rust wrapper for the IUP GUI library.

Clear Coat Clear Coat is a Rust wrapper for the IUP GUI library. IUP uses native controls and has Windows and GTK backends. A macOS backend has been o

A single-header ANSI C immediate mode cross-platform GUI library
A single-header ANSI C immediate mode cross-platform GUI library

Nuklear This is a minimal-state, immediate-mode graphical user interface toolkit written in ANSI C and licensed under public domain. It was designed a

The bindings to the Nuklear 2D immediate GUI library.

nuklear-rust The bindings to the Nuklear 2D immediate GUI library. Currently beta. Drawing backends: gfx-pre-ll for GFX 3D drawing engine (examples: O

A cross-platform GUI library for Rust, inspired by Elm
A cross-platform GUI library for Rust, inspired by Elm

Iced A cross-platform GUI library for Rust focused on simplicity and type-safety. Inspired by Elm. Features Simple, easy-to-use, batteries-included AP

Truly cross platform, truly native. multiple backend GUI for rust
Truly cross platform, truly native. multiple backend GUI for rust

WIP: Sauron-native a rust UI library that conquers all platforms ranging from desktop to mobile devices. An attempt to create a truly native, truly cr

 A GUI for Cargo
A GUI for Cargo

A GUI for Cargo This is a project to make a GUI for cargo, built using SixtyFPS: The idea cargo install cargo-ui cargo ui Prerequisites In addition to

A cross-platform GUI library for Rust focused on simplicity and type-safety
A cross-platform GUI library for Rust focused on simplicity and type-safety

A cross-platform GUI library for Rust, inspired by Elm

Automatically create GUI applications from clap3 apps
Automatically create GUI applications from clap3 apps

Automatically create GUI applications from clap3 apps

A simple news reading GUI app built in Rust
A simple news reading GUI app built in Rust

Headlines [WIP] A native GUI app built with Rust using egui. Uses newsapi.org as the source to fetch news articles. This is a WIP and the current stat

Comments
  • Best way to do color?

    Best way to do color?

    Before I do anything, I want your opinions on implementation. The items needed to do this are:

    If it is simple to make callbacks function here, I would like to also make other common dialogs, like FlFile(String) to open a file chooser. It would also simply set_label() as well. Perhaps a checkbox button with fl_ask() Using something like FlAsk(pub value:bool, pub label:String); Can a callback set the struct fields?

    // from the docs
    but.set_callback(move |_| frame.set_label("Hello World!")); // the closure capture is mutable borrow to our button
    
    opened by 1sra3l 17
  • typed Generics possible?

    typed Generics possible?

    I know this is likely fringe, but is this even possible?

    #[derive( Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
    #[cfg_attr(feature = "fltkform", derive(FltkForm))]
    pub struct Config<T:Copy 
                     + Default
                     + AddAssign
                     + Add<Output = T>
                     + Div<Output = T>
                     + DivAssign
                     + Mul<Output = T>
                     + MulAssign
                     + Neg<Output = T>
                     + Rem<Output = T>
                     + RemAssign
                     + Sub<Output = T>
                     + SubAssign
                     + std::cmp::PartialOrd> {
        /// Identification Number
        pub id:T,
        pub cost:T,
        pub amount:T,
    }
    
    opened by 1sra3l 14
  • Nested structs cause an error, internal sizing issues, but this thing is amazing!

    Nested structs cause an error, internal sizing issues, but this thing is amazing!

    A struct within a struct causes a crash and backtrace is required to decipher nested structs do not work. That said, nested enums, etc... work

    The other issue is internal sizing, as you mentioned: image

    I think scaling the size of label is more important than the 'input', and unless something changed in FLTK you need to calculate text width by yourself. I've done it in the past based on the font size, but did not find the best solution.

    All in all this is great!!! What an easy way to make a GUI for entering info!!! I can now build a GUI prefilled with values and switch between files with hardly any coding! This is so amazing!!

    To sub nest a struct, the only possible way i can think is to return an Fl_Tab, with a Group for each extra struct as a tab. If every internal struct became a tab, it could potentially create a ton of tabs, and tabs within Tabs. But AFAIK this should nest correctly and look okay.

    This has me wanting to get into macros, you are really good at this stuff!! Thanks so much!

    opened by 1sra3l 12
  • would `{generate(),view()}.with_*` for styling, etc be possible?

    would `{generate(),view()}.with_*` for styling, etc be possible?

    Or is there a way to quickly theme all elements inside a Group that would make this redundant? Is this type of thing accessible using *_prop_()? Thanks again for doing this!

    opened by 1sra3l 3
Owner
fltk-rs
fltk-rs
Rust bindings for the FLTK GUI library.

fltk-rs Rust bindings for the FLTK Graphical User Interface library. The FLTK crate is a crossplatform lightweight gui library which can be statically

Mohammed Alyousef 1.1k Jan 9, 2023
Rust bindings for the FLTK GUI library.

fltk-rs Rust bindings for the FLTK Graphical User Interface library. The fltk crate is a cross-platform lightweight gui library which can be staticall

fltk-rs 1.1k Jan 9, 2023
A lightweight cross-platform system-monitoring fltk gui application based on sysinfo

Sysinfo-gui A lightweight cross-platform system-monitoring fltk gui application based on sysinfo. The UI design is inspired by stacer. The svg icons a

Mohammed Alyousef 22 Dec 31, 2022
Simple and portable (but not inflexible) GUI library in C that uses the native GUI technologies of each platform it supports.

libui: a portable GUI library for C This README is being written. Status It has come to my attention that I have not been particularly clear about how

Pietro Gagliardi 10.4k Dec 31, 2022
A smart table widget for fltk-rs

fltk-table A smart table widget for fltk-rs. It aims to reduce the amount of boilerplate required to create a table. Usage [dependencies] fltk = "1.2"

fltk-rs 11 Dec 8, 2022
FLTK frontend for Egui WGPU backend.

Egui FLTK Frontend FLTK Frontend for Egui WGPU Backend On linux Debian/Ubuntu, make sure to install the latest main requirements: sudo apt-get update

Adia Robbie 5 Oct 25, 2022
A simple, cross-platform GUI automation module for Rust.

AutoPilot AutoPilot is a Rust port of the Python C extension AutoPy, a simple, cross-platform GUI automation library for Python. For more information,

null 271 Dec 27, 2022
Desktop GUI Framework

Azul - Desktop GUI framework WARNING: The features advertised in this README may not work yet. Azul is a free, functional, immediate mode GUI framewor

Maps4Print 5.4k Jan 1, 2023
An easy-to-use, 2D GUI library written entirely in Rust.

Conrod An easy-to-use, 2D GUI library written entirely in Rust. Guide What is Conrod? A Brief Summary Screenshots and Videos Feature Overview Availabl

PistonDevelopers 3.3k Jan 1, 2023
Idiomatic, GTK+-based, GUI library, inspired by Elm, written in Rust

Relm Asynchronous, GTK+-based, GUI library, inspired by Elm, written in Rust. This library is in beta stage: it has not been thoroughly tested and its

null 2.2k Dec 31, 2022