Skip to content

Commit 6b3c0cb

Browse files
authored
feat: make end_frame method to return removed ids to the caller (#17)
1 parent 8ce1643 commit 6b3c0cb

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ serde = { version = "1.0.219", features = ["derive"], optional = true }
2323

2424
[dev-dependencies]
2525
grafo = "0.9"
26-
#grafo = { path = "../grafo" }
2726
winit = "0.30"
2827
futures = "0.3"
2928
env_logger = "0.11"

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@
5757
//! let inner_size = state.inner_size();
5858
//! }
5959
//!
60+
//! let mut remove_ids = vec![];
6061
//! // Optional: going to remove all states that were not accessed during the current frame
61-
//! text_manager.end_frame();
62+
//! text_manager.end_frame(&mut remove_ids);
6263
//! ```
6364
6465
mod action;

src/text_manager.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ impl<TMetadata> TextManager<TMetadata> {
152152
/// Utility to do some simple garbage collection of text states if you don't want
153153
/// to implement a usage tracker yourself. Call this at the end of each frame, and this will
154154
/// remove any text states not marked as accessed since the last call to `start_frame`.
155+
/// Accepts a mutable vector to which it will append the IDs of removed text states.
155156
///
156157
/// This helps prevent memory leaks when text states are no longer needed.
157158
///
@@ -161,13 +162,19 @@ impl<TMetadata> TextManager<TMetadata> {
161162
///
162163
/// let mut manager: TextManager<()> = TextManager::new();
163164
///
165+
/// let mut removed_ids = Vec::new();
164166
/// // At the end of each frame
165-
/// manager.end_frame();
167+
/// manager.end_frame(&mut removed_ids);
166168
/// ```
167-
pub fn end_frame(&mut self) {
169+
pub fn end_frame(&mut self, removed_ids: &mut Vec<Id>) {
168170
let accessed_states = self.text_context.usage_tracker.accessed_states();
169-
self.text_states
170-
.retain(|id, _| accessed_states.contains(id));
171+
self.text_states.retain(|id, _| {
172+
let accessed = accessed_states.contains(id);
173+
if !accessed {
174+
removed_ids.push(*id);
175+
}
176+
accessed
177+
});
171178
}
172179

173180
/// Sets the global scale factor used for shaping and rasterization.

0 commit comments

Comments
 (0)