feat: add basic eframe/egui application
This commit is contained in:
parent
79c904237a
commit
878827569f
3657
Cargo.lock
generated
Normal file
3657
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
|
@ -6,3 +6,4 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
eframe = "0.27.2"
|
||||
|
|
44
src/main.rs
44
src/main.rs
|
@ -1,3 +1,43 @@
|
|||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use eframe::egui;
|
||||
|
||||
fn main() -> Result<(), eframe::Error> {
|
||||
let options = eframe::NativeOptions {
|
||||
viewport: egui::ViewportBuilder::default().with_inner_size([320.0, 240.0]),
|
||||
..Default::default()
|
||||
};
|
||||
eframe::run_native(
|
||||
"My egui App",
|
||||
options,
|
||||
Box::new(|cc| Box::new(AmethystApp::new(cc))),
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct AmethystApp {
|
||||
name: String,
|
||||
age: u32,
|
||||
}
|
||||
|
||||
impl AmethystApp {
|
||||
fn new(_: &eframe::CreationContext<'_>) -> Self {
|
||||
Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl eframe::App for AmethystApp {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
ui.heading("My egui Application");
|
||||
ui.horizontal(|ui| {
|
||||
let name_label = ui.label("Your name: ");
|
||||
ui.text_edit_singleline(&mut self.name)
|
||||
.labelled_by(name_label.id);
|
||||
});
|
||||
ui.add(egui::Slider::new(&mut self.age, 0..=120).text("age"));
|
||||
if ui.button("Increment").clicked() {
|
||||
self.age += 1;
|
||||
}
|
||||
ui.label(format!("Hello '{}', age {}", self.name, self.age));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue