Skip to content

Commit

Permalink
Add return value to with_accessibility_parent
Browse files Browse the repository at this point in the history
  • Loading branch information
bash committed Sep 6, 2024
1 parent 6b7f431 commit e1c53ff
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions crates/egui/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2887,9 +2887,9 @@ impl Context {
/// the function is still called, but with no other effect.
///
/// No locks are held while the given closure is called.
#[allow(clippy::unused_self)]
#[allow(clippy::unused_self, clippy::let_and_return)]
#[inline]
pub fn with_accessibility_parent(&self, _id: Id, f: impl FnOnce()) {
pub fn with_accessibility_parent<R>(&self, _id: Id, f: impl FnOnce() -> R) -> R {
// TODO(emilk): this isn't thread-safe - another thread can call this function between the push/pop calls
#[cfg(feature = "accesskit")]
self.frame_state_mut(|fs| {
Expand All @@ -2898,14 +2898,16 @@ impl Context {
}
});

f();
let result = f();

#[cfg(feature = "accesskit")]
self.frame_state_mut(|fs| {
if let Some(state) = fs.accesskit_state.as_mut() {
assert_eq!(state.parent_stack.pop(), Some(_id));
}
});

result
}

/// If AccessKit support is active for the current frame, get or create
Expand Down

0 comments on commit e1c53ff

Please sign in to comment.