簡體   English   中英

如何在函數中調用 FLTK 代碼?

[英]How do I call an FLTK code in a function?

我是 Rust 的新手,正在使用 FLTK 構建界面。 我有以下主要代碼。 下面是一個我想調用以建立一個組的函數。 如果在 main.rs 中我從 wallet_add 中提取代碼並將其放入 main 中調用它的位置,它將正確顯示組。

我如何獲得調用函數的能力?

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)這個函數簽名是錯誤的。 嘗試將其更改為pub fn wallet_add(winw: &mut Window) ,然后在app.run().unwrap();之前在主函數中調用它app.run().unwrap();

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

另請注意,代碼樣式不是慣用的,盡管它可能是由 fl2rust 自動生成的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM