fltk-rs / fl2rust

A fluid (fltk ui designer) file to Rust transpiler
MIT License
52 stars 3 forks source link

Menu items created in FLUID have shortcut created incorrectly #7

Closed 1sra3l closed 3 years ago

1sra3l commented 3 years ago

The issue is when adding Keyboard Shortcuts for a menu item via FLUID's widget browser, then running fl2rust.

// the menu item `load` is never made in the Rust code
load.set_shortcut(unsafe {std::mem::transmute(0x4006f)});
// this should create a menu item like in the C++ `Fl_Menu_Item* UI::load = UI::menu_menu + 3;`  so I can use emit
menu.add("{&File}/&Open", Shortcut::None, MenuFlag::Normal, || {});

I know I can simply build the menu programmatically, but I do like having all the menu items in the FLUID file for others to see it easily.

Thanks again for all your work

MoAlyousef commented 3 years ago

Hi I think it's fixed now if you can try the latest version. Unfortunately menus (and menu items) don't map particularly well from C++ to Rust. FLTK's C++ uses a menu array with null termination for submenus and the menu itself, this isn't exposed on the Rust side, and would be difficult to expose anyway. So on the Rust side, the ::add constructor is used.

1sra3l commented 3 years ago

So this happens using &File now :smile_cat:

image

I think it is something in the formatting output??? The sub menus are not effected by it.

The important thing is that it compiles now!!!

Which meant I could delete my hacky code, and put it into the fl file, where other people would think it is!

So almost closed?

1sra3l commented 3 years ago

Oh yeah, the way I expose the menu to myself is

// menu item number 1
let mut m = match menu.at(1){
        Some(m) => m,
        None => return,
    };
    m.emit(send_action, Action::whatever);

The reason I am saying this, is that from the API user side, you have mapped things well. It may not be bit for bit, but you've made FLTK much more fun to use in Rust. I am interested to see what this will be like with the 1.4.X branch, when that day comes. That may be a game changer for many people, with the backened renderer setup changing.

MoAlyousef commented 3 years ago

That's great to hear :) Thank you

btw I've published version 0.4.9 with the fix for the brackets.

1sra3l commented 3 years ago

Thanks! That did it!