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

Crash on pause and timeline focus capture fixed #159

Merged
merged 1 commit into from
Dec 30, 2024
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
17 changes: 16 additions & 1 deletion frontend/app/src/simulation_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,21 @@ impl Component for SimulationWindow {
Msg::TimelineEvent(slider_value)
});

// We need a separate callback for the onchange event because the input event is not fired on release
// which causes the timeline to remain focused which captures all key events
let timeline_on_change_cb = context.link().callback(|event: Event| {
let target = event
.target()
.expect("Event should have a target when dispatched");

let slider_value = target
.unchecked_into::<HtmlInputElement>()
.value_as_number()
.round() as usize;

Msg::TimelineEvent(slider_value)
});

create_portal(
html! {
<>
Expand All @@ -225,7 +240,7 @@ impl Component for SimulationWindow {
onpointerup={pointer_event_cb.clone()}
onpointerdown={pointer_event_cb}
onblur={blur_event_cb} />
<input ref={self.timeline_ref.clone()} type="range" oninput={timeline_event_cb} class="slider"/>
<input ref={self.timeline_ref.clone()} type="range" oninput={timeline_event_cb} onchange={timeline_on_change_cb} class="slider"/>
<div class="status" ref={self.status_ref.clone()} />
<div class="picked">
<pre ref={self.picked_ref.clone()}></pre>
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ impl UI {
self.steps_forward = 0;
self.steps_backward = 0;
self.is_buffering = false;
self.last_render_time = instant::Instant::now();
// No time should elapse while pausing
self.last_render_time = now;
}
if self.keys_pressed.contains("KeyN") {
self.paused = true;
Expand Down Expand Up @@ -390,7 +391,6 @@ impl UI {

self.frame_timer
.end((instant::Instant::now() - self.start_time).as_millis() as f64);

self.keys_pressed.clear();
}

Expand Down
Loading