Skip to content

Commit

Permalink
Remove highlight_this_frame
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Jul 3, 2024
1 parent 8568150 commit 5a03690
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
11 changes: 10 additions & 1 deletion crates/egui/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,14 @@ impl Context {
self.write(move |ctx| writer(&mut ctx.viewport().frame_state))
}

/// Read-only access to the [`FrameState`] from the previous frame.
///
/// This is swapped at the end of each frame.
#[inline]
pub(crate) fn prev_frame_state<R>(&self, reader: impl FnOnce(&FrameState) -> R) -> R {
self.write(move |ctx| reader(&ctx.viewport().prev_frame_state))
}

/// Read-only access to [`Fonts`].
///
/// Not valid until first call to [`Context::run()`].
Expand Down Expand Up @@ -1108,7 +1116,8 @@ impl Context {
enabled,
} = widget_rect;

let highlighted = self.frame_state(|fs| fs.highlight_this_frame.contains(&id));
// previous frame + "highlight next frame" == "highlight this frame"
let highlighted = self.prev_frame_state(|fs| fs.highlight_next_frame.contains(&id));

let mut res = Response {
ctx: self.clone(),
Expand Down
9 changes: 2 additions & 7 deletions crates/egui/src/frame_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,7 @@ pub struct FrameState {
#[cfg(feature = "accesskit")]
pub accesskit_state: Option<AccessKitFrameState>,

/// Highlight these widgets this next frame. Read from this.
pub highlight_this_frame: IdSet,

/// Highlight these widgets the next frame. Write to this.
/// Highlight these widgets the next frame.
pub highlight_next_frame: IdSet,

#[cfg(debug_assertions)]
Expand All @@ -92,7 +89,6 @@ impl Default for FrameState {
scroll_delta: Vec2::default(),
#[cfg(feature = "accesskit")]
accesskit_state: None,
highlight_this_frame: Default::default(),
highlight_next_frame: Default::default(),

#[cfg(debug_assertions)]
Expand All @@ -114,7 +110,6 @@ impl FrameState {
scroll_delta,
#[cfg(feature = "accesskit")]
accesskit_state,
highlight_this_frame,
highlight_next_frame,

#[cfg(debug_assertions)]
Expand All @@ -139,7 +134,7 @@ impl FrameState {
*accesskit_state = None;
}

*highlight_this_frame = std::mem::take(highlight_next_frame);
highlight_next_frame.clear();
}

/// How much space is still available after panels has been added.
Expand Down

0 comments on commit 5a03690

Please sign in to comment.