1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-29 21:00:03 -04:00

Add http fetch to eframe and implement it in egui_glium using ureq

This commit is contained in:
Emil Ernerfeldt
2020-12-30 20:56:50 +01:00
parent 6d9cdafbc9
commit 9db1b8dbf9
13 changed files with 488 additions and 36 deletions

View File

@@ -10,10 +10,7 @@ crate-type = ["cdylib", "rlib"]
[dependencies]
eframe = { path = "../eframe" }
egui_web = { path = "../egui_web" }
image = { version = "0.23", default_features = false, features = ["jpeg", "png"] }
js-sys = "0.3"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
syntect = { version = "4", default_features = false, features = ["default-fancy"] }
wasm-bindgen = "0.2"

View File

@@ -1,5 +1,5 @@
use eframe::{egui, epi};
use egui_web::fetch::Response;
use epi::http::Response;
use std::sync::mpsc::Receiver;
struct Resource {
@@ -76,8 +76,9 @@ impl epi::App for ExampleApp {
let repaint_signal = integration_context.repaint_signal.clone();
let (sender, receiver) = std::sync::mpsc::channel();
self.in_progress = Some(receiver);
egui_web::spawn_future(async move {
sender.send(egui_web::fetch::get(&url).await).ok();
eframe::http::fetch(eframe::http::Request::get(url), move |response| {
sender.send(response).ok();
repaint_signal.request_repaint();
});
}

View File

@@ -3,6 +3,7 @@
#![warn(clippy::all)]
mod example_app;
pub use example_app::ExampleApp;
#[cfg(target_arch = "wasm32")]
use eframe::wasm_bindgen::{self, prelude::*};

9
example_web/src/main.rs Normal file
View File

@@ -0,0 +1,9 @@
#![forbid(unsafe_code)]
#![cfg_attr(not(debug_assertions), deny(warnings))] // Forbid warnings in release builds
#![warn(clippy::all)]
// When compiling natively:
fn main() {
let app = example_web::ExampleApp::default();
eframe::run_native(Box::new(app));
}