[window] Remove ability to throw windows

This commit is contained in:
Emil Ernerfeldt 2020-10-23 15:16:04 +02:00
parent fa831a2b55
commit 211d70b4f3
5 changed files with 5 additions and 42 deletions

View file

@ -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

View file

@ -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;

View file

@ -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(

View file

@ -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)

View file

@ -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;
}
}