Add distance dependent animation length (#621)

* Add distance dependent animation length

* Fix for #117 cursor trails disabled when switching between modes an optionally when going to cmd line
macos-click-through
JeWe37 4 years ago committed by GitHub
parent ba42855f4c
commit 94bd58847e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

2
Cargo.lock generated

@ -1,7 +1,5 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "ab_glyph_rasterizer"
version = "0.1.4"

@ -114,7 +114,7 @@ pub enum WindowAnchor {
SouthEast,
}
#[derive(Debug)]
#[derive(Debug, Clone)]
pub enum EditorMode {
// The set of modes reported will change in new versions of Nvim, for
// instance more sub-modes and temporary states might be represented as

@ -25,7 +25,9 @@ const STANDARD_CORNERS: &[(f32, f32); 4] = &[(-0.5, -0.5), (0.5, -0.5), (0.5, 0.
pub struct CursorSettings {
antialiasing: bool,
animation_length: f32,
distance_length_adjust: bool,
animate_in_insert_mode: bool,
animate_command_line: bool,
trail_size: f32,
vfx_mode: cursor_vfx::VfxMode,
vfx_opacity: f32,
@ -42,7 +44,9 @@ impl Default for CursorSettings {
antialiasing: true,
animation_length: 0.13,
animate_in_insert_mode: true,
animate_command_line: true,
trail_size: 0.7,
distance_length_adjust: false,
vfx_mode: cursor_vfx::VfxMode::Disabled,
vfx_opacity: 200.0,
vfx_particle_lifetime: 1.2,
@ -60,6 +64,7 @@ pub struct Corner {
current_position: Point,
relative_position: Point,
previous_destination: Point,
length_multiplier: f32,
t: f32,
}
@ -70,6 +75,7 @@ impl Corner {
current_position: Point::new(0.0, 0.0),
relative_position: Point::new(0.0, 0.0),
previous_destination: Point::new(-1000.0, -1000.0),
length_multiplier: 1.0,
t: 0.0,
}
}
@ -86,6 +92,11 @@ impl Corner {
self.t = 0.0;
self.start_position = self.current_position;
self.previous_destination = destination;
self.length_multiplier = if settings.distance_length_adjust {
(destination - self.current_position).length().log10()
} else {
1.0
}
}
// Check first if animation's over
@ -135,7 +146,7 @@ impl Corner {
(1.0 - settings.trail_size).max(0.0).min(1.0),
-direction_alignment,
);
self.t = (self.t + corner_dt / settings.animation_length).min(1.0)
self.t = (self.t + corner_dt / (settings.animation_length * self.length_multiplier)).min(1.0)
}
self.current_position = ease_point(
@ -155,6 +166,7 @@ pub struct CursorRenderer {
destination: Point,
blink_status: BlinkStatus,
previous_cursor_shape: Option<CursorShape>,
previous_editor_mode: EditorMode,
cursor_vfx: Option<Box<dyn cursor_vfx::CursorVfx>>,
previous_vfx_mode: cursor_vfx::VfxMode,
}
@ -167,6 +179,7 @@ impl CursorRenderer {
destination: (0.0, 0.0).into(),
blink_status: BlinkStatus::new(),
previous_cursor_shape: None,
previous_editor_mode: EditorMode::Normal,
cursor_vfx: None,
previous_vfx_mode: cursor_vfx::VfxMode::Disabled,
};
@ -213,10 +226,12 @@ impl CursorRenderer {
font_width: f32,
font_height: f32,
windows: &HashMap<u64, RenderedWindow>,
current_mode: &EditorMode,
) {
let (cursor_grid_x, cursor_grid_y) = self.cursor.grid_position;
if let Some(window) = windows.get(&self.cursor.parent_window_id) {
if cursor_grid_y < window.grid_height-1 || matches!(current_mode, EditorMode::CmdLine) {
let grid_x = cursor_grid_x as f32 + window.grid_current_position.x;
let mut grid_y = cursor_grid_y as f32 + window.grid_current_position.y
- (window.current_scroll - window.current_surfaces.top_line);
@ -229,6 +244,7 @@ impl CursorRenderer {
.min(window.grid_current_position.y + window.grid_height as f32 - 1.0);
self.destination = (grid_x * font_width, grid_y * font_height).into();
}
} else {
self.destination = (
cursor_grid_x as f32 * font_width,
@ -269,6 +285,8 @@ impl CursorRenderer {
let font_dimensions: Point = (font_width, font_height).into();
let in_insert_mode = matches!(current_mode, EditorMode::Insert);
let changed_to_from_cmdline = !matches!(self.previous_editor_mode, EditorMode::CmdLine)
^ matches!(current_mode, EditorMode::CmdLine);
let center_destination = self.destination + font_dimensions * 0.5;
let new_cursor = Some(self.cursor.shape.clone());
@ -296,7 +314,8 @@ impl CursorRenderer {
font_dimensions,
center_destination,
dt,
!settings.animate_in_insert_mode && in_insert_mode,
!settings.animate_in_insert_mode && in_insert_mode
|| !settings.animate_command_line && !changed_to_from_cmdline,
);
animating |= corner_animating;
@ -313,6 +332,8 @@ impl CursorRenderer {
if animating {
REDRAW_SCHEDULER.queue_next_frame();
} else {
self.previous_editor_mode = current_mode.clone();
}
if self.cursor.enabled && render {

@ -342,7 +342,7 @@ impl Renderer {
let windows = &self.rendered_windows;
self.cursor_renderer
.update_cursor_destination(font_width, font_height, windows);
.update_cursor_destination(font_width, font_height, windows, &self.current_mode);
self.cursor_renderer.draw(
&self.default_style.colors,

Loading…
Cancel
Save