initial egui damus app
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,2 +1,4 @@
|
|||||||
|
.build-result
|
||||||
|
.buildcmd
|
||||||
/target
|
/target
|
||||||
/dist
|
/dist
|
||||||
|
|||||||
24
Cargo.lock
generated
24
Cargo.lock
generated
@@ -345,6 +345,18 @@ version = "0.2.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35"
|
checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "damus"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"console_error_panic_hook",
|
||||||
|
"eframe",
|
||||||
|
"egui",
|
||||||
|
"serde",
|
||||||
|
"tracing-subscriber",
|
||||||
|
"tracing-wasm",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "darling"
|
name = "darling"
|
||||||
version = "0.13.4"
|
version = "0.13.4"
|
||||||
@@ -470,18 +482,6 @@ dependencies = [
|
|||||||
"winit",
|
"winit",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "eframe_template"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"console_error_panic_hook",
|
|
||||||
"eframe",
|
|
||||||
"egui",
|
|
||||||
"serde",
|
|
||||||
"tracing-subscriber",
|
|
||||||
"tracing-wasm",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "egui"
|
name = "egui"
|
||||||
version = "0.19.0"
|
version = "0.19.0"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "eframe_template"
|
name = "damus"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
|
authors = ["William Casarin <jb55@jb55.com>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
rust-version = "1.60"
|
rust-version = "1.60"
|
||||||
|
|
||||||
|
|||||||
66
src/app.rs
66
src/app.rs
@@ -1,7 +1,7 @@
|
|||||||
/// We derive Deserialize/Serialize so we can persist app state on shutdown.
|
/// We derive Deserialize/Serialize so we can persist app state on shutdown.
|
||||||
#[derive(serde::Deserialize, serde::Serialize)]
|
#[derive(serde::Deserialize, serde::Serialize)]
|
||||||
#[serde(default)] // if we add new fields, give them default values when deserializing old state
|
#[serde(default)] // if we add new fields, give them default values when deserializing old state
|
||||||
pub struct TemplateApp {
|
pub struct Damus {
|
||||||
// Example stuff:
|
// Example stuff:
|
||||||
label: String,
|
label: String,
|
||||||
|
|
||||||
@@ -10,7 +10,7 @@ pub struct TemplateApp {
|
|||||||
value: f32,
|
value: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for TemplateApp {
|
impl Default for Damus {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
// Example stuff:
|
// Example stuff:
|
||||||
@@ -20,7 +20,7 @@ impl Default for TemplateApp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TemplateApp {
|
impl Damus {
|
||||||
/// Called once before the first frame.
|
/// Called once before the first frame.
|
||||||
pub fn new(cc: &eframe::CreationContext<'_>) -> Self {
|
pub fn new(cc: &eframe::CreationContext<'_>) -> Self {
|
||||||
// This is also where you can customized the look at feel of egui using
|
// 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.
|
/// Called by the frame work to save state before shutdown.
|
||||||
fn save(&mut self, storage: &mut dyn eframe::Storage) {
|
fn save(&mut self, storage: &mut dyn eframe::Storage) {
|
||||||
eframe::set_value(storage, eframe::APP_KEY, self);
|
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.
|
/// 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`.
|
/// Put your widgets into a `SidePanel`, `TopPanel`, `CentralPanel`, `Window` or `Area`.
|
||||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
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.
|
// Examples of how to create different panels and windows.
|
||||||
// Pick whichever suits you.
|
// Pick whichever suits you.
|
||||||
// Tip: a good default choice is to just keep the `CentralPanel`.
|
// 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| {
|
egui::SidePanel::left("side_panel").show(ctx, |ui| timeline_view(self, 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::CentralPanel::default().show(ctx, |ui| {
|
egui::CentralPanel::default().show(ctx, |ui| {
|
||||||
// The central panel the region left after adding TopPanel's and SidePanel's
|
// The central panel the region left after adding TopPanel's and SidePanel's
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#![warn(clippy::all, rust_2018_idioms)]
|
#![warn(clippy::all, rust_2018_idioms)]
|
||||||
|
|
||||||
mod app;
|
mod app;
|
||||||
pub use app::TemplateApp;
|
pub use app::Damus;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ fn main() {
|
|||||||
eframe::run_native(
|
eframe::run_native(
|
||||||
"eframe template",
|
"eframe template",
|
||||||
native_options,
|
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(
|
eframe::start_web(
|
||||||
"the_canvas_id", // hardcode it
|
"the_canvas_id", // hardcode it
|
||||||
web_options,
|
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");
|
.expect("failed to start eframe");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user