【问题标题】:How stop auto refresh of egui screen如何停止egui屏幕的自动刷新
【发布时间】:2022-09-25 16:16:13
【问题描述】:

我有以下菜单项

fn update(&mut self, ctx: &egui::Context, frame: &epi::Frame) {
    //let Self { label, value } = self; 

    // Examples of how to create different panels and windows.
    // Pick whichever suits you.
    // Tip: a good default choice is to just keep the `CentralPanel`.
    // For inspiration and more examples, go to https://emilk.github.io/egui

    egui::TopBottomPanel::top(\"top_panel\").show(ctx, |ui| {
        // The top panel is often a good place for a menu bar:
        egui::menu::bar(ui, |ui| {
            ui.menu_button(\"File\", |ui| {
                if ui.button(\"Quit\").clicked() {
                    frame.quit();
                }
            });
            ui.menu_button(\"Items\", |ui| {
                if ui.button(\"Exchanges\").clicked() {
                    println!(\"Exchanges\");
                    ui.close_menu();
                    exchange_trans(ctx);
                                        }
                if ui.button(\"Coins\").clicked() {
                    println!(\"Coins\");
                    ui.close_menu();
                }
                if ui.button(\"Transactions\").clicked() {
                    println!(\"Transactions\");
                    ui.close_menu();
                }
            });

我打电话 \'\'\'

pub fn exchange_trans(ctx: &egui::Context) {
    egui::SidePanel::left(\"side_panel\").show(ctx, |ui| {
        ui.heading(\"My egui Application\");
    ui.horizontal(|ui| {
        ui.label(\"Your name: \");
        ui.group(|ui| {
            ui.label(\"Within a frame\");
            ui.set_min_height(200.0);
        });
        
       // ui.text_edit_singleline(&mut name);
    });
}

\'\'\' 问题是当可以选择菜单项时会出现黑屏。当我选择 Exchange 菜单项时,屏幕会闪烁,然后由黑变黑。我认为刷新率设置为连续,我需要将其设置为反应性。我该怎么做,或者我走错了路。

    标签: rust egui


    【解决方案1】:

    我会尝试像示例中那样做 https://github.com/emilk/eframe_template/blob/master/src/app.rs

     fn update(..) {
       ...
       if my_variable {
         egui::SidePanel::left("side_panel").show(ctx, |ui| {
            ui.heading("My egui Application");
            ....
        });  
       }
    }
    

    并从菜单中将 my_variable 更改为 true 或 false - 不执行方法 exchange_trans(ctx); 因为它将被更新覆盖

                 ui.menu_button("Items", |ui| {
                    if ui.button("Exchanges").clicked() {
                        println!("Exchanges");
                        ui.close_menu();
                        my_variable = !my_variable;
    

    【讨论】:

      猜你喜欢
      • 2014-04-01
      • 2018-11-03
      • 1970-01-01
      • 1970-01-01
      • 2016-09-17
      • 2023-04-05
      • 1970-01-01
      • 1970-01-01
      • 2022-07-17
      相关资源
      最近更新 更多