简体   繁体   中英

How do I call an FLTK code in a function?

I am a newbie to Rust and am using FLTK to build an interface. I have the following main code. below that is a function I want to call to build a Group. If in the main.rs I pull the code from wallet_add and put it into the spot where it is called in main it will display the Group properly.

How do I get the ability to call in a function?

fn main() {
    let cursqllogin = Sqllogin {
        usrname: String::from("root"),
        pasword: String::from("system"),
    };

    crypto_sql::sql_run_check();

    usrlogin(cursqllogin);

    //
    //   Block Main1 Start
    //
    //      This block of code builds the main screen that the user first sees and makes selections from.
    //      Main owner John Galway
    //

    let app = App::default().with_scheme(Scheme::Gtk);
    let mut win = Window::default()
        .with_size(1240, 625)
        .center_screen()
        .with_label("Crypto Tracker");
    win.end();
    win.set_align(unsafe { std::mem::transmute(17) });
    win.make_resizable(true);
    win.show();
    let mut menu = MenuBar::new(0, 0, 1237, 30, "File");
    menu.end();
    win.add(&menu);
    menu.add("File/Preferences", Shortcut::None, MenuFlag::Normal, |_| {});
    menu.add("File/Exit", Shortcut::None, MenuFlag::Normal, |_| {
        std::process::exit(0)
    });
    menu.add(
        "Transactions/Wallet or Exchange",
        Shortcut::None,
        MenuFlag::Normal,
        move |_| {
            wallet_add(&win);
        },
    );
    menu.add(
        "Transactions/Coins",
        Shortcut::None,
        MenuFlag::Normal,
        move |_| {
            
        },
    );
    menu.add(
        "Transactions/Transactions",
        Shortcut::None,
        MenuFlag::Normal,
        |_| {},
    );
    menu.add(
        "Reports/Manual Pricing",
        Shortcut::None,
        MenuFlag::Normal,
        |_| {},
    );
    menu.add(
        "Reports/Gains Report",
        Shortcut::None,
        MenuFlag::Normal,
        |_| {},
    );
    menu.add(
        "Automation/Coin Pricing",
        Shortcut::None,
        MenuFlag::Normal,
        |_| {},
    );
    menu.add(
        "Automation/Harvest Transactions",
        Shortcut::None,
        MenuFlag::Normal,
        |_| {},
    );

    app.run().unwrap();
}

pub fn wallet_add(mut i32: winw){
    println!("in wallet trans");
    let mut wall_group = Group::new(50, 90, 500, 300, "Wallet Data Add/Change/Delete");
    wall_group.end();
    winw.redraw();
    wall_group.set_frame(FrameType::FlatBox);
    wall_group.set_color(Color::by_index(2));
    winw.add(&wall_group);
    let mut wall_name = fltk::input::Input::new(180, 105, 170, 20, "Wallet Name:");
    wall_group.add(&wall_name);
    let mut wall_username = fltk::input::Input::new(180, 130, 170, 20, "Wallet Username:");
    wall_group.add(&wall_username);
    let mut wall_password = fltk::input::Input::new(180, 155, 170, 20, "Wallet Password:");
    wall_group.add(&wall_password);
    let mut btn_wall_add = fltk::button::Button::new(180, 190, 60, 20, "Add");
    wall_group.add(&btn_wall_add);
    let mut btn_wall_delete = fltk::button::Button::new(260, 190, 60, 20, "Delete");
    wall_group.add(&btn_wall_delete);
}

pub fn wallet_add(mut i32: winw) this function signature is wrong. Try changing it to pub fn wallet_add(winw: &mut Window) , then call it in the main function before app.run().unwrap();

walledt_add(&mut winw);
app.run().unwrap();

Also note that the code style isn't idiomatic, although it might be auto-generated by fl2rust.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM