mirror of
https://github.com/mikedilger/gossip.git
synced 2024-10-01 09:21:53 +00:00
Initial egui-eframe hello world application
This commit is contained in:
parent
b31d1f4334
commit
fe541f9e6e
1654
Cargo.lock
generated
1654
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -13,6 +13,7 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
dirs = "4.0"
|
||||
eframe = "0.20"
|
||||
lazy_static = "1.4"
|
||||
nostr-proto = { git = "https://github.com/mikedilger/nostr-proto", branch = "master" }
|
||||
rusqlite = { version = "0.28", features = ["bundled", "chrono", "serde_json"] }
|
||||
|
10
src/main.rs
10
src/main.rs
@ -1,3 +1,5 @@
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
|
||||
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
|
||||
@ -5,7 +7,15 @@ mod comms;
|
||||
mod db;
|
||||
mod error;
|
||||
mod globals;
|
||||
mod ui;
|
||||
|
||||
fn main() {
|
||||
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
47
src/ui/mod.rs
Normal 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));
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user