From 30f9bc9d59783beba30944ca5b63ca1b3e685a94 Mon Sep 17 00:00:00 2001 From: Keith Simmons Date: Sat, 26 Jun 2021 12:34:39 -0700 Subject: [PATCH] minor clippy fixes --- src/editor/grid.rs | 2 +- src/editor/mod.rs | 71 ++++++++++++++------------------- src/editor/window.rs | 53 +++++++++++------------- src/renderer/mod.rs | 6 +-- src/renderer/rendered_window.rs | 6 +-- 5 files changed, 59 insertions(+), 79 deletions(-) diff --git a/src/editor/grid.rs b/src/editor/grid.rs index 9fc4bbc..8990da2 100644 --- a/src/editor/grid.rs +++ b/src/editor/grid.rs @@ -29,7 +29,7 @@ impl CharacterGrid { } } - pub fn resize(&mut self, width: u64, height: u64) { + pub fn resize(&mut self, (width, height): (u64, u64)) { let new_cell_count = (width * height) as usize; let mut new_characters = vec![default_cell!(); new_cell_count]; diff --git a/src/editor/mod.rs b/src/editor/mod.rs index fe44dcf..cc557a1 100644 --- a/src/editor/mod.rs +++ b/src/editor/mod.rs @@ -238,16 +238,14 @@ impl Editor { fn resize_window(&mut self, grid: u64, width: u64, height: u64) { trace!("editor resize {}", grid); if let Some(window) = self.windows.get_mut(&grid) { - window.resize(width, height); + window.resize((width, height)); } else { let window = Window::new( grid, WindowType::Editor, - width, - height, None, - 0.0, - 0.0, + (0.0, 0.0), + (width, height), self.draw_command_batcher.clone(), ); self.windows.insert(grid, window); @@ -263,17 +261,15 @@ impl Editor { height: u64, ) { if let Some(window) = self.windows.get_mut(&grid) { - window.position(width, height, None, start_left as f64, start_top as f64); + window.position(None, (width, height), (start_left as f64, start_top as f64)); window.show(); } else { let new_window = Window::new( grid, WindowType::Editor, - width, - height, None, - start_left as f64, - start_top as f64, + (start_left as f64, start_top as f64), + (width, height), self.draw_command_batcher.clone(), ); self.windows.insert(grid, new_window); @@ -302,8 +298,6 @@ impl Editor { } window.position( - width, - height, Some(AnchorInfo { anchor_grid_id: anchor_grid, anchor_type, @@ -311,8 +305,8 @@ impl Editor { anchor_top, sort_order: sort_order.unwrap_or(grid), }), - modified_left, - modified_top, + (width, height), + (modified_left, modified_top), ); window.show(); } else { @@ -338,22 +332,18 @@ impl Editor { if let Some(window) = self.windows.get_mut(&grid) { window.window_type = WindowType::Message; window.position( - parent_width, - window.get_height(), Some(anchor_info), - 0.0, - grid_top as f64, + (parent_width, window.get_height()), + (0.0, grid_top as f64), ); window.show(); } else { let new_window = Window::new( grid, WindowType::Message, - parent_width, - 1, Some(anchor_info), - 0.0, - grid_top as f64, + (0.0, grid_top as f64), + (parent_width, 1), self.draw_command_batcher.clone(), ); self.windows.insert(grid, new_window); @@ -387,26 +377,27 @@ impl Editor { } fn set_cursor_position(&mut self, grid: u64, grid_left: u64, grid_top: u64) { - match self.windows.get(&grid) { - Some(Window { window_type: WindowType::Message, .. }) => { - // When the user presses ":" to type a command, the cursor is sent to the gutter - // in position 1 (right after the ":"). In all other cases, we want to skip - // positioning to avoid confusing movements. - let intentional = grid_left == 1; - // If the cursor was already in this message, we can still move within it. - let already_there = self.cursor.parent_window_id == grid; + if let Some(Window { + window_type: WindowType::Message, + .. + }) = self.windows.get(&grid) + { + // When the user presses ":" to type a command, the cursor is sent to the gutter + // in position 1 (right after the ":"). In all other cases, we want to skip + // positioning to avoid confusing movements. + let intentional = grid_left == 1; + // If the cursor was already in this message, we can still move within it. + let already_there = self.cursor.parent_window_id == grid; - if !intentional && !already_there { - trace!( - "Cursor unexpectedly sent to message buffer {} ({}, {})", - grid, - grid_left, - grid_top - ); - return; - } + if !intentional && !already_there { + trace!( + "Cursor unexpectedly sent to message buffer {} ({}, {})", + grid, + grid_left, + grid_top + ); + return; } - _ => {} } self.cursor.parent_window_id = grid; diff --git a/src/editor/window.rs b/src/editor/window.rs index b6d3e0b..7e7157c 100644 --- a/src/editor/window.rs +++ b/src/editor/window.rs @@ -12,10 +12,8 @@ use crate::bridge::GridLineCell; #[derive(new, Clone, Debug)] pub enum WindowDrawCommand { Position { - grid_left: f64, - grid_top: f64, - width: u64, - height: u64, + grid_position: (f64, f64), + grid_size: (u64, u64), floating_order: Option, }, Cells { @@ -45,7 +43,7 @@ pub enum WindowDrawCommand { pub enum WindowType { Editor, - Message + Message, } pub struct Window { @@ -54,9 +52,7 @@ pub struct Window { pub window_type: WindowType, pub anchor_info: Option, - - grid_left: f64, - grid_top: f64, + grid_position: (f64, f64), draw_command_batcher: Arc, } @@ -65,20 +61,17 @@ impl Window { pub fn new( grid_id: u64, window_type: WindowType, - width: u64, - height: u64, anchor_info: Option, - grid_left: f64, - grid_top: f64, + grid_position: (f64, f64), + grid_size: (u64, u64), draw_command_batcher: Arc, ) -> Window { let window = Window { grid_id, - grid: CharacterGrid::new((width, height)), + grid: CharacterGrid::new(grid_size), window_type, anchor_info, - grid_left, - grid_top, + grid_position, draw_command_batcher, }; window.send_updated_position(); @@ -96,10 +89,8 @@ impl Window { fn send_updated_position(&self) { self.send_command(WindowDrawCommand::Position { - grid_left: self.grid_left, - grid_top: self.grid_top, - width: self.grid.width, - height: self.grid.height, + grid_position: self.grid_position, + grid_size: (self.grid.width, self.grid.height), floating_order: self.anchor_info.clone().map(|anchor| anchor.sort_order), }); } @@ -127,27 +118,24 @@ impl Window { } pub fn get_grid_position(&self) -> (f64, f64) { - (self.grid_left, self.grid_top) + self.grid_position } pub fn position( &mut self, - width: u64, - height: u64, anchor_info: Option, - grid_left: f64, - grid_top: f64, + grid_size: (u64, u64), + grid_position: (f64, f64), ) { - self.grid.resize(width, height); + self.grid.resize(grid_size); self.anchor_info = anchor_info; - self.grid_left = grid_left; - self.grid_top = grid_top; + self.grid_position = grid_position; self.send_updated_position(); self.redraw(); } - pub fn resize(&mut self, width: u64, height: u64) { - self.grid.resize(width, height); + pub fn resize(&mut self, new_size: (u64, u64)) { + self.grid.resize(new_size); self.send_updated_position(); self.redraw(); } @@ -379,7 +367,12 @@ mod tests { fn window_separator_modifies_grid_and_sends_draw_command() { let (batched_receiver, batched_sender) = build_test_channels(); let mut window = Window::new( - 1, WindowType::Editor, 114, 64, None, 0.0, 0.0, batched_sender.clone() + 1, + WindowType::Editor, + None, + (0.0, 0.0), + (114, 64), + batched_sender.clone(), ); batched_sender .send_batch() diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index d7af543..0f34867 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -218,10 +218,8 @@ impl Renderer { rendered_window.handle_window_draw_command(self, command, scaling); self.rendered_windows.insert(grid_id, rendered_window); } else if let WindowDrawCommand::Position { - grid_left, - grid_top, - width, - height, + grid_position: (grid_left, grid_top), + grid_size: (width, height), .. } = command { diff --git a/src/renderer/rendered_window.rs b/src/renderer/rendered_window.rs index 7735d02..529b9b7 100644 --- a/src/renderer/rendered_window.rs +++ b/src/renderer/rendered_window.rs @@ -306,10 +306,8 @@ impl RenderedWindow { ) -> Self { match draw_command { WindowDrawCommand::Position { - grid_left, - grid_top, - width: grid_width, - height: grid_height, + grid_position: (grid_left, grid_top), + grid_size: (grid_width, grid_height), floating_order, } => { let new_destination: Point = (grid_left as f32, grid_top as f32).into();