initial egui damus app

This commit is contained in:
William Casarin 2022-11-06 16:42:20 -08:00
parent 696caa1f1c
commit ce21e10c90
6 changed files with 52 additions and 50 deletions

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
.build-result
.buildcmd
/target
/dist

24
Cargo.lock generated
View File

@ -345,6 +345,18 @@ version = "0.2.2"
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"
@ -470,18 +482,6 @@ dependencies = [
"winit",
]
[[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"

View File

@ -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"

View File

@ -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

View File

@ -1,4 +1,4 @@
#![warn(clippy::all, rust_2018_idioms)]
mod app;
pub use app::TemplateApp;
pub use app::Damus;

View File

@ -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");
}