diff --git a/Cargo.lock b/Cargo.lock index 8cec147f0..b7832e5bb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -364,7 +364,7 @@ checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -512,7 +512,7 @@ checksum = "1ee891b04274a59bd38b412188e24b849617b2e45a0fd8d057deb63e7403761b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -533,9 +533,9 @@ dependencies = [ [[package]] name = "bytes" -version = "1.6.0" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" +checksum = "a12916984aab3fa6e39d655a33e09c0071eb36d6ab3aea5c2d78551f1df6d952" [[package]] name = "calloop" @@ -565,9 +565,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.1.1" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907d8581360765417f8f2e0e7d602733bbed60156b4465b7617243689ef9b83d" +checksum = "47de7e88bbbd467951ae7f5a6f34f70d1b4d9cfce53d5fd70f74ebe118b3db56" dependencies = [ "jobserver", "libc", @@ -644,7 +644,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -716,7 +716,7 @@ version = "4.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba5a308b75df32fe02788e748662718f03fde005016435c444eea572398219fd" dependencies = [ - "bytes 1.6.0", + "bytes 1.6.1", "memchr", ] @@ -928,7 +928,7 @@ checksum = "d150dea618e920167e5973d70ae6ece4385b7164e0d799fe7c122dd0a5d912ad" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -997,7 +997,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -1011,9 +1011,9 @@ dependencies = [ [[package]] name = "document-features" -version = "0.2.8" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef5282ad69563b5fc40319526ba27e0e7363d552a896f0297d54f767717f9b95" +checksum = "cb6969eaabd2421f8a2775cfd2471a2b634372b4a25d41e3bd647b79912850a0" dependencies = [ "litrs", ] @@ -1076,7 +1076,6 @@ version = "0.22.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e0f0eb73b934648cd7a4a61f1b15391cd95dab0b4da6e2e66c2a072c144b4a20" dependencies = [ - "mint", "num-traits", "serde", ] @@ -1297,7 +1296,7 @@ checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -1443,7 +1442,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -1551,15 +1550,6 @@ dependencies = [ "xml-rs", ] -[[package]] -name = "glam" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12f597d56c1bd55a811a1be189459e8fad2bbc272616375602443bdfb37fa774" -dependencies = [ - "mint", -] - [[package]] name = "glam" version = "0.27.0" @@ -1579,7 +1569,7 @@ checksum = "0ce0d37a206e319849899049d6fe5d386a2cdcbf2efc9b0b1adeb3fabed26152" dependencies = [ "approx", "bytemuck", - "glam 0.27.0", + "glam", "num-traits", "serde", ] @@ -2334,10 +2324,9 @@ dependencies = [ "csscolorparser", "derive-new", "dirs", - "euclid", "flexi_logger", "futures 0.3.30", - "glam 0.22.0", + "glamour", "glutin", "glutin-winit", "icrate", @@ -2544,7 +2533,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -2719,7 +2708,7 @@ dependencies = [ "by_address", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -2847,7 +2836,7 @@ dependencies = [ "phf_shared", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -2994,7 +2983,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8021cf59c8ec9c432cfc2526ac6b8aa508ecaf29cd415f271b8406c1b851c3fd" dependencies = [ "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -3249,7 +3238,7 @@ dependencies = [ "proc-macro2", "quote", "rust-embed-utils", - "syn 2.0.70", + "syn 2.0.71", "walkdir", ] @@ -3401,7 +3390,7 @@ checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -3446,7 +3435,7 @@ checksum = "82fe9db325bcef1fbcde82e078a5cc4efdf787e96b3b9cf45b50b529f2083d67" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -3667,7 +3656,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -3700,9 +3689,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.70" +version = "2.0.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f0209b68b3613b093e0ec905354eccaedcfe83b8cb37cbdeae64026c3064c16" +checksum = "b146dcf730474b4bcd16c311627b31ede9ab149045db4d6088b3becaea046462" dependencies = [ "proc-macro2", "quote", @@ -3735,7 +3724,7 @@ checksum = "d20468752b09f49e909e55a5d338caa8bedf615594e9d80bc4c565d30faf798c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -3820,7 +3809,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" dependencies = [ "backtrace", - "bytes 1.6.0", + "bytes 1.6.1", "libc", "mio", "num_cpus", @@ -3851,7 +3840,7 @@ checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -3860,7 +3849,7 @@ version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" dependencies = [ - "bytes 1.6.0", + "bytes 1.6.1", "futures-core", "futures-io", "futures-sink", @@ -4062,7 +4051,7 @@ dependencies = [ "font-kit", "futures 0.3.30", "futures-intrusive", - "glam 0.27.0", + "glam", "glamour", "image", "lazy_static", @@ -4136,7 +4125,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", "wasm-bindgen-shared", ] @@ -4170,7 +4159,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -4548,7 +4537,7 @@ checksum = "f6fc35f58ecd95a9b71c4f2329b911016e6bec66b3f2e6a4aad86bd2e99e2f9b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -4559,7 +4548,7 @@ checksum = "08990546bf4edef8f431fa6326e032865f27138718c587dc21bc0265bbcb57cc" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -5013,7 +5002,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index baae04353..506c44245 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,10 +36,9 @@ copypasta = "0.10.1" csscolorparser = "0.6.2" derive-new = "0.6.0" dirs = "5.0.0" -euclid = { version = "0.22.9", features = ["serde", "mint"] } +glamour = { version = "0.11.1", features = ["serde"] } flexi_logger = { version = "0.28.0", default-features = false } futures = "0.3.21" -glam = { version = "0.22.0", features = ["mint"] } glutin = "0.31.1" glutin-winit = "0.4.2" image = { version = "0.25.0", default-features = false, features = ["ico"] } diff --git a/src/renderer/animation_utils.rs b/src/renderer/animation_utils.rs index 8f1edfcf7..7d658c99e 100644 --- a/src/renderer/animation_utils.rs +++ b/src/renderer/animation_utils.rs @@ -1,4 +1,4 @@ -use crate::units::PixelPos; +use glamour::{Point2, Unit}; #[allow(dead_code)] pub fn ease_linear(t: f32) -> f32 { @@ -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>( ease_func: fn(f32) -> f32, - start: PixelPos, - end: PixelPos, + start: Point2, + end: Point2, t: f32, -) -> PixelPos { - PixelPos::new( +) -> Point2 { + Point2::new( ease(ease_func, start.x, end.x, t), ease(ease_func, start.y, end.y, t), ) diff --git a/src/renderer/cursor_renderer/cursor_vfx.rs b/src/renderer/cursor_renderer/cursor_vfx.rs index 20869e843..296f22aed 100644 --- a/src/renderer/cursor_renderer/cursor_vfx.rs +++ b/src/renderer/cursor_renderer/cursor_vfx.rs @@ -6,7 +6,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 { @@ -136,7 +136,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; @@ -161,7 +161,6 @@ impl CursorVfx for PointHighlight { // paint.set_stroke_width(cursor_height * 0.2); // canvas.draw_rect(rect, &paint); // } - // } } } @@ -316,7 +315,7 @@ impl CursorVfx for ParticleTrail { fn render(&self, settings: &CursorSettings, grid_renderer: &mut GridRenderer, 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); diff --git a/src/renderer/cursor_renderer/mod.rs b/src/renderer/cursor_renderer/mod.rs index 4f5e24513..dc42b8c52 100644 --- a/src/renderer/cursor_renderer/mod.rs +++ b/src/renderer/cursor_renderer/mod.rs @@ -78,9 +78,9 @@ pub struct Corner { impl Corner { pub fn new() -> Corner { Corner { - start_position: PixelPos::origin(), - current_position: PixelPos::origin(), - relative_position: GridPos::::origin(), + start_position: PixelPos::default(), + current_position: PixelPos::default(), + relative_position: GridPos::::default(), previous_destination: PixelPos::new(-1000.0, -1000.0), length_multiplier: 1.0, t: 0.0, @@ -133,7 +133,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); @@ -351,12 +351,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); @@ -381,13 +381,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, diff --git a/src/renderer/grid_renderer.rs b/src/renderer/grid_renderer.rs index 5129a96f1..e3742b3b6 100644 --- a/src/renderer/grid_renderer.rs +++ b/src/renderer/grid_renderer.rs @@ -2,7 +2,6 @@ use std::sync::Arc; use log::trace; -use glam::Vec4; use palette::{named, Hsv, IntoColor, LinSrgba, Srgba, WithAlpha}; use vide::{Layer, Quad, Text}; @@ -49,7 +48,7 @@ impl GridRenderer { //shaper, default_style, em_size, - grid_scale: GridScale(font_dimensions), + grid_scale: GridScale::new(font_dimensions), is_ready: false, } } @@ -81,16 +80,16 @@ impl GridRenderer { fn update_font_dimensions(&mut self) { // TODO - //self.em_size = self.shaper.current_size(); - //self.grid_scale = GridScale(self.shaper.font_base_dimensions()); - //self.grid_scale = GridScale((10.0, 10.0).into()); + // self.em_size = self.shaper.current_size(); + // self.grid_scale = GridScale::new(self.shaper.font_base_dimensions()); + self.grid_scale = GridScale::new((10.0, 10.0).into()); 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, cell_width: i32) -> PixelRect { - 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) } @@ -134,14 +133,7 @@ impl GridRenderer { let custom_color = color != self.default_style.colors.background.unwrap(); if custom_color { - let top_left: mint::Vector2<_> = region.min.to_vector().into(); - let bottom_right: mint::Vector2<_> = region.max.to_vector().into(); - let color: LinSrgba = color.into_color(); - let quad = Quad::new( - top_left.into(), - bottom_right.into(), - Vec4::from_array(color.into()), - ); + let quad = Quad::new(*region.min.as_untyped(), *region.size().as_untyped(), color); layer.add_quad(quad); } @@ -163,8 +155,8 @@ impl GridRenderer { layer: &mut Layer, ) -> bool { tracy_zone!("draw_foreground"); - let pos = grid_position.cast() * self.grid_scale + transform; - let size = GridSize::new(cell_width, 0).cast() * self.grid_scale; + let pos = grid_position * self.grid_scale + transform; + let size = GridSize::new(cell_width, 0) * self.grid_scale; let width = size.width; let style = style.as_ref().unwrap_or(&self.default_style); @@ -177,7 +169,7 @@ impl GridRenderer { // TODO: Draw underline // 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); // @@ -204,21 +196,16 @@ impl GridRenderer { // let y_adjustment = self.shaper.y_adjustment; let y_adjustment = self.em_size; let adjustment = PixelVec::new( - leading_spaces as f32 * self.grid_scale.0.width, + leading_spaces as f32 * self.grid_scale.width(), y_adjustment, ); if !trimmed.is_empty() { tracy_zone!("draw_text_blob"); - let pos: mint::Vector2<_> = (pos + adjustment).to_vector().into(); + let pos = pos + adjustment; // TODO: The text is not in linear srgba for some reason //let color: LinSrgba = color.into_color(); - let text = Text::new( - trimmed.to_string(), - pos.into(), - self.em_size, - Vec4::from_array(color.into()), - ); + let text = Text::new(trimmed.to_string(), pos, self.em_size, color); layer.add_text(text); //canvas.draw_text_blob(blob, to_skia_point(pos + adjustment), &paint); drawn = true; @@ -283,7 +270,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; diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index 4c76da990..307f14af3 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -15,7 +15,6 @@ use std::{ use futures::executor::block_on; -use glam::Vec4; use itertools::Itertools; use log::{error, warn}; use mint::Vector2; diff --git a/src/renderer/rendered_layer.rs b/src/renderer/rendered_layer.rs index a4231cc31..f08b3f930 100644 --- a/src/renderer/rendered_layer.rs +++ b/src/renderer/rendered_layer.rs @@ -1,5 +1,6 @@ use itertools::Itertools; +use glamour::Intersection; use palette::LinSrgba; use vide::{Layer, Scene}; diff --git a/src/renderer/rendered_window.rs b/src/renderer/rendered_window.rs index d9489dd60..12f58ac91 100644 --- a/src/renderer/rendered_window.rs +++ b/src/renderer/rendered_window.rs @@ -1,7 +1,6 @@ use std::{cell::RefCell, rc::Rc, sync::Arc}; -use glam::Vec4; -use palette::{LinSrgba, Srgba, WithAlpha}; +use palette::{named, LinSrgba, Srgba, WithAlpha}; use vide::{Layer, Scene}; use crate::{ @@ -139,9 +138,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(), @@ -151,8 +150,10 @@ impl RenderedWindow { } pub fn pixel_region(&self, grid_scale: GridScale) -> PixelRect { - GridRect::::from_origin_and_size(self.grid_current_position, self.grid_size.cast()) - * grid_scale + GridRect::::from_origin_and_size( + self.grid_current_position, + self.grid_size.try_cast().unwrap(), + ) * grid_scale } pub fn update_blend(&self, blend: u8) { @@ -169,7 +170,7 @@ impl RenderedWindow { return destination; } - let mut grid_size: GridSize = self.grid_size.cast(); + let mut grid_size: GridSize = 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 @@ -212,11 +213,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 @@ -274,28 +274,16 @@ impl RenderedWindow { // // canvas.save(); // canvas.clip_rect(to_skia_rect(&pixel_region), None, false); - let clip = Vec4::new( - pixel_region.min.x, - pixel_region.min.y, - pixel_region.width(), - pixel_region.height(), - ); let mut layer = Layer::new() - .with_background(Vec4::from_array(default_color.into())) - .with_clip(clip); + .with_background(default_color.into()) + .with_clip(pixel_region.to_rect().as_untyped().try_cast().unwrap()); self.iter_border_lines_with_transform(pixel_region, grid_scale) .for_each(|(transform, line)| draw_line(transform, line, &mut layer)); scene.add_layer(layer); - let clip = Vec4::new( - inner_region.min.x, - inner_region.min.y, - inner_region.width(), - inner_region.height(), - ); let mut layer = Layer::new() - .with_background(Vec4::from_array(default_color.into())) - .with_clip(clip); + .with_background(default_color.into()) + .with_clip(inner_region.to_rect().as_untyped().try_cast().unwrap()); self.iter_scrollable_lines_with_transform(pixel_region, grid_scale) .for_each(|(transform, line)| draw_line(transform, line, &mut layer)); scene.add_layer(layer); @@ -343,30 +331,18 @@ impl RenderedWindow { } }; - let clip = Vec4::new( - pixel_region.min.x, - pixel_region.min.y, - pixel_region.width(), - pixel_region.height(), - ); let mut layer = Layer::new() - .with_background(Vec4::new(0.0, 0.0, 0.0, 0.0)) - .with_font("FiraCode Nerd Font".to_string()) - .with_clip(clip); + .with_background(named::BLACK.with_alpha(0).into()) + //.with_font("FiraCode Nerd Font".to_string()) + .with_clip(pixel_region.to_rect().as_untyped().try_cast().unwrap()); self.iter_border_lines_with_transform(pixel_region, grid_scale) .for_each(|(transform, line)| draw_line(transform, line, &mut layer)); scene.add_layer(layer); - let clip = Vec4::new( - inner_region.min.x, - inner_region.min.y, - inner_region.width(), - inner_region.height(), - ); let mut layer = Layer::new() - .with_background(Vec4::new(0.0, 0.0, 0.0, 0.0)) - .with_font("FiraCode Nerd Font".to_string()) - .with_clip(clip); + .with_background(named::BLACK.with_alpha(0).into()) + //.with_font("FiraCode Nerd Font".to_string()) + .with_clip(inner_region.to_rect().as_untyped().try_cast().unwrap()); self.iter_scrollable_lines_with_transform(pixel_region, grid_scale) .for_each(|(transform, line)| draw_line(transform, line, &mut layer)); @@ -684,14 +660,14 @@ impl RenderedWindow { ) -> impl Iterator, &Rc>)> { 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 transform = PixelVec::new( 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())), ); (transform, line) }) @@ -764,7 +740,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); // diff --git a/src/settings/window_size.rs b/src/settings/window_size.rs index 471ea3b73..9cf00a99f 100644 --- a/src/settings/window_size.rs +++ b/src/settings/window_size.rs @@ -9,9 +9,18 @@ use crate::{ const SETTINGS_FILE: &str = "neovide-settings.json"; -pub const DEFAULT_GRID_SIZE: GridSize = GridSize::new(100, 50); -pub const MIN_GRID_SIZE: GridSize = GridSize::new(20, 6); -pub const MAX_GRID_SIZE: GridSize = GridSize::new(10000, 1000); +pub const DEFAULT_GRID_SIZE: GridSize = GridSize { + width: 100, + height: 50, +}; +pub const MIN_GRID_SIZE: GridSize = GridSize { + width: 20, + height: 6, +}; +pub const MAX_GRID_SIZE: GridSize = GridSize { + width: 10000, + height: 1000, +}; #[derive(Serialize, Deserialize, Debug)] pub enum PersistentWindowSettings { diff --git a/src/units.rs b/src/units.rs index 1b64d483e..b6d3c7d90 100644 --- a/src/units.rs +++ b/src/units.rs @@ -1,106 +1,130 @@ -use std::ops::{Div, Mul}; +use std::{ + fmt::Debug, + marker::PhantomData, + ops::{Div, Mul}, +}; -use euclid::{Box2D, Point2D, Size2D, Vector2D}; +use glamour::{Box2, Point2, Scalar, Size2, Transform2, TransformMap, Unit, Vector2}; /// Coordinates in grid units (multiplies of the font size) -pub struct Grid; +pub struct Grid { + phantom: PhantomData, +} + +impl Unit for Grid { + type Scalar = T; +} /// Coordinates in pixel units -pub struct Pixel; +pub struct Pixel { + phantom: PhantomData, +} +impl Unit for Pixel { + type Scalar = T; +} -pub type GridVec = Vector2D; -pub type PixelVec = Vector2D; +pub type GridVec = Vector2>; +pub type PixelVec = Vector2>; -pub type GridSize = Size2D; -pub type PixelSize = Size2D; +pub type GridSize = Size2>; +pub type PixelSize = Size2>; -pub type GridPos = Point2D; -pub type PixelPos = Point2D; +pub type GridPos = Point2>; +pub type PixelPos = Point2>; -pub type GridRect = Box2D; -pub type PixelRect = Box2D; +pub type GridRect = Box2>; +pub type PixelRect = Box2>; -// The Euclid library doesn't support two dimensional scales, so make our own simplified one -#[derive(Copy, Clone)] -pub struct GridScale(pub PixelSize); +#[derive(Copy, Clone, Debug)] +pub struct GridScale { + transform: Transform2, Pixel>, +} impl GridScale { + pub fn new(scale: PixelSize) -> Self { + Self { + transform: Transform2::from_scale(scale.as_vector().cast()), + } + } + pub fn height(&self) -> f32 { - self.0.height + self.transform.matrix.y_axis.y } pub fn width(&self) -> f32 { - self.0.width + self.transform.matrix.x_axis.x } } -impl Mul for GridVec { +impl Mul for GridVec { type Output = PixelVec; #[inline] fn mul(self, scale: GridScale) -> Self::Output { - Self::Output::new(self.x * scale.0.width, self.y * scale.0.height) + let grid_vec: GridVec = self.try_cast().unwrap(); + scale.transform.map(grid_vec) } } -impl Mul for GridSize { +impl Mul for GridSize { type Output = PixelSize; #[inline] fn mul(self, scale: GridScale) -> Self::Output { - Self::Output::new(self.width * scale.0.width, self.height * scale.0.height) + (*self.as_vector() * scale).to_size() } } -impl Mul for GridPos { +impl Mul for GridPos { type Output = PixelPos; #[inline] fn mul(self, scale: GridScale) -> Self::Output { - Self::Output::new(self.x * scale.0.width, self.y * scale.0.height) + (*self.as_vector() * scale).to_point() } } -impl Mul for GridRect { +impl Mul for GridRect { type Output = PixelRect; #[inline] fn mul(self, scale: GridScale) -> Self::Output { - Self::Output::new(self.min * scale, self.max * scale) + PixelRect::new(*self.min.as_vector() * scale, *self.max.as_vector() * scale) } } -impl Div for PixelVec { +impl Div for PixelVec { type Output = GridVec; #[inline] fn div(self, scale: GridScale) -> Self::Output { - Self::Output::new(self.x / scale.0.width, self.y / scale.0.height) + let pixel_vec: PixelVec = self.try_cast().unwrap(); + scale.transform.inverse().map(pixel_vec) } } -impl Div for PixelSize { +impl Div for PixelSize { type Output = GridSize; #[inline] fn div(self, scale: GridScale) -> Self::Output { - Self::Output::new(self.width / scale.0.width, self.height / scale.0.height) + (*self.as_vector() / scale).to_size() } } -impl Div for PixelPos { +impl Div for PixelPos { type Output = GridPos; #[inline] fn div(self, scale: GridScale) -> Self::Output { - Self::Output::new(self.x / scale.0.width, self.y / scale.0.height) + (*self.as_vector() / scale).to_point() } } -impl Div for PixelRect { +impl Div for PixelRect { type Output = GridRect; #[inline] fn div(self, scale: GridScale) -> Self::Output { - Self::Output::new(self.min / scale, self.max / scale) + GridRect::new(*self.min.as_vector() / scale, *self.max.as_vector() / scale) } } diff --git a/src/window/mouse_manager.rs b/src/window/mouse_manager.rs index 0ea869958..a42840158 100644 --- a/src/window/mouse_manager.rs +++ b/src/window/mouse_manager.rs @@ -12,6 +12,8 @@ use winit::{ window::Window, }; +use glamour::Contains; + use crate::{ bridge::{send_ui, SerialCommand}, renderer::{Renderer, WindowDrawDetails}, @@ -27,9 +29,9 @@ fn clamp_position( grid_scale: GridScale, ) -> PixelPos { let min = region.min; - let max = region.max - grid_scale.0; + let max = region.max - GridPos::new(1.0, 1.0) * grid_scale; - position.clamp(min, max) + position.clamp(min, max.into()) } fn mouse_button_to_button_text(mouse_button: MouseButton) -> Option { @@ -84,9 +86,9 @@ impl MouseManager { MouseManager { drag_details: None, has_moved: false, - window_position: PixelPos::origin(), - grid_position: GridPos::origin(), - scroll_position: GridPos::::origin(), + window_position: PixelPos::default(), + grid_position: GridPos::default(), + scroll_position: GridPos::default(), touch_position: HashMap::new(), mouse_hidden: false, enabled: true, @@ -104,7 +106,7 @@ impl MouseManager { editor_state .window_regions .iter() - .filter(|details| details.region.contains(position)) + .filter(|details| details.region.contains(&position)) .last() } @@ -123,14 +125,15 @@ impl MouseManager { (relative_position / *editor_state.grid_scale) .floor() - .cast() + .try_cast() + .unwrap() } fn handle_pointer_motion(&mut self, position: PixelPos, editor_state: &EditorState) { let window_size = editor_state.window.inner_size(); let window_size = PixelSize::new(window_size.width as f32, window_size.height as f32); let relative_window_rect = PixelRect::from_size(window_size); - if !relative_window_rect.contains(position) { + if !relative_window_rect.contains(&position) { return; } @@ -159,7 +162,7 @@ impl MouseManager { send_ui(SerialCommand::Drag { button: mouse_button_to_button_text(drag_details.button).unwrap(), grid_id: window_details.event_grid_id(), - position: self.grid_position.try_cast().unwrap().to_tuple(), + position: self.grid_position.try_cast::().unwrap().to_tuple(), modifier_string: editor_state .keyboard_manager .format_modifier_string("", true), @@ -170,7 +173,7 @@ impl MouseManager { button: "move".into(), action: "".into(), // this is ignored by nvim grid_id: window_details.event_grid_id(), - position: relative_position.try_cast().unwrap().to_tuple(), + position: relative_position.try_cast::().unwrap().to_tuple(), modifier_string: editor_state .keyboard_manager .format_modifier_string("", true), @@ -210,7 +213,7 @@ impl MouseManager { button: button_text.clone(), action, grid_id: details.event_grid_id(), - position: position.try_cast().unwrap().to_tuple(), + position: position.try_cast::().unwrap().to_tuple(), modifier_string: editor_state .keyboard_manager .format_modifier_string("", true), @@ -243,9 +246,9 @@ impl MouseManager { let draw_details = self.get_window_details_under_mouse(editor_state); let grid_id = draw_details.map(|details| details.id).unwrap_or(0); - let previous: GridPos = self.scroll_position.floor().cast().cast_unit(); + let previous: GridPos = self.scroll_position.floor().try_cast().unwrap(); self.scroll_position += amount; - let new: GridPos = self.scroll_position.floor().cast().cast_unit(); + let new: GridPos = self.scroll_position.floor().try_cast().unwrap(); let vertical_input_type = match new.y.partial_cmp(&previous.y) { Some(Ordering::Greater) => Some("up"), @@ -257,7 +260,7 @@ impl MouseManager { let scroll_command = SerialCommand::Scroll { direction: input_type.to_string(), grid_id, - position: self.grid_position.try_cast().unwrap().to_tuple(), + position: self.grid_position.try_cast::().unwrap().to_tuple(), modifier_string: editor_state .keyboard_manager .format_modifier_string("", true), @@ -277,7 +280,7 @@ impl MouseManager { let scroll_command = SerialCommand::Scroll { direction: input_type.to_string(), grid_id, - position: self.grid_position.try_cast().unwrap().to_tuple(), + position: self.grid_position.try_cast::().unwrap().to_tuple(), modifier_string: editor_state .keyboard_manager .format_modifier_string("", true), diff --git a/src/window/window_wrapper.rs b/src/window/window_wrapper.rs index a27ea9d2f..659ad2140 100644 --- a/src/window/window_wrapper.rs +++ b/src/window/window_wrapper.rs @@ -102,7 +102,7 @@ impl<'a> WinitWindowWrapper<'a> { log::info!( "window created (scale_factor: {:.4}, font_dimensions: {:?})", scale_factor, - renderer.grid_renderer.grid_scale.0, + renderer.grid_renderer.grid_scale, ); let WindowSettings { @@ -451,7 +451,7 @@ impl<'a> WinitWindowWrapper<'a> { let res = self .renderer - .animate_frame(&self.get_grid_rect_from_window(GridSize::zero()).cast(), dt); + .animate_frame(&self.get_grid_rect_from_window(GridSize::default()), dt); tracy_plot!("animate_frame", res as u8 as f64); self.renderer.prepare_lines(false); #[allow(clippy::let_and_return)] @@ -581,10 +581,10 @@ impl<'a> WinitWindowWrapper<'a> { ), )); - let new_size = (grid_size.cast() * self.renderer.grid_renderer.grid_scale) + let new_size = (grid_size * self.renderer.grid_renderer.grid_scale) .floor() - .cast() - .cast_unit() + .try_cast() + .unwrap() + window_padding_size; log::info!( @@ -610,15 +610,16 @@ impl<'a> WinitWindowWrapper<'a> { PixelSize::new(self.saved_inner_size.width, self.saved_inner_size.height) - window_padding_size; - let grid_size = (content_size.cast() / self.renderer.grid_renderer.grid_scale) + let grid_size = (content_size / self.renderer.grid_renderer.grid_scale) .floor() - .cast(); + .try_cast() + .unwrap(); grid_size.max(min) } fn get_grid_rect_from_window(&self, min: GridSize) -> GridRect { - let size = self.get_grid_size_from_window(min).cast(); + let size = self.get_grid_size_from_window(min).try_cast().unwrap(); let pos = PixelPos::new(self.window_padding.left, self.window_padding.top).cast() / self.renderer.grid_renderer.grid_scale; GridRect::::from_origin_and_size(pos, size) @@ -645,10 +646,10 @@ impl<'a> WinitWindowWrapper<'a> { fn update_ime_position(&mut self) { let grid_scale = self.renderer.grid_renderer.grid_scale; - let font_dimensions = grid_scale.0; + let font_dimensions = GridSize::new(1.0, 1.0) * grid_scale; let mut position = self.renderer.get_cursor_destination(); position.y += font_dimensions.height; - let position: GridPos = (position / grid_scale).floor().cast(); + let position: GridPos = (position / grid_scale).floor().try_cast().unwrap(); let position = dpi::PhysicalPosition { x: position.x, y: position.y,