Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid deadlocks by using lambdas for context lock #2625

Merged
merged 26 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Code cleanup
  • Loading branch information
emilk committed Jan 24, 2023
commit 98637da4edf59714de8a1e4159d5cab6f44c69af
6 changes: 3 additions & 3 deletions crates/egui/src/containers/scroll_area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,9 @@ impl ScrollArea {
if content_response.dragged() {
for d in 0..2 {
if has_bar[d] {
ui.input(|i| {
state.offset[d] -= i.pointer.delta()[d];
state.vel[d] = i.pointer.velocity()[d];
ui.input(|input| {
state.offset[d] -= input.pointer.delta()[d];
state.vel[d] = input.pointer.velocity()[d];
});
state.scroll_stuck_to_end[d] = false;
} else {
Expand Down
4 changes: 3 additions & 1 deletion crates/egui/src/painter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ impl Painter {
&self.ctx
}

/// Available fonts.
/// Read-only access to the shared [`Fonts`].
///
/// See [`Context`] documentation for how locks work.
#[inline(always)]
pub fn fonts<R>(&self, reader: impl FnOnce(&Fonts) -> R) -> R {
self.ctx.fonts(reader)
Expand Down
4 changes: 2 additions & 2 deletions crates/egui/src/widgets/drag_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,8 @@ impl<'a> Widget for DragValue<'a> {
#[cfg(feature = "accesskit")]
{
use accesskit::{Action, ActionData};
ui.input(|i| {
for request in i.accesskit_action_requests(id, Action::SetValue) {
ui.input(|input| {
for request in input.accesskit_action_requests(id, Action::SetValue) {
if let Some(ActionData::NumericValue(new_value)) = request.data {
value = new_value;
}
Expand Down
3 changes: 2 additions & 1 deletion crates/egui/src/widgets/progress_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ impl Widget for ProgressBar {

let (dark, bright) = (0.7, 1.0);
let color_factor = if animate {
lerp(dark..=bright, ui.input(|i| i.time).cos().abs())
let time = ui.input(|i| i.time);
lerp(dark..=bright, time.cos().abs())
} else {
bright
};
Expand Down
24 changes: 12 additions & 12 deletions crates/egui/src/widgets/slider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,18 +562,18 @@ impl<'a> Slider<'a> {
SliderOrientation::Vertical => (Key::ArrowUp, Key::ArrowDown),
};

ui.input(|i| {
decrement += i.num_presses(dec_key);
increment += i.num_presses(inc_key);
ui.input(|input| {
decrement += input.num_presses(dec_key);
increment += input.num_presses(inc_key);
});
}

#[cfg(feature = "accesskit")]
{
use accesskit::Action;
ui.input(|i| {
decrement += i.num_accesskit_action_requests(response.id, Action::Decrement);
increment += i.num_accesskit_action_requests(response.id, Action::Increment);
ui.input(|input| {
decrement += input.num_accesskit_action_requests(response.id, Action::Decrement);
increment += input.num_accesskit_action_requests(response.id, Action::Increment);
});
}

Expand All @@ -600,8 +600,8 @@ impl<'a> Slider<'a> {
#[cfg(feature = "accesskit")]
{
use accesskit::{Action, ActionData};
ui.input(|i| {
for request in i.accesskit_action_requests(response.id, Action::SetValue) {
ui.input(|input| {
for request in input.accesskit_action_requests(response.id, Action::SetValue) {
if let Some(ActionData::NumericValue(new_value)) = request.data {
self.set_value(new_value);
}
Expand Down Expand Up @@ -693,10 +693,10 @@ impl<'a> Slider<'a> {

fn value_ui(&mut self, ui: &mut Ui, position_range: RangeInclusive<f32>) -> Response {
// If [`DragValue`] is controlled from the keyboard and `step` is defined, set speed to `step`
let change = ui.input(|i| {
i.num_presses(Key::ArrowUp) as i32 + i.num_presses(Key::ArrowRight) as i32
- i.num_presses(Key::ArrowDown) as i32
- i.num_presses(Key::ArrowLeft) as i32
let change = ui.input(|input| {
input.num_presses(Key::ArrowUp) as i32 + input.num_presses(Key::ArrowRight) as i32
- input.num_presses(Key::ArrowDown) as i32
- input.num_presses(Key::ArrowLeft) as i32
});

let any_change = change != 0;
Expand Down