From 6d38f34f8b0431da38297df9bc2efa6002ad1635 Mon Sep 17 00:00:00 2001 From: Serg Tereshchenko Date: Mon, 9 Aug 2021 17:45:25 +0300 Subject: [PATCH] refactor: Use paired values as tuples/Dimensions Paired values, like width/height now using tuples and Dimensions. `Dimensions` struct implements traits for multiplication and division, which allows us to scale grid size to physical and back just by multiplying `Dimensions` instead of each variable. Also, added trait for multiplication (u64, u64) by Dimensions. For the same purpose as above. --- src/cmd_line.rs | 3 +- src/main.rs | 1 + src/renderer/cursor_renderer/mod.rs | 8 +- src/renderer/fonts/caching_shaper.rs | 2 +- src/renderer/mod.rs | 95 +++++++++------------- src/renderer/rendered_window.rs | 89 +++++++++----------- src/settings/mod.rs | 4 +- src/settings/window_geometry.rs | 48 ++++------- src/utils/dimensions.rs | 83 +++++++++++++++++++ src/utils/mod.rs | 3 + src/window/window_wrapper/mod.rs | 14 ++-- src/window/window_wrapper/mouse_manager.rs | 34 ++++---- 12 files changed, 211 insertions(+), 173 deletions(-) create mode 100644 src/utils/dimensions.rs create mode 100644 src/utils/mod.rs diff --git a/src/cmd_line.rs b/src/cmd_line.rs index 70b7d2e..38a99f2 100644 --- a/src/cmd_line.rs +++ b/src/cmd_line.rs @@ -1,4 +1,5 @@ use crate::settings::*; +use crate::utils::Dimensions; use clap::{App, Arg}; @@ -11,7 +12,7 @@ pub struct CmdLineSettings { pub files_to_open: Vec, pub nofork: bool, - pub geometry: WindowGeometry, + pub geometry: Dimensions, pub wsl: bool, pub remote_tcp: Option, pub multi_grid: bool, diff --git a/src/main.rs b/src/main.rs index 0de485d..a2bbd8c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,6 +20,7 @@ mod error_handling; mod redraw_scheduler; mod renderer; mod settings; +mod utils; mod window; pub mod windows_utils; diff --git a/src/renderer/cursor_renderer/mod.rs b/src/renderer/cursor_renderer/mod.rs index 05d1ae5..6514244 100644 --- a/src/renderer/cursor_renderer/mod.rs +++ b/src/renderer/cursor_renderer/mod.rs @@ -228,8 +228,7 @@ impl CursorRenderer { pub fn update_cursor_destination( &mut self, - font_width: u64, - font_height: u64, + (font_width, font_height): (u64, u64), windows: &HashMap, ) { let (cursor_grid_x, cursor_grid_y) = self.cursor.grid_position; @@ -244,7 +243,7 @@ impl CursorRenderer { // grid position. grid_y = grid_y .max(window.grid_current_position.y) - .min(window.grid_current_position.y + window.grid_height as f32 - 1.0); + .min(window.grid_current_position.y + window.grid_size.height as f32 - 1.0); self.destination = (grid_x * font_width as f32, grid_y * font_height as f32).into(); } else { @@ -259,13 +258,12 @@ impl CursorRenderer { pub fn draw( &mut self, default_colors: &Colors, - font_size: (u64, u64), + (font_width, font_height): (u64, u64), current_mode: &EditorMode, shaper: &mut CachingShaper, canvas: &mut Canvas, dt: f32, ) { - let (font_width, font_height) = font_size; let render = self.blink_status.update_status(&self.cursor); let settings = SETTINGS.get::(); diff --git a/src/renderer/fonts/caching_shaper.rs b/src/renderer/fonts/caching_shaper.rs index 331967c..0da30eb 100644 --- a/src/renderer/fonts/caching_shaper.rs +++ b/src/renderer/fonts/caching_shaper.rs @@ -231,7 +231,7 @@ impl CachingShaper { pub fn shape(&mut self, cells: &[String], bold: bool, italic: bool) -> Vec { let current_size = self.current_size(); - let (glyph_width, _glyph_height) = self.font_base_dimensions(); + let (glyph_width, ..) = self.font_base_dimensions(); let mut resulting_blobs = Vec::new(); diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index e2d56b9..a5afc22 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -1,3 +1,8 @@ +pub mod animation_utils; +pub mod cursor_renderer; +mod fonts; +mod rendered_window; + use std::collections::HashMap; use std::sync::mpsc::Receiver; use std::sync::Arc; @@ -6,18 +11,13 @@ use glutin::dpi::PhysicalSize; use log::{error, trace}; use skia_safe::{colors, dash_path_effect, BlendMode, Canvas, Color, Paint, Rect, HSV}; -pub mod animation_utils; -pub mod cursor_renderer; -mod fonts; -mod rendered_window; - -pub use fonts::caching_shaper::CachingShaper; -pub use rendered_window::{RenderedWindow, WindowDrawDetails}; - use crate::bridge::EditorMode; use crate::editor::{Colors, DrawCommand, Style, WindowDrawCommand}; use crate::settings::*; +use crate::utils::Dimensions; use cursor_renderer::CursorRenderer; +pub use fonts::caching_shaper::CachingShaper; +pub use rendered_window::{RenderedWindow, WindowDrawDetails}; #[derive(SettingGroup)] #[setting_prefix = "window"] @@ -48,8 +48,7 @@ pub struct Renderer { pub paint: Paint, pub shaper: CachingShaper, pub default_style: Arc