Initial egui-eframe hello world application

This commit is contained in:
Mike Dilger 2022-12-20 19:07:05 +13:00
parent b31d1f4334
commit fe541f9e6e
4 changed files with 1703 additions and 9 deletions

1654
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -13,6 +13,7 @@ edition = "2021"
[dependencies] [dependencies]
dirs = "4.0" dirs = "4.0"
eframe = "0.20"
lazy_static = "1.4" lazy_static = "1.4"
nostr-proto = { git = "https://github.com/mikedilger/nostr-proto", branch = "master" } nostr-proto = { git = "https://github.com/mikedilger/nostr-proto", branch = "master" }
rusqlite = { version = "0.28", features = ["bundled", "chrono", "serde_json"] } rusqlite = { version = "0.28", features = ["bundled", "chrono", "serde_json"] }

View File

@ -1,3 +1,5 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
#[macro_use] #[macro_use]
extern crate lazy_static; extern crate lazy_static;
@ -5,7 +7,15 @@ mod comms;
mod db; mod db;
mod error; mod error;
mod globals; mod globals;
mod ui;
fn main() { fn main() {
tracing_subscriber::fmt::init(); tracing_subscriber::fmt::init();
// TBD: start async code
ui::run();
// TBD: Tell the async parties to close down
// TBD: wait for the async parties to close down
} }

47
src/ui/mod.rs Normal file
View File

@ -0,0 +1,47 @@
use eframe::egui;
pub fn run() {
let options = eframe::NativeOptions {
initial_window_size: Some(egui::vec2(320.0, 240.0)),
..Default::default()
};
eframe::run_native(
"My egui App",
options,
Box::new(|_cc| Box::new(MyApp::default())),
)
}
struct MyApp {
name: String,
age: u32,
}
impl Default for MyApp {
fn default() -> Self {
Self {
name: "Arthur".to_owned(),
age: 42,
}
}
}
impl eframe::App for MyApp {
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("Click each year").clicked() {
self.age += 1;
}
ui.label(format!("Hello '{}', age {}", self.name, self.age));
});
}
}