mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 06:40:06 -04:00
Now Memory::interaction is stored per viewport in Memory::interactions
This will allow in the future drag and drop betwen windows Fixes if a an other window is rendered will forgot what was draging, this was very annoying
This commit is contained in:
@@ -240,6 +240,7 @@ impl ContextImpl {
|
|||||||
self.memory.begin_frame(
|
self.memory.begin_frame(
|
||||||
self.input.get(&viewport_id).unwrap_or(&Default::default()),
|
self.input.get(&viewport_id).unwrap_or(&Default::default()),
|
||||||
&new_raw_input,
|
&new_raw_input,
|
||||||
|
viewport_id,
|
||||||
);
|
);
|
||||||
|
|
||||||
let input = self
|
let input = self
|
||||||
@@ -1299,6 +1300,14 @@ impl Context {
|
|||||||
/// Call at the end of each frame.
|
/// Call at the end of each frame.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn end_frame(&self) -> FullOutput {
|
pub fn end_frame(&self) -> FullOutput {
|
||||||
|
let mut viewports: Vec<u64> = self.read(|ctx| {
|
||||||
|
ctx.viewports
|
||||||
|
.iter()
|
||||||
|
.map(|(_, (_, id, _, _, _))| *id)
|
||||||
|
.collect()
|
||||||
|
});
|
||||||
|
viewports.push(0);
|
||||||
|
|
||||||
if self.input(|i| i.wants_repaint()) {
|
if self.input(|i| i.wants_repaint()) {
|
||||||
self.request_repaint();
|
self.request_repaint();
|
||||||
}
|
}
|
||||||
@@ -1306,6 +1315,7 @@ impl Context {
|
|||||||
let textures_delta = self.write(|ctx| {
|
let textures_delta = self.write(|ctx| {
|
||||||
ctx.memory.end_frame(
|
ctx.memory.end_frame(
|
||||||
ctx.input.get(&ctx.current_rendering_viewport).unwrap(),
|
ctx.input.get(&ctx.current_rendering_viewport).unwrap(),
|
||||||
|
&viewports,
|
||||||
&ctx.frame_state.used_ids,
|
&ctx.frame_state.used_ids,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -1352,14 +1362,6 @@ impl Context {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut viewports: Vec<u64> = self.read(|ctx| {
|
|
||||||
ctx.viewports
|
|
||||||
.iter()
|
|
||||||
.map(|(_, (_, id, _, _, _))| *id)
|
|
||||||
.collect()
|
|
||||||
});
|
|
||||||
viewports.push(0);
|
|
||||||
|
|
||||||
self.write(|ctx| ctx.input.retain(|id, _| viewports.contains(&id)));
|
self.write(|ctx| ctx.input.retain(|id, _| viewports.contains(&id)));
|
||||||
|
|
||||||
let repaint_after = self.write(|ctx| {
|
let repaint_after = self.write(|ctx| {
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
use ahash::HashMap;
|
||||||
|
|
||||||
use crate::{area, window, Id, IdMap, InputState, LayerId, Pos2, Rect, Style};
|
use crate::{area, window, Id, IdMap, InputState, LayerId, Pos2, Rect, Style};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -69,9 +71,16 @@ pub struct Memory {
|
|||||||
#[cfg_attr(feature = "persistence", serde(skip))]
|
#[cfg_attr(feature = "persistence", serde(skip))]
|
||||||
pub(crate) new_font_definitions: Option<epaint::text::FontDefinitions>,
|
pub(crate) new_font_definitions: Option<epaint::text::FontDefinitions>,
|
||||||
|
|
||||||
|
#[cfg_attr(feature = "persistence", serde(skip))]
|
||||||
|
pub(crate) interactions: HashMap<u64, Interaction>,
|
||||||
|
|
||||||
#[cfg_attr(feature = "persistence", serde(skip))]
|
#[cfg_attr(feature = "persistence", serde(skip))]
|
||||||
pub(crate) interaction: Interaction,
|
pub(crate) interaction: Interaction,
|
||||||
|
|
||||||
|
// Current viewport
|
||||||
|
#[cfg_attr(feature = "persistence", serde(skip))]
|
||||||
|
pub(crate) viewport_id: u64,
|
||||||
|
|
||||||
#[cfg_attr(feature = "persistence", serde(skip))]
|
#[cfg_attr(feature = "persistence", serde(skip))]
|
||||||
pub(crate) window_interaction: Option<window::WindowInteraction>,
|
pub(crate) window_interaction: Option<window::WindowInteraction>,
|
||||||
|
|
||||||
@@ -354,19 +363,33 @@ impl Memory {
|
|||||||
&mut self,
|
&mut self,
|
||||||
prev_input: &crate::input_state::InputState,
|
prev_input: &crate::input_state::InputState,
|
||||||
new_input: &crate::data::input::RawInput,
|
new_input: &crate::data::input::RawInput,
|
||||||
|
viewport_id: u64,
|
||||||
) {
|
) {
|
||||||
self.interaction.begin_frame(prev_input, new_input);
|
self.viewport_id = viewport_id;
|
||||||
|
self.interactions
|
||||||
|
.entry(viewport_id)
|
||||||
|
.or_default()
|
||||||
|
.begin_frame(prev_input, new_input);
|
||||||
|
self.interaction = self.interactions.remove(&viewport_id).unwrap();
|
||||||
|
|
||||||
if !prev_input.pointer.any_down() {
|
if !prev_input.pointer.any_down() {
|
||||||
self.window_interaction = None;
|
self.window_interaction = None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn end_frame(&mut self, input: &InputState, used_ids: &IdMap<Rect>) {
|
pub(crate) fn end_frame(
|
||||||
|
&mut self,
|
||||||
|
input: &InputState,
|
||||||
|
viewports: &[u64],
|
||||||
|
used_ids: &IdMap<Rect>,
|
||||||
|
) {
|
||||||
self.caches.update();
|
self.caches.update();
|
||||||
self.areas.end_frame();
|
self.areas.end_frame();
|
||||||
self.interaction.focus.end_frame(used_ids);
|
self.interaction.focus.end_frame(used_ids);
|
||||||
|
self.interactions
|
||||||
|
.insert(self.viewport_id, std::mem::take(&mut self.interaction));
|
||||||
self.drag_value.end_frame(input);
|
self.drag_value.end_frame(input);
|
||||||
|
self.interactions.retain(|id, _| viewports.contains(id))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Top-most layer at the given position.
|
/// Top-most layer at the given position.
|
||||||
|
|||||||
Reference in New Issue
Block a user