@@ -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 ) ]
4540pub 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 ( ) ) ;
0 commit comments