[window] Remove ability to throw windows
This commit is contained in:
parent
fa831a2b55
commit
211d70b4f3
5 changed files with 5 additions and 42 deletions
|
@ -9,6 +9,7 @@
|
||||||
* Windows are now constrained to the screen
|
* Windows are now constrained to the screen
|
||||||
* Panels: you can now create panels using `SidePanel` and `TopPanel`.
|
* 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`).
|
* 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
|
## 0.2.0 - 2020-10-10
|
||||||
|
|
||||||
|
|
|
@ -19,11 +19,6 @@ pub(crate) struct State {
|
||||||
/// If false, clicks goes straight through to what is behind us.
|
/// If false, clicks goes straight through to what is behind us.
|
||||||
/// Good for tooltips etc.
|
/// Good for tooltips etc.
|
||||||
pub interactable: bool,
|
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 {
|
impl State {
|
||||||
|
@ -128,7 +123,6 @@ impl Area {
|
||||||
pos: default_pos.unwrap_or_else(|| automatic_area_position(ctx)),
|
pos: default_pos.unwrap_or_else(|| automatic_area_position(ctx)),
|
||||||
size: Vec2::zero(),
|
size: Vec2::zero(),
|
||||||
interactable,
|
interactable,
|
||||||
vel: Vec2::zero(),
|
|
||||||
});
|
});
|
||||||
state.pos = fixed_pos.unwrap_or(state.pos);
|
state.pos = fixed_pos.unwrap_or(state.pos);
|
||||||
state.pos = ctx.round_pos_to_pixels(state.pos);
|
state.pos = ctx.round_pos_to_pixels(state.pos);
|
||||||
|
@ -183,6 +177,7 @@ impl Prepared {
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
let move_response = ctx.interact(
|
let move_response = ctx.interact(
|
||||||
layer_id,
|
layer_id,
|
||||||
Rect::everything(),
|
Rect::everything(),
|
||||||
|
@ -191,23 +186,8 @@ impl Prepared {
|
||||||
Sense::click_and_drag(),
|
Sense::click_and_drag(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let input = ctx.input();
|
|
||||||
if move_response.active {
|
if move_response.active {
|
||||||
state.pos += input.mouse.delta;
|
state.pos += ctx.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.constrain_window_rect(state.rect()).min;
|
state.pos = ctx.constrain_window_rect(state.rect()).min;
|
||||||
|
|
|
@ -370,10 +370,6 @@ impl WindowInteraction {
|
||||||
pub fn is_resize(&self) -> bool {
|
pub fn is_resize(&self) -> bool {
|
||||||
self.left || self.right || self.top || self.bottom
|
self.left || self.right || self.top || self.bottom
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_pure_move(&self) -> bool {
|
|
||||||
!self.is_resize()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn interact(
|
fn interact(
|
||||||
|
|
|
@ -277,7 +277,6 @@ impl Context {
|
||||||
pos: rect.min,
|
pos: rect.min,
|
||||||
size: rect.size(),
|
size: rect.size(),
|
||||||
interactable: true,
|
interactable: true,
|
||||||
vel: Default::default(),
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
Ui::new(self.clone(), layer_id, layer_id.id, rect, rect)
|
Ui::new(self.clone(), layer_id, layer_id.id, rect, rect)
|
||||||
|
|
|
@ -135,21 +135,8 @@ impl Memory {
|
||||||
pub(crate) fn begin_frame(&mut self, prev_input: &crate::input::InputState) {
|
pub(crate) fn begin_frame(&mut self, prev_input: &crate::input::InputState) {
|
||||||
self.interaction.begin_frame(prev_input);
|
self.interaction.begin_frame(prev_input);
|
||||||
|
|
||||||
if !prev_input.mouse.down || prev_input.mouse.pos.is_none() {
|
if !prev_input.mouse.down {
|
||||||
// mouse was not down last frame
|
self.window_interaction = None;
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue