Created
September 23, 2021 16:27
-
-
Save MoAlyousef/36495ba6ab7a4c83c3cdb1fe876c30cd to your computer and use it in GitHub Desktop.
fltk-sys example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(concat_idents)] | |
use fltk_sys::{fl::*, frame::*, window::*, group::*, button::{self, *}}; | |
use std::os::raw::*; | |
macro_rules! fstr { | |
($s:literal) => { | |
concat!($s, "\0").as_ptr() as _ | |
} | |
} | |
macro_rules! default { | |
($i:ident, $s:literal) => { | |
concat_idents!($i, _new)(0, 0, 0, 0, fstr!($s)) | |
}; | |
($i:ident) => { | |
default!($i, "") | |
}; | |
} | |
macro_rules! default_fill { | |
($i:ident, $s:literal) => { | |
{ | |
let g = Fl_Group_current(); | |
concat_idents!($i, _new)(0, 0, Fl_Group_width(g), Fl_Group_height(g), fstr!($s)) | |
} | |
}; | |
($i:ident) => { | |
default_fill!($i, "") | |
} | |
} | |
unsafe extern "C" fn btn_cb(_w: *mut button::Fl_Widget, data: *mut c_void) { | |
Fl_Window_set_label(data as _, fstr!("Works")); | |
} | |
fn main() { | |
unsafe { | |
let win = Fl_Window_new(100, 100, 400, 300, fstr!("Hello")); | |
let flex = default_fill!(Fl_Flex); | |
Fl_Flex_set_type(flex, 1); | |
default!(Fl_Box); | |
let btn = default!(Fl_Button, "Click"); | |
default!(Fl_Box); | |
Fl_Flex_end(flex); | |
Fl_Window_end(win); | |
Fl_Window_show(win); | |
Fl_Button_set_callback(btn, Some(btn_cb), win as _); | |
Fl_run(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment