Skip to content

Instantly share code, notes, and snippets.

@osa1
Last active September 16, 2023 08:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save osa1/2d91ea107df8ec1a06dc5e4522621bfd to your computer and use it in GitHub Desktop.
Save osa1/2d91ea107df8ec1a06dc5e4522621bfd to your computer and use it in GitHub Desktop.
use eframe::egui;
fn main() -> Result<(), eframe::Error> {
let options = eframe::NativeOptions {
drag_and_drop_support: true,
initial_window_size: Some(egui::vec2(320.0, 240.0)),
..Default::default()
};
eframe::run_native(
"Native file dialogs and drag-and-drop files",
options,
Box::new(|_cc| Box::<MyApp>::default()),
)
}
#[derive(Default)]
struct MyApp {
input1: String,
input2: String,
age: u32,
frame: u64,
widget_order: bool,
}
impl eframe::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
if self.frame % 100 == 0 {
self.widget_order = !self.widget_order;
}
ui.heading("My egui Application");
ui.horizontal(|ui| {
if self.widget_order {
let id1 = ui.text_edit_singleline(&mut self.input1).id;
let id2 = ui.text_edit_singleline(&mut self.input2).id;
dbg!((id1, id2));
} else {
let id2 = ui.text_edit_singleline(&mut self.input2).id;
let id1 = ui.text_edit_singleline(&mut self.input1).id;
dbg!((id1, id2));
}
});
ui.add(egui::Slider::new(&mut self.age, 0..=120).text("age"));
if ui.button("Click each year").clicked() {
self.age += 1;
}
ui.label(format!("input1 = {}, input2 = {}", self.input1, self.input2));
self.frame += 1;
dbg!(self.frame);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment