Skip to content

Commit

Permalink
use tokio to spawn server
Browse files Browse the repository at this point in the history
  • Loading branch information
DougAnderson444 committed Nov 7, 2024
1 parent c7bbc1b commit 70570e1
Show file tree
Hide file tree
Showing 6 changed files with 315 additions and 24 deletions.
83 changes: 79 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ eframe = { version = "0.29", default-features = false, features = [
"glow", # Use the glow rendering backend. Alternative: "wgpu".
"persistence", # Enable restoring app state when restarting the app.
] }

log = "0.4"

# You only need serde if you want app persistence:
Expand All @@ -29,6 +30,13 @@ tracing = "0.1"
# native:
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tokio = { version = "1", features = [
"time",
"rt",
"macros",
"sync",
"rt-multi-thread",
] }

# web:
[target.'cfg(target_arch = "wasm32")'.dependencies]
Expand Down
33 changes: 20 additions & 13 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct TemplateApp {
// Platform specific fields
#[serde(skip)]
/// Any platform that impls both [platform::PlatformTrait] and [Default]
platform: PlatformEnum,
platform: Platform,
}

impl Default for TemplateApp {
Expand Down Expand Up @@ -70,8 +70,10 @@ impl eframe::App for TemplateApp {

/// Called each time the UI needs repainting, which may be many times per second.
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
// Put your widgets into a `SidePanel`, `TopBottomPanel`, `CentralPanel`, `Window` or `Area`.
// For inspiration and more examples, go to https://emilk.github.io/egui
// pass the ctx to the platform
if !self.platform.egui_ctx() {

Check failure on line 74 in src/app.rs

View workflow job for this annotation

GitHub Actions / Check wasm32

no method named `egui_ctx` found for struct `Platform` in the current scope
self.platform.set_egui_ctx(ctx.clone());

Check failure on line 75 in src/app.rs

View workflow job for this annotation

GitHub Actions / Check wasm32

no method named `set_egui_ctx` found for struct `Platform` in the current scope
}

// set the style
style::style(ctx);
Expand All @@ -93,27 +95,32 @@ impl eframe::App for TemplateApp {
});
});

egui::TopBottomPanel::bottom("footer").show(ctx, |ui| {
ui.with_layout(egui::Layout::bottom_up(egui::Align::LEFT), |ui| {
powered_by_egui_and_eframe(ui);
ui.add(egui::github_link_file!(
"https://github.com/PeerPiper/egui-multinode/blob/main/",
"Source code"
));
egui::warn_if_debug_build(ui);
});
});

egui::CentralPanel::default().show(ctx, |ui| {
// The central panel the region left after adding TopPanel's and SidePanel's
ui.heading("PeerPiper Multinode");

platform::show(self, ui);
ui.vertical(|ui| {
platform::show(self, ui);
self.platform.show(ctx, ui);

Check failure on line 115 in src/app.rs

View workflow job for this annotation

GitHub Actions / Check wasm32

no method named `show` found for struct `Platform` in the current scope
});

ui.add(egui::Slider::new(&mut self.value, 0.0..=10.0).text("value"));
if ui.button("Increment").clicked() {
self.value += 1.0;
}

ui.separator();

ui.with_layout(egui::Layout::bottom_up(egui::Align::LEFT), |ui| {
powered_by_egui_and_eframe(ui);
ui.add(egui::github_link_file!(
"https://github.com/PeerPiper/egui-multinode/blob/main/",
"Source code"
));
egui::warn_if_debug_build(ui);
});
});
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/app/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ impl PlatformEnum {
Self::Web(platform) => platform.close(),
}
}

/// Show
pub fn show(&mut self, ctx: &egui::Context, ui: &mut egui::Ui) {
match self {
#[cfg(not(target_arch = "wasm32"))]
Self::Native(platform) => platform.show(ctx, ui),
#[cfg(target_arch = "wasm32")]
Self::Web(platform) => platform.show(ui),

Check failure on line 54 in src/app/platform.rs

View workflow job for this annotation

GitHub Actions / Check wasm32

no method named `show` found for mutable reference `&mut Platform` in the current scope
}
}
}

pub(crate) fn show(this: &mut super::TemplateApp, ui: &mut egui::Ui) {
Expand Down
Loading

0 comments on commit 70570e1

Please sign in to comment.