formatting fixes

macos-click-through
Keith Simmons 3 years ago
parent f5b65a6770
commit 407a7e24a9

@ -94,7 +94,10 @@ impl Corner {
self.start_position = self.current_position;
self.previous_destination = destination;
self.length_multiplier = if settings.distance_length_adjust {
(destination - self.current_position).length().log10().max(0.0)
(destination - self.current_position)
.length()
.log10()
.max(0.0)
} else {
1.0
}
@ -109,7 +112,8 @@ impl Corner {
let relative_scaled_position: Point = (
self.relative_position.x * font_dimensions.x,
self.relative_position.y * font_dimensions.y,
).into();
)
.into();
let corner_destination = destination + relative_scaled_position;

@ -101,7 +101,8 @@ impl KeyboardManager {
pub fn handle_event(&mut self, event: &Event<()>) {
match event {
Event::WindowEvent {
event: WindowEvent::KeyboardInput {
event:
WindowEvent::KeyboardInput {
event: key_event, ..
},
..
@ -115,7 +116,7 @@ impl KeyboardManager {
.expect("Could not send keyboard ui command");
}
}
},
}
Event::WindowEvent {
event: WindowEvent::ModifiersChanged(modifiers),
..
@ -124,8 +125,8 @@ impl KeyboardManager {
self.ctrl = modifiers.control_key();
self.alt = modifiers.alt_key();
self.logo = modifiers.super_key();
},
_ => { }
}
_ => {}
}
}
}

@ -1,37 +1,44 @@
use glutin::{
self,
WindowedContext,
dpi::{
LogicalPosition,
PhysicalPosition,
},
event::{
ElementState,
Event,
MouseButton,
MouseScrollDelta,
WindowEvent,
},
PossiblyCurrent
dpi::{LogicalPosition, PhysicalPosition},
event::{ElementState, Event, MouseButton, MouseScrollDelta, WindowEvent},
PossiblyCurrent, WindowedContext,
};
use skia_safe::Rect;
use crate::channel_utils::LoggingTx;
use crate::bridge::UiCommand;
use crate::channel_utils::LoggingTx;
use crate::renderer::{Renderer, WindowDrawDetails};
use crate::settings::SETTINGS;
use crate::window::WindowSettings;
fn clamp_position(position: LogicalPosition<f32>, region: Rect, font_width: u64, font_height: u64) -> LogicalPosition<f32> {
fn clamp_position(
position: LogicalPosition<f32>,
region: Rect,
font_width: u64,
font_height: u64,
) -> LogicalPosition<f32> {
LogicalPosition::new(
position.x.min(region.right - font_width as f32).max(region.left),
position.y.min(region.bottom - font_height as f32).max(region.top))
position
.x
.min(region.right - font_width as f32)
.max(region.left),
position
.y
.min(region.bottom - font_height as f32)
.max(region.top),
)
}
fn to_grid_coords(position: LogicalPosition<f32>, font_width: u64, font_height: u64) -> LogicalPosition<u32> {
fn to_grid_coords(
position: LogicalPosition<f32>,
font_width: u64,
font_height: u64,
) -> LogicalPosition<u32> {
LogicalPosition::new(
(position.x as u64 / font_width) as u32,
(position.y as u64 / font_height) as u32)
(position.y as u64 / font_height) as u32,
)
}
pub struct MouseManager {
@ -59,7 +66,13 @@ impl MouseManager {
}
}
fn handle_pointer_motion(&mut self, x: i32, y: i32, renderer: &Renderer, windowed_context: &WindowedContext<PossiblyCurrent>) {
fn handle_pointer_motion(
&mut self,
x: i32,
y: i32,
renderer: &Renderer,
windowed_context: &WindowedContext<PossiblyCurrent>,
) {
let size = windowed_context.window().inner_size();
if x < 0 || x as u32 >= size.width || y < 0 || y as u32 >= size.height {
return;
@ -71,29 +84,48 @@ impl MouseManager {
// If dragging, the relevant window (the one which we send all commands to) is the one
// which the mouse drag started on. Otherwise its the top rendered window
let relevant_window_details = if self.dragging {
renderer.window_regions.iter()
.find(|details| details.id == self.window_details_under_mouse.as_ref().expect("If dragging, there should be a window details recorded").id)
renderer.window_regions.iter().find(|details| {
details.id
== self
.window_details_under_mouse
.as_ref()
.expect("If dragging, there should be a window details recorded")
.id
})
} else {
// the rendered window regions are sorted by draw order, so the earlier windows in the
// list are drawn under the later ones
renderer.window_regions.iter().filter(|details| {
logical_position.x >= details.region.left &&
logical_position.x < details.region.right &&
logical_position.y >= details.region.top &&
logical_position.y < details.region.bottom
}).last()
renderer
.window_regions
.iter()
.filter(|details| {
logical_position.x >= details.region.left
&& logical_position.x < details.region.right
&& logical_position.y >= details.region.top
&& logical_position.y < details.region.bottom
})
.last()
};
let global_bounds = relevant_window_details.map(|details| details.region).unwrap_or(Rect::from_wh(size.width as f32, size.height as f32));
let clamped_position = clamp_position(logical_position, global_bounds, renderer.font_width, renderer.font_height);
let global_bounds = relevant_window_details
.map(|details| details.region)
.unwrap_or(Rect::from_wh(size.width as f32, size.height as f32));
let clamped_position = clamp_position(
logical_position,
global_bounds,
renderer.font_width,
renderer.font_height,
);
self.position = to_grid_coords(clamped_position, renderer.font_width, renderer.font_height);
if let Some(relevant_window_details) = relevant_window_details {
let relative_position = LogicalPosition::new(
clamped_position.x - relevant_window_details.region.left,
clamped_position.y - relevant_window_details.region.top);
self.relative_position = to_grid_coords(relative_position, renderer.font_width, renderer.font_height);
clamped_position.y - relevant_window_details.region.top,
);
self.relative_position =
to_grid_coords(relative_position, renderer.font_width, renderer.font_height);
let previous_position = self.drag_position;
// Until https://github.com/neovim/neovim/pull/12667 is merged, we have to special
@ -178,7 +210,11 @@ impl MouseManager {
self.command_sender
.send(UiCommand::Scroll {
direction: input_type.to_string(),
grid_id: self.window_details_under_mouse.as_ref().map(|details| details.id).unwrap_or(0),
grid_id: self
.window_details_under_mouse
.as_ref()
.map(|details| details.id)
.unwrap_or(0),
position: self.drag_position.into(),
})
.ok();
@ -194,21 +230,33 @@ impl MouseManager {
self.command_sender
.send(UiCommand::Scroll {
direction: input_type.to_string(),
grid_id: self.window_details_under_mouse.as_ref().map(|details| details.id).unwrap_or(0),
grid_id: self
.window_details_under_mouse
.as_ref()
.map(|details| details.id)
.unwrap_or(0),
position: self.drag_position.into(),
})
.ok();
}
}
pub fn handle_event(&mut self, event: &Event<()>, renderer: &Renderer, windowed_context: &WindowedContext<PossiblyCurrent>) {
pub fn handle_event(
&mut self,
event: &Event<()>,
renderer: &Renderer,
windowed_context: &WindowedContext<PossiblyCurrent>,
) {
match event {
Event::WindowEvent {
event: WindowEvent::CursorMoved { position, .. },
..
} => self.handle_pointer_motion(
position.x as i32, position.y as i32,
renderer, windowed_context),
position.x as i32,
position.y as i32,
renderer,
windowed_context,
),
Event::WindowEvent {
event:
WindowEvent::MouseWheel {

Loading…
Cancel
Save