make editor grid access more robust

macos-click-through
Keith Simmons 5 years ago
parent c7bb4e2f7a
commit e72c8959f1

@ -201,12 +201,17 @@ impl CursorRenderer {
let (character, font_dimensions): (String, Point) = { let (character, font_dimensions): (String, Point) = {
let editor = EDITOR.lock().unwrap(); let editor = EDITOR.lock().unwrap();
let character = editor.grid[grid_y as usize][grid_x as usize].clone() let character = editor.grid
.get(grid_y as usize)
.and_then(|row| row.get(grid_x as usize).cloned())
.flatten()
.map(|(character, _)| character) .map(|(character, _)| character)
.unwrap_or(' '.to_string()); .unwrap_or(' '.to_string());
let is_double = editor.grid[grid_y as usize] let is_double = editor.grid
.get(grid_x as usize + 1) .get(grid_y as usize)
.map(|cell| cell.as_ref().map(|(character, _)| character.is_empty()).unwrap_or(false)) .and_then(|row| row.get(grid_x as usize + 1).cloned())
.flatten()
.map(|(character, _)| character.is_empty())
.unwrap_or(false); .unwrap_or(false);
let font_width = match (is_double, &cursor.shape) { let font_width = match (is_double, &cursor.shape) {

@ -171,14 +171,11 @@ pub fn ui_loop() {
let frame_start = Instant::now(); let frame_start = Instant::now();
if REDRAW_SCHEDULER.should_draw() { if REDRAW_SCHEDULER.should_draw() {
if let Err(e) = skulpin_renderer.draw(&window, |canvas, coordinate_system_helper| { skulpin_renderer.draw(&window, |canvas, coordinate_system_helper| {
if renderer.draw(canvas, coordinate_system_helper) { if renderer.draw(canvas, coordinate_system_helper) {
handle_new_grid_size(window.inner_size(), &renderer) handle_new_grid_size(window.inner_size(), &renderer)
} }
}).ok();
}) {
println!("Error during draw: {:?}", e);
}
} }
*control_flow = ControlFlow::WaitUntil(frame_start + Duration::from_secs_f32(1.0 / 60.0)); *control_flow = ControlFlow::WaitUntil(frame_start + Duration::from_secs_f32(1.0 / 60.0));

Loading…
Cancel
Save