From 211d70b4f3d12fb82ad9fc1789f949c0e29bf5c7 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Fri, 23 Oct 2020 15:16:04 +0200 Subject: [PATCH] [window] Remove ability to throw windows --- CHANGELOG.md | 1 + egui/src/containers/area.rs | 24 ++---------------------- egui/src/containers/window.rs | 4 ---- egui/src/context.rs | 1 - egui/src/memory.rs | 17 ++--------------- 5 files changed, 5 insertions(+), 42 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc0b7595..2286d854 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ * Windows are now constrained to the screen * Panels: you can now create panels using `SidePanel` and `TopPanel`. * Fix a bug where some regions would slowly grow for non-integral scales (`pixels_per_point`). +* You can no longer throw windows ## 0.2.0 - 2020-10-10 diff --git a/egui/src/containers/area.rs b/egui/src/containers/area.rs index d1b4fe78..94ec9dcd 100644 --- a/egui/src/containers/area.rs +++ b/egui/src/containers/area.rs @@ -19,11 +19,6 @@ pub(crate) struct State { /// If false, clicks goes straight through to what is behind us. /// Good for tooltips etc. pub interactable: bool, - - /// You can throw a moveable Area. It's fun. - /// TODO: separate out moveable to container? - #[cfg_attr(feature = "serde", serde(skip))] - pub vel: Vec2, } impl State { @@ -128,7 +123,6 @@ impl Area { pos: default_pos.unwrap_or_else(|| automatic_area_position(ctx)), size: Vec2::zero(), interactable, - vel: Vec2::zero(), }); state.pos = fixed_pos.unwrap_or(state.pos); state.pos = ctx.round_pos_to_pixels(state.pos); @@ -183,6 +177,7 @@ impl Prepared { } else { None }; + let move_response = ctx.interact( layer_id, Rect::everything(), @@ -191,23 +186,8 @@ impl Prepared { Sense::click_and_drag(), ); - let input = ctx.input(); if move_response.active { - state.pos += input.mouse.delta; - state.vel = input.mouse.velocity; - } else { - let stop_speed = 20.0; // Pixels per second. - let friction_coeff = 1000.0; // Pixels per second squared. - let dt = input.unstable_dt; - - let friction = friction_coeff * dt; - if friction > state.vel.length() || state.vel.length() < stop_speed { - state.vel = Vec2::zero(); - } else { - state.vel -= friction * state.vel.normalized(); - state.pos += state.vel * dt; - ctx.request_repaint(); - } + state.pos += ctx.input().mouse.delta; } state.pos = ctx.constrain_window_rect(state.rect()).min; diff --git a/egui/src/containers/window.rs b/egui/src/containers/window.rs index ecb90448..67876709 100644 --- a/egui/src/containers/window.rs +++ b/egui/src/containers/window.rs @@ -370,10 +370,6 @@ impl WindowInteraction { pub fn is_resize(&self) -> bool { self.left || self.right || self.top || self.bottom } - - pub fn is_pure_move(&self) -> bool { - !self.is_resize() - } } fn interact( diff --git a/egui/src/context.rs b/egui/src/context.rs index 51fd12f9..edd676bd 100644 --- a/egui/src/context.rs +++ b/egui/src/context.rs @@ -277,7 +277,6 @@ impl Context { pos: rect.min, size: rect.size(), interactable: true, - vel: Default::default(), }, ); Ui::new(self.clone(), layer_id, layer_id.id, rect, rect) diff --git a/egui/src/memory.rs b/egui/src/memory.rs index 692bdb63..c952e7d5 100644 --- a/egui/src/memory.rs +++ b/egui/src/memory.rs @@ -135,21 +135,8 @@ impl Memory { pub(crate) fn begin_frame(&mut self, prev_input: &crate::input::InputState) { self.interaction.begin_frame(prev_input); - if !prev_input.mouse.down || prev_input.mouse.pos.is_none() { - // mouse was not down last frame - - let window_interaction = self.window_interaction.take(); - if let Some(window_interaction) = window_interaction { - if window_interaction.is_pure_move() { - // Throw windows because it is fun: - let area_layer_id = window_interaction.area_layer_id; - let area_state = self.areas.get(area_layer_id.id).cloned(); - if let Some(mut area_state) = area_state { - area_state.vel = prev_input.mouse.velocity; - self.areas.set_state(area_layer_id, area_state); - } - } - } + if !prev_input.mouse.down { + self.window_interaction = None; } }