minor clippy fixes

macos-click-through
Keith Simmons 3 years ago
parent 27a9c94ad3
commit 30f9bc9d59

@ -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 new_cell_count = (width * height) as usize;
let mut new_characters = vec![default_cell!(); new_cell_count]; let mut new_characters = vec![default_cell!(); new_cell_count];

@ -238,16 +238,14 @@ impl Editor {
fn resize_window(&mut self, grid: u64, width: u64, height: u64) { fn resize_window(&mut self, grid: u64, width: u64, height: u64) {
trace!("editor resize {}", grid); trace!("editor resize {}", grid);
if let Some(window) = self.windows.get_mut(&grid) { if let Some(window) = self.windows.get_mut(&grid) {
window.resize(width, height); window.resize((width, height));
} else { } else {
let window = Window::new( let window = Window::new(
grid, grid,
WindowType::Editor, WindowType::Editor,
width,
height,
None, None,
0.0, (0.0, 0.0),
0.0, (width, height),
self.draw_command_batcher.clone(), self.draw_command_batcher.clone(),
); );
self.windows.insert(grid, window); self.windows.insert(grid, window);
@ -263,17 +261,15 @@ impl Editor {
height: u64, height: u64,
) { ) {
if let Some(window) = self.windows.get_mut(&grid) { 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(); window.show();
} else { } else {
let new_window = Window::new( let new_window = Window::new(
grid, grid,
WindowType::Editor, WindowType::Editor,
width,
height,
None, None,
start_left as f64, (start_left as f64, start_top as f64),
start_top as f64, (width, height),
self.draw_command_batcher.clone(), self.draw_command_batcher.clone(),
); );
self.windows.insert(grid, new_window); self.windows.insert(grid, new_window);
@ -302,8 +298,6 @@ impl Editor {
} }
window.position( window.position(
width,
height,
Some(AnchorInfo { Some(AnchorInfo {
anchor_grid_id: anchor_grid, anchor_grid_id: anchor_grid,
anchor_type, anchor_type,
@ -311,8 +305,8 @@ impl Editor {
anchor_top, anchor_top,
sort_order: sort_order.unwrap_or(grid), sort_order: sort_order.unwrap_or(grid),
}), }),
modified_left, (width, height),
modified_top, (modified_left, modified_top),
); );
window.show(); window.show();
} else { } else {
@ -338,22 +332,18 @@ impl Editor {
if let Some(window) = self.windows.get_mut(&grid) { if let Some(window) = self.windows.get_mut(&grid) {
window.window_type = WindowType::Message; window.window_type = WindowType::Message;
window.position( window.position(
parent_width,
window.get_height(),
Some(anchor_info), Some(anchor_info),
0.0, (parent_width, window.get_height()),
grid_top as f64, (0.0, grid_top as f64),
); );
window.show(); window.show();
} else { } else {
let new_window = Window::new( let new_window = Window::new(
grid, grid,
WindowType::Message, WindowType::Message,
parent_width,
1,
Some(anchor_info), Some(anchor_info),
0.0, (0.0, grid_top as f64),
grid_top as f64, (parent_width, 1),
self.draw_command_batcher.clone(), self.draw_command_batcher.clone(),
); );
self.windows.insert(grid, new_window); 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) { fn set_cursor_position(&mut self, grid: u64, grid_left: u64, grid_top: u64) {
match self.windows.get(&grid) { if let Some(Window {
Some(Window { window_type: WindowType::Message, .. }) => { 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 }) = self.windows.get(&grid)
// positioning to avoid confusing movements. {
let intentional = grid_left == 1; // When the user presses ":" to type a command, the cursor is sent to the gutter
// If the cursor was already in this message, we can still move within it. // in position 1 (right after the ":"). In all other cases, we want to skip
let already_there = self.cursor.parent_window_id == grid; // 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 { if !intentional && !already_there {
trace!( trace!(
"Cursor unexpectedly sent to message buffer {} ({}, {})", "Cursor unexpectedly sent to message buffer {} ({}, {})",
grid, grid,
grid_left, grid_left,
grid_top grid_top
); );
return; return;
}
} }
_ => {}
} }
self.cursor.parent_window_id = grid; self.cursor.parent_window_id = grid;

@ -12,10 +12,8 @@ use crate::bridge::GridLineCell;
#[derive(new, Clone, Debug)] #[derive(new, Clone, Debug)]
pub enum WindowDrawCommand { pub enum WindowDrawCommand {
Position { Position {
grid_left: f64, grid_position: (f64, f64),
grid_top: f64, grid_size: (u64, u64),
width: u64,
height: u64,
floating_order: Option<u64>, floating_order: Option<u64>,
}, },
Cells { Cells {
@ -45,7 +43,7 @@ pub enum WindowDrawCommand {
pub enum WindowType { pub enum WindowType {
Editor, Editor,
Message Message,
} }
pub struct Window { pub struct Window {
@ -54,9 +52,7 @@ pub struct Window {
pub window_type: WindowType, pub window_type: WindowType,
pub anchor_info: Option<AnchorInfo>, pub anchor_info: Option<AnchorInfo>,
grid_position: (f64, f64),
grid_left: f64,
grid_top: f64,
draw_command_batcher: Arc<DrawCommandBatcher>, draw_command_batcher: Arc<DrawCommandBatcher>,
} }
@ -65,20 +61,17 @@ impl Window {
pub fn new( pub fn new(
grid_id: u64, grid_id: u64,
window_type: WindowType, window_type: WindowType,
width: u64,
height: u64,
anchor_info: Option<AnchorInfo>, anchor_info: Option<AnchorInfo>,
grid_left: f64, grid_position: (f64, f64),
grid_top: f64, grid_size: (u64, u64),
draw_command_batcher: Arc<DrawCommandBatcher>, draw_command_batcher: Arc<DrawCommandBatcher>,
) -> Window { ) -> Window {
let window = Window { let window = Window {
grid_id, grid_id,
grid: CharacterGrid::new((width, height)), grid: CharacterGrid::new(grid_size),
window_type, window_type,
anchor_info, anchor_info,
grid_left, grid_position,
grid_top,
draw_command_batcher, draw_command_batcher,
}; };
window.send_updated_position(); window.send_updated_position();
@ -96,10 +89,8 @@ impl Window {
fn send_updated_position(&self) { fn send_updated_position(&self) {
self.send_command(WindowDrawCommand::Position { self.send_command(WindowDrawCommand::Position {
grid_left: self.grid_left, grid_position: self.grid_position,
grid_top: self.grid_top, grid_size: (self.grid.width, self.grid.height),
width: self.grid.width,
height: self.grid.height,
floating_order: self.anchor_info.clone().map(|anchor| anchor.sort_order), 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) { pub fn get_grid_position(&self) -> (f64, f64) {
(self.grid_left, self.grid_top) self.grid_position
} }
pub fn position( pub fn position(
&mut self, &mut self,
width: u64,
height: u64,
anchor_info: Option<AnchorInfo>, anchor_info: Option<AnchorInfo>,
grid_left: f64, grid_size: (u64, u64),
grid_top: f64, grid_position: (f64, f64),
) { ) {
self.grid.resize(width, height); self.grid.resize(grid_size);
self.anchor_info = anchor_info; self.anchor_info = anchor_info;
self.grid_left = grid_left; self.grid_position = grid_position;
self.grid_top = grid_top;
self.send_updated_position(); self.send_updated_position();
self.redraw(); self.redraw();
} }
pub fn resize(&mut self, width: u64, height: u64) { pub fn resize(&mut self, new_size: (u64, u64)) {
self.grid.resize(width, height); self.grid.resize(new_size);
self.send_updated_position(); self.send_updated_position();
self.redraw(); self.redraw();
} }
@ -379,7 +367,12 @@ mod tests {
fn window_separator_modifies_grid_and_sends_draw_command() { fn window_separator_modifies_grid_and_sends_draw_command() {
let (batched_receiver, batched_sender) = build_test_channels(); let (batched_receiver, batched_sender) = build_test_channels();
let mut window = Window::new( 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 batched_sender
.send_batch() .send_batch()

@ -218,10 +218,8 @@ impl Renderer {
rendered_window.handle_window_draw_command(self, command, scaling); rendered_window.handle_window_draw_command(self, command, scaling);
self.rendered_windows.insert(grid_id, rendered_window); self.rendered_windows.insert(grid_id, rendered_window);
} else if let WindowDrawCommand::Position { } else if let WindowDrawCommand::Position {
grid_left, grid_position: (grid_left, grid_top),
grid_top, grid_size: (width, height),
width,
height,
.. ..
} = command } = command
{ {

@ -306,10 +306,8 @@ impl RenderedWindow {
) -> Self { ) -> Self {
match draw_command { match draw_command {
WindowDrawCommand::Position { WindowDrawCommand::Position {
grid_left, grid_position: (grid_left, grid_top),
grid_top, grid_size: (grid_width, grid_height),
width: grid_width,
height: grid_height,
floating_order, floating_order,
} => { } => {
let new_destination: Point = (grid_left as f32, grid_top as f32).into(); let new_destination: Point = (grid_left as f32, grid_top as f32).into();

Loading…
Cancel
Save