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 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)
.unwrap_or(' '.to_string());
let is_double = editor.grid[grid_y as usize]
.get(grid_x as usize + 1)
.map(|cell| cell.as_ref().map(|(character, _)| character.is_empty()).unwrap_or(false))
let is_double = editor.grid
.get(grid_y as usize)
.and_then(|row| row.get(grid_x as usize + 1).cloned())
.flatten()
.map(|(character, _)| character.is_empty())
.unwrap_or(false);
let font_width = match (is_double, &cursor.shape) {

@ -171,14 +171,11 @@ pub fn ui_loop() {
let frame_start = Instant::now();
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) {
handle_new_grid_size(window.inner_size(), &renderer)
}
}) {
println!("Error during draw: {:?}", e);
}
}).ok();
}
*control_flow = ControlFlow::WaitUntil(frame_start + Duration::from_secs_f32(1.0 / 60.0));

Loading…
Cancel
Save