Skip to content

Commit

Permalink
Document
Browse files Browse the repository at this point in the history
  • Loading branch information
nanoqsh committed Apr 24, 2024
1 parent 481cc38 commit 6881166
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dunge/src/el.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ where
}
}

/// The main event loop control type.
/// The control type of the main event loop.
pub struct Control {
view: View,
resized: Option<(u32, u32)>,
Expand Down
26 changes: 26 additions & 0 deletions dunge/src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,32 @@ use crate::{
/// dunge::update(upd, draw)
/// }
/// ```
///
/// # Shared state
/// Draw and update stages may share some state.
/// This is not a problem to implement traits manually for some type.
/// However, to be able to use helpers, dunge has the [`update_with_state`] function.
/// ```rust
/// use dunge::{Control, Frame, Update};
///
/// struct State { counter: usize }
///
/// fn make_update() -> impl Update {
/// let draw = |state: &State, frame: Frame| {
/// dbg!(state.counter);
/// };
///
/// let upd = |state: &mut State, ctrl: &Control| {
/// state.counter += 1;
/// };
///
/// let state = State { counter: 0 };
/// dunge::update_with_state(state, upd, draw)
/// }
/// ```
///
/// Also see the [`update_with_event`] function to set a custom event handler.
///
pub trait Update: Draw {
type Flow: Flow;
type Event;
Expand Down

0 comments on commit 6881166

Please sign in to comment.