Skip to content

Commit

Permalink
WindowBehavior::initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
ecton committed Sep 13, 2024
1 parent eb70033 commit 236c977
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
area of the window.
- `App::prevent_shutdown()` returns a guard that prevents the application from
closing automatically when the final window is closed.
- `WindowBehavior::initialized` is invoked once the window has been fully
initialized.

## v0.10.0 (2024-08-20)

Expand Down
10 changes: 5 additions & 5 deletions Cargo.lock

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

15 changes: 15 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,10 @@ where
NonZeroU32::new(4).assert("4 is less than u32::MAX")
}

/// Executed once after the window has been fully initialized.
#[allow(unused_variables)]
fn initialized(&mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine) {}

/// Prepare the window to render.
///
/// This is called directly before [`render()`](Self::render()) and is a
Expand Down Expand Up @@ -1299,6 +1303,17 @@ where
}
}

fn initialized(&mut self, window: &mut RunningWindow<AppEvent<User>>) {
self.behavior.initialized(
Window::new(
window,
self.last_render.elapsed(),
self.last_render_duration,
),
&mut self.kludgine,
);
}

fn redraw(&mut self, window: &mut RunningWindow<AppEvent<User>>) {
if self.config.width > 0 && self.config.height > 0 {
let Some(surface) = self.current_surface_texture(window) else {
Expand Down

0 comments on commit 236c977

Please sign in to comment.