Skip to content

Commit 086d033

Browse files
bashhacknus
authored andcommitted
Add return value to with_accessibility_parent (emilk#5083)
Extracted out of emilk#4805 In [`egui-theme-switch`] I'm allocating a response inside the closure passed to `with_accessibility_parent` so that my radio buttons have the radio group as parent. I'm working around the lack of return value with a custom extension trait for now: [`ContextExt`] * [x] I have followed the instructions in the PR template [`egui-theme-switch`]: https://github.com/bash/egui-theme-switch/blob/main/src/lib.rs [`ContextExt`]: https://github.com/bash/egui-theme-switch/blob/main/src/context_ext.rs
1 parent dbc808c commit 086d033

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

crates/egui/src/context.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -2887,9 +2887,9 @@ impl Context {
28872887
/// the function is still called, but with no other effect.
28882888
///
28892889
/// No locks are held while the given closure is called.
2890-
#[allow(clippy::unused_self)]
2890+
#[allow(clippy::unused_self, clippy::let_and_return)]
28912891
#[inline]
2892-
pub fn with_accessibility_parent(&self, _id: Id, f: impl FnOnce()) {
2892+
pub fn with_accessibility_parent<R>(&self, _id: Id, f: impl FnOnce() -> R) -> R {
28932893
// TODO(emilk): this isn't thread-safe - another thread can call this function between the push/pop calls
28942894
#[cfg(feature = "accesskit")]
28952895
self.frame_state_mut(|fs| {
@@ -2898,14 +2898,16 @@ impl Context {
28982898
}
28992899
});
29002900

2901-
f();
2901+
let result = f();
29022902

29032903
#[cfg(feature = "accesskit")]
29042904
self.frame_state_mut(|fs| {
29052905
if let Some(state) = fs.accesskit_state.as_mut() {
29062906
assert_eq!(state.parent_stack.pop(), Some(_id));
29072907
}
29082908
});
2909+
2910+
result
29092911
}
29102912

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

0 commit comments

Comments
 (0)