Skip to content

Commit

Permalink
Fixed hot-reloading bug (closes #22)
Browse files Browse the repository at this point in the history
  • Loading branch information
fschutt committed Oct 16, 2018
1 parent 427d057 commit 9ebdd12
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
18 changes: 13 additions & 5 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,6 @@ impl<T: Layout> App<T> {
force_redraw_cache[idx] = 2;
}

// TODO: use this!
let should_redraw_animations = window.run_all_animations();

// Update the window state that we got from the frame event (updates window dimensions and DPI)
window.update_from_external_window_state(&mut frame_event_info);
// Update the window state every frame that was set by the user
Expand All @@ -293,9 +290,20 @@ impl<T: Layout> App<T> {

if frame_event_info.should_redraw_window || force_redraw_cache[idx] > 0 {

if parsed_css_cache[idx].is_none() {
let should_update_parsed_css = {
// In debug mode, if hot-reloading is active, we want to always update the ParsedCss
#[cfg(not(debug_assertions))] {
parsed_css_cache[idx].is_none()
}
#[cfg(debug_assertions)] {
parsed_css_cache[idx].is_none() || window.css.hot_reload_path.is_some()
}
};

if should_update_parsed_css {
parsed_css_cache[idx] = Some(ParsedCss::from_css(&window.css));
}

let parsed_css = parsed_css_cache[idx].as_ref().unwrap();

// Call the Layout::layout() fn, get the DOM
Expand Down Expand Up @@ -334,7 +342,7 @@ impl<T: Layout> App<T> {
#[cfg(debug_assertions)] {
for (window_idx, window) in self.windows.iter_mut().enumerate() {
// Hot-reload CSS if necessary
if window.css.hot_reload_path.is_some() && Instant::now() - last_css_reload > Duration::from_millis(500) {
if window.css.hot_reload_path.is_some() && (Instant::now() - last_css_reload) > Duration::from_millis(500) {
window.css.reload_css();
window.css.needs_relayout = true;
last_css_reload = Instant::now();
Expand Down
9 changes: 1 addition & 8 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use gleam::gl::{self, Gl};
use {
cache::DomHash,
FastHashMap,
dom::{Texture, Callback, UpdateScreen},
dom::{Texture, Callback},
daemon::{Daemon, DaemonId},
css::{Css, FakeCss},
window_state::{WindowState, MouseState, KeyboardState, DebugState},
Expand Down Expand Up @@ -858,13 +858,6 @@ impl<T: Layout> Window<T> {
pub(crate) fn remove_unused_scroll_states(&mut self) {
self.scroll_states.retain(|_, state| state.used_this_frame);
}

/// Runs all animations currently registered in this DOM
#[must_use]
pub(crate) fn run_all_animations(&mut self) -> UpdateScreen {
// TODO
UpdateScreen::DontRedraw
}
}

pub(crate) fn get_gl_context(display: &Display) -> Result<Rc<Gl>, WindowCreateError> {
Expand Down

0 comments on commit 9ebdd12

Please sign in to comment.