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 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) {
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,8 +377,11 @@ 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, .. }) => {
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.
@ -406,8 +399,6 @@ impl Editor {
return;
}
}
_ => {}
}
self.cursor.parent_window_id = grid;
self.cursor.grid_position = (grid_left, grid_top);

@ -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<u64>,
},
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<AnchorInfo>,
grid_left: f64,
grid_top: f64,
grid_position: (f64, f64),
draw_command_batcher: Arc<DrawCommandBatcher>,
}
@ -65,20 +61,17 @@ impl Window {
pub fn new(
grid_id: u64,
window_type: WindowType,
width: u64,
height: u64,
anchor_info: Option<AnchorInfo>,
grid_left: f64,
grid_top: f64,
grid_position: (f64, f64),
grid_size: (u64, u64),
draw_command_batcher: Arc<DrawCommandBatcher>,
) -> 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<AnchorInfo>,
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()

@ -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
{

@ -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();

Loading…
Cancel
Save