Last active
September 16, 2023 08:36
-
-
Save osa1/2d91ea107df8ec1a06dc5e4522621bfd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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