mirror of
https://github.com/emilk/egui.git
synced 2026-06-27 15:13:12 -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.input.get(&viewport_id).unwrap_or(&Default::default()),
|
||||
&new_raw_input,
|
||||
viewport_id,
|
||||
);
|
||||
|
||||
let input = self
|
||||
@@ -1299,6 +1300,14 @@ impl Context {
|
||||
/// Call at the end of each frame.
|
||||
#[must_use]
|
||||
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()) {
|
||||
self.request_repaint();
|
||||
}
|
||||
@@ -1306,6 +1315,7 @@ impl Context {
|
||||
let textures_delta = self.write(|ctx| {
|
||||
ctx.memory.end_frame(
|
||||
ctx.input.get(&ctx.current_rendering_viewport).unwrap(),
|
||||
&viewports,
|
||||
&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)));
|
||||
|
||||
let repaint_after = self.write(|ctx| {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use ahash::HashMap;
|
||||
|
||||
use crate::{area, window, Id, IdMap, InputState, LayerId, Pos2, Rect, Style};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -69,9 +71,16 @@ pub struct Memory {
|
||||
#[cfg_attr(feature = "persistence", serde(skip))]
|
||||
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))]
|
||||
pub(crate) interaction: Interaction,
|
||||
|
||||
// Current viewport
|
||||
#[cfg_attr(feature = "persistence", serde(skip))]
|
||||
pub(crate) viewport_id: u64,
|
||||
|
||||
#[cfg_attr(feature = "persistence", serde(skip))]
|
||||
pub(crate) window_interaction: Option<window::WindowInteraction>,
|
||||
|
||||
@@ -354,19 +363,33 @@ impl Memory {
|
||||
&mut self,
|
||||
prev_input: &crate::input_state::InputState,
|
||||
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() {
|
||||
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.areas.end_frame();
|
||||
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.interactions.retain(|id, _| viewports.contains(id))
|
||||
}
|
||||
|
||||
/// Top-most layer at the given position.
|
||||
|
||||
Reference in New Issue
Block a user