|
1 | 1 | //! Image viewer widget for displaying Image with zooming and panning. |
2 | 2 | //! |
3 | 3 | //! There are 2 types of ImageViewerActions handled by this widget. They are "Show" and "Hide". |
4 | | -//! ImageViewerRef has 3 public methods, `display_using_background_thread`, `display_using_texture` and `reset`. |
| 4 | +//! ImageViewerRef has 4 public methods, `configure_zoom`, `display_using_background_thread`, `display_using_texture` and `reset`. |
5 | 5 | use std::sync::{Arc, mpsc::Receiver}; |
6 | 6 |
|
7 | 7 | use makepad_widgets::{event::TouchUpdateEvent, image_cache::{ImageBuffer, ImageError}, rotated_image::RotatedImageWidgetExt, *}; |
@@ -110,7 +110,7 @@ live_design! { |
110 | 110 | width: Fill, height: Fill, |
111 | 111 | align: { x: 0.4, y: 0.35 } |
112 | 112 |
|
113 | | - magnify_glass_sign = <Label> { |
| 113 | + magnifying_glass_sign = <Label> { |
114 | 114 | text: "+", |
115 | 115 | draw_text: { |
116 | 116 | text_style: <THEME_FONT_BOLD>{font_size: 15}, |
@@ -154,7 +154,7 @@ live_design! { |
154 | 154 | width: Fill, height: Fill, |
155 | 155 | align: { x: 0.4, y: 0.35 } |
156 | 156 |
|
157 | | - magnify_glass_sign = <Label> { |
| 157 | + magnifying_glass_sign = <Label> { |
158 | 158 | text: "-", |
159 | 159 | draw_text: { |
160 | 160 | text_style: <THEME_FONT_BOLD>{font_size: 15}, |
@@ -657,9 +657,18 @@ impl ImageViewer { |
657 | 657 | } |
658 | 658 |
|
659 | 659 | /// Handle touch update events, specifically the pinch gesture to zoom in/out. |
660 | | - /// When the event contains two touches, the distance between the two touches is used to calculate a scale factor. |
661 | | - /// The scale factor is then passed to `adjust_zoom` to adjust the zoom level of the image viewer. |
662 | | - /// When the event contains less than two touches, the previous pinch distance is reset to `None`. |
| 660 | + /// |
| 661 | + /// This method implements pinch-to-zoom functionality by: |
| 662 | + /// 1. Detecting when exactly two touch points are present |
| 663 | + /// 2. Calculating the current distance between the two touch points |
| 664 | + /// 3. Comparing it to the previous distance to determine the scale factor |
| 665 | + /// 4. Applying the scale factor to adjust the zoom level |
| 666 | + /// 5. Resetting the pinch tracking when fewer than two touches are detected |
| 667 | + /// |
| 668 | + /// When the event contains two touches, the distance between the two touches is used |
| 669 | + /// to calculate a scale factor. The scale factor is then passed to `adjust_zoom` to |
| 670 | + /// adjust the zoom level of the image viewer. When the event contains less than two |
| 671 | + /// touches, the previous pinch distance is reset to `None`. |
663 | 672 | fn handle_touch_update(&mut self, cx: &mut Cx, event: &TouchUpdateEvent) { |
664 | 673 | if event.touches.len() == 2 { |
665 | 674 | let touch1 = &event.touches[0]; |
|
0 commit comments