Skip to content

Commit

Permalink
Address reviewer's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
polwel committed Jan 6, 2025
1 parent c86e0af commit a69fa29
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
35 changes: 18 additions & 17 deletions crates/egui/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,8 @@ impl Context {

/// Do all interaction for an existing widget, without (re-)registering it.
pub(crate) fn get_response(&self, widget_rect: WidgetRect) -> Response {
use response::Flags;

let WidgetRect {
id,
layer_id,
Expand All @@ -1238,19 +1240,19 @@ impl Context {
rect,
interact_rect,
sense,
flags: response::Flags::empty(),
flags: Flags::empty(),
interact_pointer_pos: None,
intrinsic_size: None,
};

res.flags.set(response::Flags::ENABLED, enabled);
res.flags.set(response::Flags::HIGHLIGHTED, highlighted);
res.flags.set(Flags::ENABLED, enabled);
res.flags.set(Flags::HIGHLIGHTED, highlighted);

self.write(|ctx| {
let viewport = ctx.viewports.entry(ctx.viewport_id()).or_default();

res.flags.set(
response::Flags::CONTAINS_POINTER,
Flags::CONTAINS_POINTER,
viewport.interact_widgets.contains_pointer.contains(&id),
);

Expand All @@ -1263,45 +1265,45 @@ impl Context {
&& (input.key_pressed(Key::Space) || input.key_pressed(Key::Enter))
{
// Space/enter works like a primary click for e.g. selected buttons
res.flags.set(response::Flags::FAKE_PRIMARY_CLICKED, true);
res.flags.set(Flags::FAKE_PRIMARY_CLICKED, true);
}

#[cfg(feature = "accesskit")]
if enabled
&& sense.senses_click()
&& input.has_accesskit_action_request(id, accesskit::Action::Click)
{
res.flags.set(response::Flags::FAKE_PRIMARY_CLICKED, true);
res.flags.set(Flags::FAKE_PRIMARY_CLICKED, true);
}

if enabled && sense.senses_click() && Some(id) == viewport.interact_widgets.long_touched
{
res.flags.set(response::Flags::LONG_TOUCHED, true);
res.flags.set(Flags::LONG_TOUCHED, true);
}

let interaction = memory.interaction();

res.flags.set(
response::Flags::IS_POINTER_BUTTON_DOWN_ON,
Flags::IS_POINTER_BUTTON_DOWN_ON,
interaction.potential_click_id == Some(id)
|| interaction.potential_drag_id == Some(id),
);

if res.enabled() {
res.flags.set(
response::Flags::HOVERED,
Flags::HOVERED,
viewport.interact_widgets.hovered.contains(&id),
);
res.flags.set(
response::Flags::DRAGGED,
Flags::DRAGGED,
Some(id) == viewport.interact_widgets.dragged,
);
res.flags.set(
response::Flags::DRAG_STARTED,
Flags::DRAG_STARTED,
Some(id) == viewport.interact_widgets.drag_started,
);
res.flags.set(
response::Flags::DRAG_STOPPED,
Flags::DRAG_STOPPED,
Some(id) == viewport.interact_widgets.drag_stopped,
);
}
Expand All @@ -1317,12 +1319,11 @@ impl Context {
}
PointerEvent::Released { click, .. } => {
if enabled && sense.senses_click() && clicked && click.is_some() {
res.flags.set(response::Flags::CLICKED, true);
res.flags.set(Flags::CLICKED, true);
}

res.flags
.set(response::Flags::IS_POINTER_BUTTON_DOWN_ON, false);
res.flags.set(response::Flags::DRAGGED, false);
res.flags.set(Flags::IS_POINTER_BUTTON_DOWN_ON, false);
res.flags.set(Flags::DRAGGED, false);
}
}
}
Expand All @@ -1345,7 +1346,7 @@ impl Context {

if input.pointer.any_down() && !is_interacted_with {
// We don't hover widgets while interacting with *other* widgets:
res.flags.set(response::Flags::HOVERED, false);
res.flags.set(Flags::HOVERED, false);
}

let pointer_pressed_elsewhere = any_press && !res.hovered();
Expand Down
9 changes: 4 additions & 5 deletions crates/egui/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ pub struct Response {
pub intrinsic_size: Option<Vec2>,

#[doc(hidden)]
pub(crate) flags: Flags,
pub flags: Flags,
}

/// A bit set for various boolean properties of `Response`.
#[doc(hidden)]
#[derive(Copy, Clone, Debug)]
pub struct Flags(u16);

Expand Down Expand Up @@ -225,10 +227,7 @@ impl Response {
let pointer = &i.pointer;

if pointer.any_click() {
if self
.flags
.intersects(Flags::CONTAINS_POINTER | Flags::HOVERED)
{
if self.contains_pointer() || self.hovered() {
false
} else if let Some(pos) = pointer.interact_pos() {
!self.interact_rect.contains(pos)
Expand Down

0 comments on commit a69fa29

Please sign in to comment.