Skip to content

Commit 0c1fb66

Browse files
committed
removed rotation_animation duration
1 parent 378760a commit 0c1fb66

File tree

3 files changed

+42
-48
lines changed

3 files changed

+42
-48
lines changed

src/home/room_image_viewer.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use makepad_widgets::*;
22
use matrix_sdk_ui::timeline::EventTimelineItem;
33
use matrix_sdk::{
4-
media::MediaFormat, ruma::
5-
events::room::{message::MessageType, MediaSource}
6-
4+
media::MediaFormat,
5+
ruma::events::room::{message::MessageType, MediaSource},
76
};
87
use reqwest::StatusCode;
98

@@ -55,7 +54,7 @@ pub fn get_image_name_and_filesize(event_tl_item: &EventTimelineItem) -> (String
5554
.info
5655
.as_ref()
5756
.and_then(|info| info.size)
58-
.map(|s| u64::try_from(s).unwrap_or_default())
57+
.map(u64::from)
5958
.unwrap_or(0);
6059
return (name, size);
6160
}

src/shared/image_viewer.rs

Lines changed: 38 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ pub fn get_png_or_jpg_image_buffer(data: Vec<u8>) -> Result<ImageBuffer, ImageEr
3535
}
3636
}
3737

38-
/// Duration for rotation animations in seconds.
39-
///
40-
/// This value should be consistent with the duration value in set in the animator.
41-
const ROTATION_ANIMATION_DURATION: f64 = 1.0;
42-
4338
/// Configuration for zoom and pan settings in the image viewer
4439
#[derive(Clone, Debug)]
4540
pub struct Config {
@@ -464,10 +459,6 @@ struct ImageViewer {
464459
is_animating_rotation: bool,
465460
#[animator]
466461
animator: Animator,
467-
/// Timer for rotation animation, prevents clicking the rotation buttons too often
468-
/// to start the animation
469-
#[rust]
470-
timer: Timer,
471462
/// Zoom constraints for the image viewer
472463
#[rust]
473464
min_zoom: f32,
@@ -595,11 +586,9 @@ impl Widget for ImageViewer {
595586
}
596587
}
597588
if let Event::TouchUpdate(touch_event) = event {
598-
self.handle_touch_update(cx, touch_event);
599-
}
600-
if let Some(_timer) = self.timer.is_event(event) {
601-
self.is_animating_rotation = false;
589+
self.handle_pinch_to_zoom(cx, touch_event);
602590
}
591+
603592
if let (Event::Signal, Some((_background_task_id, receiver))) = (event, &mut self.receiver) {
604593
let mut remove_receiver = false;
605594
match receiver.try_recv() {
@@ -630,14 +619,29 @@ impl Widget for ImageViewer {
630619
self.receiver = None;
631620
}
632621
}
633-
self.animator_handle_event(cx, event);
622+
if let Event::NextFrame(_) = event {
623+
let animator_action = self.animator_handle_event(cx, event);
624+
let animation_id = match self.rotation_step {
625+
0 => ids!(mode.upright), // 0°
626+
1 => ids!(mode.degree_90), // 90°
627+
2 => ids!(mode.degree_180), // 180°
628+
3 => ids!(mode.degree_270), // 270°
629+
_ => ids!(mode.upright),
630+
};
631+
if self.animator.animator_in_state(cx, animation_id) {
632+
self.is_animating_rotation = animator_action.is_animating();
633+
}
634+
}
635+
634636
self.view.handle_event(cx, event, scope);
635637
self.match_event(cx, event);
636638
}
637639

638640
fn draw_walk(&mut self, cx: &mut Cx2d, scope: &mut Scope, walk: Walk) -> DrawStep {
639-
let mut layout = Layout::default();
640-
layout.flow = Flow::Overlay;
641+
let layout = Layout{
642+
flow: Flow::Overlay,
643+
..Default::default()
644+
};
641645
cx.begin_turtle(walk, layout);
642646
let steps = self.view.draw_walk(cx, scope, walk);
643647
if self.avatar_placeholder_rect.is_none() {
@@ -693,7 +697,6 @@ impl MatchEvent for ImageViewer {
693697
.clicked(actions)
694698
{
695699
if !self.is_animating_rotation {
696-
self.timer = cx.start_timeout(ROTATION_ANIMATION_DURATION);
697700
self.is_animating_rotation = true;
698701
if self.rotation_step == 3 {
699702
self.animator_cut(cx, ids!(mode.degree_neg90));
@@ -709,7 +712,6 @@ impl MatchEvent for ImageViewer {
709712
.clicked(actions)
710713
{
711714
if !self.is_animating_rotation {
712-
self.timer = cx.start_timeout(1.0);
713715
self.is_animating_rotation = true;
714716
if self.rotation_step == 0 {
715717
self.rotation_step = 4;
@@ -729,29 +731,21 @@ impl ImageViewer {
729731
self.is_animating_rotation = false; // Reset animation state
730732
self.previous_pinch_distance = None; // Reset pinch tracking
731733
self.mouse_cursor_hover_over_image = false; // Reset hover state
732-
self.timer = Timer::default(); // Reset timer
733734
self.receiver = None;
734735
self.reset_drag_state(cx);
735-
// Clear the rotated image texture with a white background
736-
if let Ok(image_buffer) = ImageBuffer::new(&[255], 1, 1) {
737-
let texture = image_buffer.into_new_texture(cx);
738-
self.view
739-
.rotated_image(ids!(rotated_image))
740-
.set_texture(cx, Some(texture.clone()));
741-
self.view.rotated_image(ids!(rotated_image)).redraw(cx);
742-
743-
}
744736
self.avatar_ref = None;
745737
self.avatar_placeholder_rect = None;
746738
self.animator_cut(cx, ids!(mode.upright));
747-
self.view
748-
.rotated_image(ids!(rotated_image_container.rotated_image))
749-
.apply_over(
750-
cx,
751-
live! {
752-
draw_bg: { scale: 1.0 }
753-
},
754-
);
739+
let rotated_image_ref = self
740+
.view
741+
.rotated_image(ids!(rotated_image_container.rotated_image));
742+
rotated_image_ref.apply_over(
743+
cx,
744+
live! {
745+
draw_bg: { scale: 1.0 }
746+
},
747+
);
748+
rotated_image_ref.set_texture(cx, None);
755749
}
756750

757751
/// Updates the shader uniforms of the rotated image widget with the current rotation,
@@ -883,7 +877,7 @@ impl ImageViewer {
883877
/// to calculate a scale factor. The scale factor is then passed to `adjust_zoom` to
884878
/// adjust the zoom level of the image viewer. When the event contains less than two
885879
/// touches, the previous pinch distance is reset to `None`.
886-
fn handle_touch_update(&mut self, cx: &mut Cx, event: &TouchUpdateEvent) {
880+
fn handle_pinch_to_zoom(&mut self, cx: &mut Cx, event: &TouchUpdateEvent) {
887881
if event.touches.len() == 2 {
888882
let touch1 = &event.touches[0];
889883
let touch2 = &event.touches[1];
@@ -985,14 +979,15 @@ impl ImageViewer {
985979
.set_date_time(cx, timestamp);
986980
}
987981
if let Some(sender) = &metadata.sender {
988-
let truncated_sender = if sender.len() > MAX_USERNAME_LENGTH {
989-
format!("{}...", &sender[..MAX_USERNAME_LENGTH - 3])
982+
if sender.len() > MAX_USERNAME_LENGTH {
983+
meta_view
984+
.label(ids!(top_left_container.content.username))
985+
.set_text(cx, &format!("{}...", &sender[..MAX_USERNAME_LENGTH - 3]));
990986
} else {
991-
sender.clone()
987+
meta_view
988+
.label(ids!(top_left_container.content.username))
989+
.set_text(cx, sender);
992990
};
993-
meta_view
994-
.label(ids!(top_left_container.content.username))
995-
.set_text(cx, &truncated_sender);
996991
}
997992
if let Some(avatar) = &metadata.avatar_ref {
998993
self.avatar_ref = Some(avatar.clone());

src/shared/text_or_image.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! or to display an error message if the image fails to load, etc.
55
66
use makepad_widgets::{image_cache::ImageCacheImpl, *};
7-
use ruma::events::room::MediaSource;
7+
use matrix_sdk::ruma::events::room::MediaSource;
88
live_design! {
99
use link::theme::*;
1010
use link::shaders::*;

0 commit comments

Comments
 (0)