Skip to content
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: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ serde = { version = "1.0.219", features = ["derive"], optional = true }

[dev-dependencies]
grafo = "0.9"
#grafo = { path = "../grafo" }
winit = "0.30"
futures = "0.3"
env_logger = "0.11"
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@
//! let inner_size = state.inner_size();
//! }
//!
//! let mut remove_ids = vec![];
//! // Optional: going to remove all states that were not accessed during the current frame
//! text_manager.end_frame();
//! text_manager.end_frame(&mut remove_ids);
//! ```

mod action;
Expand Down
15 changes: 11 additions & 4 deletions src/text_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ impl<TMetadata> TextManager<TMetadata> {
/// Utility to do some simple garbage collection of text states if you don't want
/// to implement a usage tracker yourself. Call this at the end of each frame, and this will
/// remove any text states not marked as accessed since the last call to `start_frame`.
/// Accepts a mutable vector to which it will append the IDs of removed text states.
///
/// This helps prevent memory leaks when text states are no longer needed.
///
Expand All @@ -161,13 +162,19 @@ impl<TMetadata> TextManager<TMetadata> {
///
/// let mut manager: TextManager<()> = TextManager::new();
///
/// let mut removed_ids = Vec::new();
/// // At the end of each frame
/// manager.end_frame();
/// manager.end_frame(&mut removed_ids);
/// ```
pub fn end_frame(&mut self) {
pub fn end_frame(&mut self, removed_ids: &mut Vec<Id>) {
let accessed_states = self.text_context.usage_tracker.accessed_states();
self.text_states
.retain(|id, _| accessed_states.contains(id));
self.text_states.retain(|id, _| {
let accessed = accessed_states.contains(id);
if !accessed {
removed_ids.push(*id);
}
accessed
});
}

/// Sets the global scale factor used for shaping and rasterization.
Expand Down
Loading