Skip to content

Commit 852164c

Browse files
committed
clippy improvement
1 parent e959451 commit 852164c

File tree

3 files changed

+28
-24
lines changed

3 files changed

+28
-24
lines changed

src/app.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,9 @@ impl App {
687687

688688
/// Handles actions for the image viewer.
689689
/// Returns a boolean, is true continues the actions for loop.
690-
fn handle_image_viewer_action(&mut self, cx: &mut Cx, action: &Box<dyn ActionTrait>) -> bool {
690+
//fn handle_image_viewer_action(&mut self, cx: &mut Cx, action: &Box<dyn ActionTrait>) -> bool {
691+
fn handle_image_viewer_action(&mut self, cx: &mut Cx, action: &Action) -> bool {
692+
691693
match action.downcast_ref() {
692694
Some(ImageViewerAction::Show(load_state)) => {
693695
match load_state {

src/home/room_screen.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ impl Widget for RoomScreen {
665665
let content_message = wr.text_or_image(ids!(content.message));
666666
if let TextOrImageAction::Clicked(mxc_uri) = actions.find_widget_action(content_message.widget_uid()).cast() {
667667
let Some((texture, size)) = content_message.get_texture_and_size(cx) else { continue; };
668-
let texture = Arc::new(texture);
668+
let texture = std::rc::Rc::new(texture);
669669
let screen_width = wr.area().rect(cx).size.x;
670670
let (capped_width, capped_height) = constrain_image_dimensions(size.x, size.y, screen_width);
671671
if let Some(tl_state) = &mut self.tl_state {
@@ -721,7 +721,7 @@ impl Widget for RoomScreen {
721721
};
722722
let screen_width = wr.area().rect(cx).size.x;
723723
let (capped_width, capped_height) = constrain_image_dimensions(size.x, size.y, screen_width);
724-
let texture = Arc::new(texture);
724+
let texture = std::rc::Rc::new(texture);
725725
let Some(mxc_uri_string) = mxc_uri else { continue; };
726726
let mxc_uri = OwnedMxcUri::from(mxc_uri_string);
727727
cx.action(ImageViewerAction::Show(LoadState::Loading(texture, DVec2 { x: capped_width, y: capped_height })));

src/shared/image_viewer.rs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -443,28 +443,30 @@ impl Widget for ImageViewer {
443443
if let Event::Signal = event {
444444
let mut to_remove = false;
445445
if let Some((_background_task_id, receiver)) = &mut self.receiver {
446-
while let Ok(image_buffer_res) = receiver.try_recv() {
447-
match image_buffer_res {
448-
Ok(image_buffer) => {
449-
let rotated_image = self.view.rotated_image(ids!(rotated_image));
450-
let texture = image_buffer.into_new_texture(cx);
451-
rotated_image.set_texture(cx, Some(texture));
452-
to_remove = true;
453-
cx.action(ImageViewerAction::Show(LoadState::FinishedBackgroundDecoding));
454-
455-
}
456-
Err(error) => {
457-
let error = match error {
458-
ImageError::JpgDecode(_) | ImageError::PngDecode(_) => ImageViewerError::UnsupportedFormat,
459-
ImageError::EmptyData => ImageViewerError::BadData,
460-
ImageError::PathNotFound(_) => ImageViewerError::NotFound,
461-
ImageError::UnsupportedFormat => ImageViewerError::UnsupportedFormat,
462-
_ => ImageViewerError::BadData,
463-
};
464-
cx.action(ImageViewerAction::Show(LoadState::Error(error)));
446+
match receiver.try_recv() {
447+
Ok(image_buffer_res) => {
448+
match image_buffer_res {
449+
Ok(image_buffer) => {
450+
let rotated_image = self.view.rotated_image(ids!(rotated_image));
451+
let texture = image_buffer.into_new_texture(cx);
452+
rotated_image.set_texture(cx, Some(texture));
453+
to_remove = true;
454+
cx.action(ImageViewerAction::Show(LoadState::FinishedBackgroundDecoding));
455+
456+
}
457+
Err(error) => {
458+
let error = match error {
459+
ImageError::JpgDecode(_) | ImageError::PngDecode(_) => ImageViewerError::UnsupportedFormat,
460+
ImageError::EmptyData => ImageViewerError::BadData,
461+
ImageError::PathNotFound(_) => ImageViewerError::NotFound,
462+
ImageError::UnsupportedFormat => ImageViewerError::UnsupportedFormat,
463+
_ => ImageViewerError::BadData,
464+
};
465+
cx.action(ImageViewerAction::Show(LoadState::Error(error)));
466+
}
465467
}
466468
}
467-
break
469+
Err(_) => {}
468470
}
469471
}
470472
if to_remove {
@@ -729,7 +731,7 @@ impl ImageViewerRef {
729731
pub enum LoadState {
730732
/// The image is currently being loaded with its loading image texture and its image size.
731733
/// This texture is usually the image texture that's being selected.
732-
Loading(Arc<Option<Texture>>, DVec2),
734+
Loading(std::rc::Rc<Option<Texture>>, DVec2),
733735
/// The image has been successfully loaded given the data.
734736
Loaded(Arc<[u8]>),
735737
/// The image has been loaded from background thread.

0 commit comments

Comments
 (0)