Skip to content

Commit

Permalink
Simplify and move CloseRequested
Browse files Browse the repository at this point in the history
  • Loading branch information
konkitoman committed Nov 8, 2023
1 parent e9b57e6 commit 9676115
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 20 deletions.
4 changes: 1 addition & 3 deletions crates/egui-winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,7 @@ impl State {

// Things that may require repaint:
WindowEvent::CloseRequested => {
self.egui_input
.events
.push(egui::Event::WindowEvent(egui::WindowEvent::CloseRequested));
self.egui_input.viewport.close_requested = true;
EventResponse {
consumed: true,
repaint: true,
Expand Down
1 change: 0 additions & 1 deletion crates/egui/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ impl ContextImpl {
self.memory.begin_frame(
self.input.get(&viewport_id).unwrap_or(&Default::default()),
&new_raw_input,
viewport_id,
);

let input = self
Expand Down
15 changes: 5 additions & 10 deletions crates/egui/src/data/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ impl Default for RawInput {
events: vec![],
hovered_files: Default::default(),
dropped_files: Default::default(),
focused: true,
viewport: ViewportInfo::default(), // integrations opt into global focus tracking
focused: true, // integrations opt into global focus tracking
viewport: ViewportInfo::default(),
}
}
}
Expand Down Expand Up @@ -152,6 +152,9 @@ pub struct ViewportInfo {
/// Viewport outer position and size, drowable area + decorations
/// unit = physical pixels
pub outer_rect: Option<Rect>,

/// Viewport should close?
pub close_requested: bool,
}

impl ViewportInfo {
Expand Down Expand Up @@ -331,14 +334,6 @@ pub enum Event {
/// An assistive technology (e.g. screen reader) requested an action.
#[cfg(feature = "accesskit")]
AccessKitActionRequest(accesskit::ActionRequest),

WindowEvent(WindowEvent),
}

#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub enum WindowEvent {
CloseRequested,
}

/// Mouse button (or similar for touch input)
Expand Down
1 change: 0 additions & 1 deletion crates/egui/src/input_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ impl InputState {
};

let screen_rect = new.screen_rect.unwrap_or(self.screen_rect);

self.create_touch_states_for_new_devices(&new.events);
for touch_state in self.touch_states.values_mut() {
touch_state.begin_frame(time, &new, self.pointer.interact_pos);
Expand Down
9 changes: 4 additions & 5 deletions crates/egui/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,19 +543,18 @@ impl Memory {
&mut self,
prev_input: &crate::input_state::InputState,
new_input: &crate::data::input::RawInput,
viewport_id: ViewportId,
) {
crate::profile_function!();

self.viewport_id = viewport_id;
self.viewport_id = new_input.viewport.id_pair.this;
self.interactions
.entry(viewport_id)
.entry(self.viewport_id)
.or_default()
.begin_frame(prev_input, new_input);
self.areas.entry(viewport_id).or_default();
self.areas.entry(self.viewport_id).or_default();

if !prev_input.pointer.any_down() {
self.window_interactions.remove(&viewport_id);
self.window_interactions.remove(&self.viewport_id);
}
}

Expand Down

0 comments on commit 9676115

Please sign in to comment.