Skip to content
Snippets Groups Projects
Unverified Commit 304ff315 authored by Grim's avatar Grim Committed by GitHub
Browse files

Use let else instead of is_none & unwrap, get entitity directly instead of iterating for it. (#122)

* Use let else instead of is_none & unwrap, don't iterate to find entity just get it directly.

* Cargo fmt
parent a44020ac
No related branches found
No related tags found
No related merge requests found
...@@ -66,9 +66,9 @@ pub(crate) fn input_mouse( ...@@ -66,9 +66,9 @@ pub(crate) fn input_mouse(
) { ) {
click_timer.0.tick(time.delta()); click_timer.0.tick(time.delta());
if active_editor.0.is_none() { let Some(active_editor_entity) = active_editor.0 else {
return; return;
} };
if click_timer.0.finished() || !evr_mouse_motion.is_empty() { if click_timer.0.finished() || !evr_mouse_motion.is_empty() {
*click_count = 0; *click_count = 0;
...@@ -83,21 +83,18 @@ pub(crate) fn input_mouse( ...@@ -83,21 +83,18 @@ pub(crate) fn input_mouse(
*click_count = 0; *click_count = 0;
} }
if windows.iter().len() == 0 { let Ok(primary_window) = windows.get_single() else {
return; return;
} };
let primary_window = windows.single();
let scale_factor = primary_window.scale_factor() as f32; let scale_factor = primary_window.scale_factor() as f32;
let (camera, camera_transform) = camera_q.iter().find(|(c, _)| c.is_active).unwrap(); let Some((camera, camera_transform)) = camera_q.iter().find(|(c, _)| c.is_active) else {
return;
};
for (mut editor, sprite_transform, text_position, entity, x_offset, sprite) in if let Ok((mut editor, sprite_transform, text_position, entity, x_offset, sprite)) =
&mut editor_q.iter_mut() editor_q.get_mut(active_editor_entity)
{ {
if active_editor.0 != Some(entity) {
continue;
}
let mut is_ui_node = false; let mut is_ui_node = false;
let mut transform = sprite_transform; let mut transform = sprite_transform;
let (mut width, mut height) = let (mut width, mut height) =
...@@ -245,7 +242,11 @@ pub(crate) fn input_kb( ...@@ -245,7 +242,11 @@ pub(crate) fn input_kb(
mut edits_duration: Local<Option<Duration>>, mut edits_duration: Local<Option<Duration>>,
_channel: Option<Res<WasmPasteAsyncChannel>>, _channel: Option<Res<WasmPasteAsyncChannel>>,
) { ) {
for ( let Some(active_editor_entity) = active_editor.0 else {
return;
};
if let Ok((
mut editor, mut editor,
mut edit_history, mut edit_history,
attrs, attrs,
...@@ -254,12 +255,8 @@ pub(crate) fn input_kb( ...@@ -254,12 +255,8 @@ pub(crate) fn input_kb(
entity, entity,
readonly_opt, readonly_opt,
password_opt, password_opt,
) in &mut cosmic_edit_query.iter_mut() )) = cosmic_edit_query.get_mut(active_editor_entity)
{ {
if active_editor.0 != Some(entity) {
continue;
}
let readonly = readonly_opt.is_some(); let readonly = readonly_opt.is_some();
let attrs = &attrs.0; let attrs = &attrs.0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment