0

I have 2 structs that represent different windows. Each have its own implementation where window layout described. How to make window switch on button click? I am using EGui but if you have experience with other ui's, like Dear ImGui, I will also appreciate if you point in general direction.

#[derive(Default)]
struct Content {
    val: i32,
}

#[derive(Default)]
struct Content2 {
    val: i32,
}

impl eframe::App for Content {
    fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
        egui::CentralPanel::default().show(ctx, |ui| {
            if ui.button("Switch to window 2").clicked() {
                //switching action
            }            
        });
    }
}

impl eframe::App for Content2 {
    fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
        egui::CentralPanel::default().show(ctx, |ui| {
            if ui.button("Switch to window 1").clicked() {
                //switching action
            }            
        });
    }
}

fn main() -> Result<(), eframe::Error> {
    
    let options = eframe::NativeOptions::default();
    
    eframe::run_native(
        "My App",
        options,
        Box::new(|_cc| Box::<Content>::default()),
    )   //a way to show first window
    
}
Mbroo
  • 29
  • 5

0 Answers0