-
-
Save pa-0/b73411ac1855a1032f02145e151cfa2c 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