Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

egui-web: Update web_location_hash when hash in URL changes #1140

Merged
merged 2 commits into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions egui_web/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ All notable changes to the `egui_web` integration will be noted in this file.
* Made the WebGL painter opt-in ([#1020](https://github.com/emilk/egui/pull/1020)).
* Fix glow failure Chrome ((#1092)[https://github.com/emilk/egui/pull/1092]).
* Shift-scroll will now result in horizontal scrolling on all platforms ((#1136)[https://github.com/emilk/egui/pull/1136]).
* Update `epi::IntegrationInfo::web_location_hash` on `hashchange` event ([#1140](https://github.com/emilk/egui/pull/1140)).


## 0.16.0 - 2021-12-29
Expand Down
2 changes: 1 addition & 1 deletion egui_web/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl epi::backend::RepaintSignal for NeedRepaint {
// ----------------------------------------------------------------------------

pub struct AppRunner {
frame: epi::Frame,
pub(crate) frame: epi::Frame,
egui_ctx: egui::Context,
painter: Box<dyn Painter>,
pub(crate) input: WebInput,
Expand Down
16 changes: 16 additions & 0 deletions egui_web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,22 @@ fn install_document_events(runner_ref: &AppRunnerRef) -> Result<(), JsValue> {
closure.forget();
}

{
// hashchange
let runner_ref = runner_ref.clone();
let closure = Closure::wrap(Box::new(move || {
let runner_lock = runner_ref.0.lock();
let mut frame_lock = runner_lock.frame.lock();

// `epi::Frame::info(&self)` clones `epi::IntegrationInfo`, but we need to modify the original here
if let Some(web_info) = &mut frame_lock.info.web_info {
web_info.web_location_hash = location_hash().unwrap_or_default();
}
}) as Box<dyn FnMut()>);
window.add_event_listener_with_callback("hashchange", closure.as_ref().unchecked_ref())?;
closure.forget();
}

Ok(())
}

Expand Down