notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

commit ce21e10c907c7db294a59ca2ea9189f46ee40989
parent 696caa1f1c4865599934fe90a14eba3ea7b8107d
Author: William Casarin <jb55@jb55.com>
Date:   Sun,  6 Nov 2022 16:42:20 -0800

initial egui damus app

Diffstat:
M.gitignore | 2++
MCargo.lock | 24++++++++++++------------
MCargo.toml | 4++--
Msrc/app.rs | 66+++++++++++++++++++++++++++++++++---------------------------------
Msrc/lib.rs | 2+-
Msrc/main.rs | 4++--
6 files changed, 52 insertions(+), 50 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,2 +1,4 @@ +.build-result +.buildcmd /target /dist diff --git a/Cargo.lock b/Cargo.lock @@ -346,6 +346,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35" [[package]] +name = "damus" +version = "0.1.0" +dependencies = [ + "console_error_panic_hook", + "eframe", + "egui", + "serde", + "tracing-subscriber", + "tracing-wasm", +] + +[[package]] name = "darling" version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -471,18 +483,6 @@ dependencies = [ ] [[package]] -name = "eframe_template" -version = "0.1.0" -dependencies = [ - "console_error_panic_hook", - "eframe", - "egui", - "serde", - "tracing-subscriber", - "tracing-wasm", -] - -[[package]] name = "egui" version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/Cargo.toml b/Cargo.toml @@ -1,7 +1,7 @@ [package] -name = "eframe_template" +name = "damus" version = "0.1.0" -authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"] +authors = ["William Casarin <jb55@jb55.com>"] edition = "2021" rust-version = "1.60" diff --git a/src/app.rs b/src/app.rs @@ -1,7 +1,7 @@ /// We derive Deserialize/Serialize so we can persist app state on shutdown. #[derive(serde::Deserialize, serde::Serialize)] #[serde(default)] // if we add new fields, give them default values when deserializing old state -pub struct TemplateApp { +pub struct Damus { // Example stuff: label: String, @@ -10,7 +10,7 @@ pub struct TemplateApp { value: f32, } -impl Default for TemplateApp { +impl Default for Damus { fn default() -> Self { Self { // Example stuff: @@ -20,7 +20,7 @@ impl Default for TemplateApp { } } -impl TemplateApp { +impl Damus { /// Called once before the first frame. pub fn new(cc: &eframe::CreationContext<'_>) -> Self { // This is also where you can customized the look at feel of egui using @@ -36,7 +36,35 @@ impl TemplateApp { } } -impl eframe::App for TemplateApp { +fn timeline_view(app: &mut Damus, ui: &mut egui::Ui) { + ui.heading("Timeline"); + + ui.horizontal(|ui| { + ui.label("Write something: "); + ui.text_edit_singleline(&mut app.label); + }); + + ui.add(egui::Slider::new(&mut app.value, 0.0..=10.0).text("value")); + if ui.button("Increment").clicked() { + app.value += 1.0; + } + + ui.with_layout(egui::Layout::bottom_up(egui::Align::LEFT), |ui| { + ui.horizontal(|ui| { + ui.spacing_mut().item_spacing.x = 0.0; + ui.label("powered by "); + ui.hyperlink_to("egui", "https://github.com/emilk/egui"); + ui.label(" and "); + ui.hyperlink_to( + "eframe", + "https://github.com/emilk/egui/tree/master/crates/eframe", + ); + ui.label("."); + }); + }); +} + +impl eframe::App for Damus { /// Called by the frame work to save state before shutdown. fn save(&mut self, storage: &mut dyn eframe::Storage) { eframe::set_value(storage, eframe::APP_KEY, self); @@ -45,8 +73,6 @@ impl eframe::App for TemplateApp { /// Called each time the UI needs repainting, which may be many times per second. /// Put your widgets into a `SidePanel`, `TopPanel`, `CentralPanel`, `Window` or `Area`. fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { - let Self { label, value } = self; - // Examples of how to create different panels and windows. // Pick whichever suits you. // Tip: a good default choice is to just keep the `CentralPanel`. @@ -64,33 +90,7 @@ impl eframe::App for TemplateApp { }); }); - egui::SidePanel::left("side_panel").show(ctx, |ui| { - ui.heading("Side Panel"); - - ui.horizontal(|ui| { - ui.label("Write something: "); - ui.text_edit_singleline(label); - }); - - ui.add(egui::Slider::new(value, 0.0..=10.0).text("value")); - if ui.button("Increment").clicked() { - *value += 1.0; - } - - ui.with_layout(egui::Layout::bottom_up(egui::Align::LEFT), |ui| { - ui.horizontal(|ui| { - ui.spacing_mut().item_spacing.x = 0.0; - ui.label("powered by "); - ui.hyperlink_to("egui", "https://github.com/emilk/egui"); - ui.label(" and "); - ui.hyperlink_to( - "eframe", - "https://github.com/emilk/egui/tree/master/crates/eframe", - ); - ui.label("."); - }); - }); - }); + egui::SidePanel::left("side_panel").show(ctx, |ui| timeline_view(self, ui)); egui::CentralPanel::default().show(ctx, |ui| { // The central panel the region left after adding TopPanel's and SidePanel's diff --git a/src/lib.rs b/src/lib.rs @@ -1,4 +1,4 @@ #![warn(clippy::all, rust_2018_idioms)] mod app; -pub use app::TemplateApp; +pub use app::Damus; diff --git a/src/main.rs b/src/main.rs @@ -11,7 +11,7 @@ fn main() { eframe::run_native( "eframe template", native_options, - Box::new(|cc| Box::new(eframe_template::TemplateApp::new(cc))), + Box::new(|cc| Box::new(damus::Damus::new(cc))), ); } @@ -28,7 +28,7 @@ fn main() { eframe::start_web( "the_canvas_id", // hardcode it web_options, - Box::new(|cc| Box::new(eframe_template::TemplateApp::new(cc))), + Box::new(|cc| Box::new(damus::Damus::new(cc))), ) .expect("failed to start eframe"); }