Skip to content

Commit

Permalink
Invert ignore_focus to allow_focus
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmerlin committed Sep 2, 2024
1 parent 6a3cd72 commit 4613e51
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion crates/egui/src/containers/area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ impl Area {
sense,
enabled,
},
false,
true,
);

if movable && move_response.dragged() {
Expand Down
2 changes: 1 addition & 1 deletion crates/egui/src/containers/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ fn resize_interaction(
sense: Sense::drag(),
enabled: true,
},
false,
true,
);
SideResponse {
hover: response.hovered(),
Expand Down
11 changes: 7 additions & 4 deletions crates/egui/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1049,8 +1049,11 @@ impl Context {
/// You should use [`Ui::interact`] instead.
///
/// If the widget already exists, its state (sense, Rect, etc) will be updated.
///
/// `allow_focus` should usually be true, unless you call this function multiple times with the
/// same widget, then `allow_focus` should only be true once (like in [`Ui::new`] (true) and [`Ui::interact_bg`] (false)).
#[allow(clippy::too_many_arguments)]
pub(crate) fn create_widget(&self, w: WidgetRect, ignore_focus: bool) -> Response {
pub(crate) fn create_widget(&self, w: WidgetRect, allow_focus: bool) -> Response {
// Remember this widget
self.write(|ctx| {
let viewport = ctx.viewport();
Expand All @@ -1060,12 +1063,12 @@ impl Context {
// but also to know when we have reached the widget we are checking for cover.
viewport.this_frame.widgets.insert(w.layer_id, w);

if w.sense.focusable && !ignore_focus {
if allow_focus && w.sense.focusable {
ctx.memory.interested_in_focus(w.id);
}
});

if !w.enabled || !w.sense.focusable || !w.layer_id.allow_interaction() && !ignore_focus {
if allow_focus && (!w.enabled || !w.sense.focusable || !w.layer_id.allow_interaction()) {
// Not interested or allowed input:
self.memory_mut(|mem| mem.surrender_focus(w.id));
}
Expand All @@ -1078,7 +1081,7 @@ impl Context {
let res = self.get_response(w);

#[cfg(feature = "accesskit")]
if w.sense.focusable && !ignore_focus {
if allow_focus && w.sense.focusable {
// Make sure anything that can receive focus has an AccessKit node.
// TODO(mwcampbell): For nodes that are filled from widget info,
// some information is written to the node twice.
Expand Down
2 changes: 1 addition & 1 deletion crates/egui/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ impl Response {
sense: self.sense | sense,
enabled: self.enabled,
},
false,
true,
)
}

Expand Down
8 changes: 4 additions & 4 deletions crates/egui/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl Ui {
sense,
enabled: ui.enabled,
},
false,
true,
);

if disabled {
Expand Down Expand Up @@ -295,7 +295,7 @@ impl Ui {
sense,
enabled: child_ui.enabled,
},
false,
true,
);

child_ui
Expand Down Expand Up @@ -973,7 +973,7 @@ impl Ui {
sense,
enabled: self.enabled,
},
false,
true,
)
}

Expand Down Expand Up @@ -1011,7 +1011,7 @@ impl Ui {
sense: self.sense,
enabled: self.enabled,
},
true,
false,
)
}

Expand Down

0 comments on commit 4613e51

Please sign in to comment.