Skip to content

Commit

Permalink
Switch to glamour instead of euclid
Browse files Browse the repository at this point in the history
  • Loading branch information
fredizzimo committed Jul 13, 2024
1 parent 818ff73 commit 72cd7d9
Show file tree
Hide file tree
Showing 11 changed files with 411 additions and 349 deletions.
518 changes: 271 additions & 247 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ copypasta = "0.10.1"
csscolorparser = "0.6.2"
derive-new = "0.6.0"
dirs = "5.0.0"
euclid = { version = "0.22.9", features = ["serde"] }
glamour = { version = "0.11.1", features = ["serde"] }
flexi_logger = { version = "0.28.0", default-features = false }
futures = "0.3.21"
gl = "0.14.0"
Expand Down
12 changes: 6 additions & 6 deletions src/renderer/animation_utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::units::PixelPos;
use glamour::{Point2, Unit};

#[allow(dead_code)]
pub fn ease_linear(t: f32) -> f32 {
Expand Down Expand Up @@ -73,13 +73,13 @@ pub fn ease(ease_func: fn(f32) -> f32, start: f32, end: f32, t: f32) -> f32 {
lerp(start, end, ease_func(t))
}

pub fn ease_point(
pub fn ease_point<T: Unit<Scalar = f32>>(
ease_func: fn(f32) -> f32,
start: PixelPos<f32>,
end: PixelPos<f32>,
start: Point2<T>,
end: Point2<T>,
t: f32,
) -> PixelPos<f32> {
PixelPos::new(
) -> Point2<T> {
Point2::new(
ease(ease_func, start.x, end.x, t),
ease(ease_func, start.y, end.y, t),
)
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/cursor_renderer/cursor_vfx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
renderer::cursor_renderer::CursorSettings,
renderer::{animation_utils::*, grid_renderer::GridRenderer},
settings::*,
units::{PixelPos, PixelSize, PixelVec},
units::{GridSize, PixelPos, PixelSize, PixelVec},
};

pub trait CursorVfx {
Expand Down Expand Up @@ -149,7 +149,7 @@ impl CursorVfx for PointHighlight {

paint.set_color(color);

let cursor_height = grid_renderer.grid_scale.0.height;
let cursor_height = grid_renderer.grid_scale.height();
let size = 3.0 * cursor_height;
let radius = self.t * size;
let hr = radius * 0.5;
Expand Down Expand Up @@ -335,7 +335,7 @@ impl CursorVfx for ParticleTrail {
cursor: &Cursor,
) {
let mut paint = Paint::new(skia_safe::colors::WHITE, None);
let font_dimensions = grid_renderer.grid_scale.0;
let font_dimensions = GridSize::new(1.0, 1.0) * grid_renderer.grid_scale;
match self.trail_mode {
TrailMode::Torpedo | TrailMode::Railgun => {
paint.set_style(Style::Stroke);
Expand Down
16 changes: 8 additions & 8 deletions src/renderer/cursor_renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ pub struct Corner {
impl Corner {
pub fn new() -> Corner {
Corner {
start_position: PixelPos::origin(),
current_position: PixelPos::origin(),
relative_position: GridPos::<f32>::origin(),
start_position: PixelPos::default(),
current_position: PixelPos::default(),
relative_position: GridPos::<f32>::default(),
previous_destination: PixelPos::new(-1000.0, -1000.0),
length_multiplier: 1.0,
t: 0.0,
Expand Down Expand Up @@ -134,7 +134,7 @@ impl Corner {
d.normalize()
};

let corner_direction = self.relative_position.to_vector().normalize().cast_unit();
let corner_direction = self.relative_position.as_vector().normalize().cast();

let direction_alignment = travel_direction.dot(corner_direction);

Expand Down Expand Up @@ -352,12 +352,12 @@ impl CursorRenderer {
self.previous_vfx_mode = settings.vfx_mode.clone();
}

let mut cursor_width = grid_renderer.grid_scale.0.width;
let mut cursor_width = grid_renderer.grid_scale.width();
if self.cursor.double_width && self.cursor.shape == CursorShape::Block {
cursor_width *= 2.0;
}

let cursor_dimensions = PixelSize::new(cursor_width, grid_renderer.grid_scale.0.height);
let cursor_dimensions = PixelSize::new(cursor_width, grid_renderer.grid_scale.height());

let in_insert_mode = matches!(current_mode, EditorMode::Insert);

Expand All @@ -382,13 +382,13 @@ impl CursorRenderer {

let mut animating = false;

if center_destination != PixelPos::origin() {
if center_destination != PixelPos::ZERO {
let immediate_movement = !settings.animate_in_insert_mode && in_insert_mode
|| !settings.animate_command_line && !changed_to_from_cmdline;
for corner in self.corners.iter_mut() {
let corner_animating = corner.update(
&settings,
GridScale(cursor_dimensions),
GridScale::new(cursor_dimensions),
center_destination,
dt,
immediate_movement,
Expand Down
20 changes: 10 additions & 10 deletions src/renderer/grid_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl GridRenderer {
shaper,
default_style,
em_size,
grid_scale: GridScale(font_dimensions),
grid_scale: GridScale::new(font_dimensions),
is_ready: false,
}
}
Expand Down Expand Up @@ -77,14 +77,14 @@ impl GridRenderer {

fn update_font_dimensions(&mut self) {
self.em_size = self.shaper.current_size();
self.grid_scale = GridScale(self.shaper.font_base_dimensions());
self.grid_scale = GridScale::new(self.shaper.font_base_dimensions());
self.is_ready = true;
trace!("Updated font dimensions: {:?}", self.grid_scale.0);
trace!("Updated font dimensions: {:?}", self.grid_scale);
}

fn compute_text_region(&self, grid_position: GridPos<i32>, cell_width: i32) -> PixelRect<f32> {
let pos = grid_position.cast() * self.grid_scale;
let size = GridSize::new(cell_width, 1).cast() * self.grid_scale;
let pos = grid_position * self.grid_scale;
let size = GridSize::new(cell_width, 1) * self.grid_scale;
PixelRect::from_origin_and_size(pos, size)
}

Expand Down Expand Up @@ -151,8 +151,8 @@ impl GridRenderer {
style: &Option<Arc<Style>>,
) -> bool {
tracy_zone!("draw_foreground");
let pos = grid_position.cast() * self.grid_scale;
let size = GridSize::new(cell_width, 0).cast() * self.grid_scale;
let pos = grid_position * self.grid_scale;
let size = GridSize::new(cell_width, 0) * self.grid_scale;
let width = size.width;

let style = style.as_ref().unwrap_or(&self.default_style);
Expand All @@ -164,7 +164,7 @@ impl GridRenderer {
let region = self.compute_text_region(clip_position, cell_width + 2);

if let Some(underline_style) = style.underline {
let line_position = self.grid_scale.0.height - self.shaper.underline_position();
let line_position = self.grid_scale.height() - self.shaper.underline_position();
let p1 = pos + PixelVec::new(0.0, line_position);
let p2 = pos + PixelVec::new(width, line_position);

Expand Down Expand Up @@ -195,7 +195,7 @@ impl GridRenderer {
let leading_spaces = text[..leading_space_bytes].chars().count();
let trimmed = trimmed.trim_end();
let adjustment = PixelVec::new(
leading_spaces as f32 * self.grid_scale.0.width,
leading_spaces as f32 * self.grid_scale.width(),
self.shaper.y_adjustment(),
);

Expand Down Expand Up @@ -272,7 +272,7 @@ impl GridRenderer {
path.move_to(p1);
let mut i = p1.0;
let mut sin = -2. * stroke_width;
let increment = self.grid_scale.0.width / 2.;
let increment = self.grid_scale.width() / 2.;
while i < p2.0 {
sin *= -1.;
i += increment;
Expand Down
27 changes: 14 additions & 13 deletions src/renderer/rendered_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ impl RenderedWindow {
scroll_delta: 0,
viewport_margins: ViewportMargins { top: 0, bottom: 0 },

grid_start_position: grid_position.cast(),
grid_current_position: grid_position.cast(),
grid_destination: grid_position.cast(),
grid_start_position: grid_position.try_cast().unwrap(),
grid_current_position: grid_position.try_cast().unwrap(),
grid_destination: grid_position.try_cast().unwrap(),
position_t: 2.0, // 2.0 is out of the 0.0 to 1.0 range and stops animation.

scroll_animation: CriticallyDampedSpringAnimation::new(),
Expand All @@ -153,8 +153,10 @@ impl RenderedWindow {
}

pub fn pixel_region(&self, grid_scale: GridScale) -> PixelRect<f32> {
GridRect::<f32>::from_origin_and_size(self.grid_current_position, self.grid_size.cast())
* grid_scale
GridRect::<f32>::from_origin_and_size(
self.grid_current_position,
self.grid_size.try_cast().unwrap(),
) * grid_scale
}

pub fn update_blend(&self, blend: u8) {
Expand All @@ -171,7 +173,7 @@ impl RenderedWindow {
return destination;
}

let mut grid_size: GridSize<f32> = self.grid_size.cast();
let mut grid_size: GridSize<f32> = self.grid_size.try_cast().unwrap();

if matches!(self.window_type, WindowType::Message { .. }) {
// The message grid size is always the full window size, so use the relative position to
Expand Down Expand Up @@ -214,11 +216,10 @@ impl RenderedWindow {
let prev_position = self.grid_current_position;
self.grid_current_position = ease_point(
ease_out_expo,
self.grid_start_position.cast_unit(),
self.get_target_position(grid_rect).cast_unit(),
self.grid_start_position,
self.get_target_position(grid_rect),
self.position_t,
)
.cast_unit();
);
animating |= self.grid_current_position != prev_position;

let scrolling = self
Expand Down Expand Up @@ -607,15 +608,15 @@ impl RenderedWindow {
) -> impl Iterator<Item = (Matrix, &Rc<RefCell<Line>>)> {
let scroll_offset_lines = self.scroll_animation.position.floor();
let scroll_offset = scroll_offset_lines - self.scroll_animation.position;
let scroll_offset_pixels = (scroll_offset * grid_scale.0.height).round();
let scroll_offset_pixels = (scroll_offset * grid_scale.height()).round();

self.iter_scrollable_lines().map(move |(i, line)| {
let mut matrix = Matrix::new_identity();
matrix.set_translate((
pixel_region.min.x,
pixel_region.min.y
+ (scroll_offset_pixels
+ ((i + self.viewport_margins.top as isize) as f32 * grid_scale.0.height)),
+ ((i + self.viewport_margins.top as isize) as f32 * grid_scale.height())),
));
(matrix, line)
})
Expand Down Expand Up @@ -687,7 +688,7 @@ impl RenderedWindow {

let mut recorder = PictureRecorder::new();

let line_size = GridSize::new(self.grid_size.width, 1).cast() * grid_scale;
let line_size = GridSize::new(self.grid_size.width, 1) * grid_scale;
let grid_rect = Rect::from_wh(line_size.width, line_size.height);
let canvas = recorder.begin_recording(grid_rect, None);

Expand Down
15 changes: 12 additions & 3 deletions src/settings/window_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,18 @@ use crate::{

const SETTINGS_FILE: &str = "neovide-settings.json";

pub const DEFAULT_GRID_SIZE: GridSize<u32> = GridSize::new(100, 50);
pub const MIN_GRID_SIZE: GridSize<u32> = GridSize::new(20, 6);
pub const MAX_GRID_SIZE: GridSize<u32> = GridSize::new(10000, 1000);
pub const DEFAULT_GRID_SIZE: GridSize<u32> = GridSize {
width: 100,
height: 50,
};
pub const MIN_GRID_SIZE: GridSize<u32> = GridSize {
width: 20,
height: 6,
};
pub const MAX_GRID_SIZE: GridSize<u32> = GridSize {
width: 10000,
height: 1000,
};

#[derive(Serialize, Deserialize, Debug)]
pub enum PersistentWindowSettings {
Expand Down
Loading

0 comments on commit 72cd7d9

Please sign in to comment.