Skip to content

Commit e959451

Browse files
committed
Remove unwanted
1 parent 130e1fe commit e959451

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

src/shared/image_viewer.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Image viewer widget for displaying Image with zooming and panning.
22
//!
33
//! 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`.
55
use std::sync::{Arc, mpsc::Receiver};
66

77
use makepad_widgets::{event::TouchUpdateEvent, image_cache::{ImageBuffer, ImageError}, rotated_image::RotatedImageWidgetExt, *};
@@ -110,7 +110,7 @@ live_design! {
110110
width: Fill, height: Fill,
111111
align: { x: 0.4, y: 0.35 }
112112

113-
magnify_glass_sign = <Label> {
113+
magnifying_glass_sign = <Label> {
114114
text: "+",
115115
draw_text: {
116116
text_style: <THEME_FONT_BOLD>{font_size: 15},
@@ -154,7 +154,7 @@ live_design! {
154154
width: Fill, height: Fill,
155155
align: { x: 0.4, y: 0.35 }
156156

157-
magnify_glass_sign = <Label> {
157+
magnifying_glass_sign = <Label> {
158158
text: "-",
159159
draw_text: {
160160
text_style: <THEME_FONT_BOLD>{font_size: 15},
@@ -657,9 +657,18 @@ impl ImageViewer {
657657
}
658658

659659
/// 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`.
663672
fn handle_touch_update(&mut self, cx: &mut Cx, event: &TouchUpdateEvent) {
664673
if event.touches.len() == 2 {
665674
let touch1 = &event.touches[0];

src/utils.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ use crate::{room::FetchedRoomAvatar, shared::image_viewer::ImageViewerError, sli
1414
/// The scheme for GEO links, used for location messages in Matrix.
1515
pub const GEO_URI_SCHEME: &str = "geo:";
1616

17-
/// The max size (width or height) of a rotated image to display.
18-
const ROTATED_IMAGE_MAX_SIZE: u32 = 500;
19-
2017
/// A wrapper type that implements the `Debug` trait for non-`Debug` types.
2118
pub struct DebugWrapper<T>(T);
2219
impl<T> std::fmt::Debug for DebugWrapper<T> {
@@ -138,6 +135,24 @@ pub fn load_png_or_jpg(img: &ImageRef, cx: &mut Cx, data: &[u8]) -> Result<(), I
138135
}
139136

140137
/// Constrain the width and height of an image to the screen_width, while preserving aspect ratio.
138+
///
139+
/// This function implements an intelligent scaling algorithm that handles three scenarios:
140+
/// 1. If both dimensions are within `screen_width`: enlarges the image so height equals `screen_width`
141+
/// 2. If height exceeds limit: scales down to fit height within `screen_width`
142+
/// 3. If width exceeds limit: scales down to fit width within `screen_width`
143+
///
144+
/// The aspect ratio is always preserved during scaling operations to prevent image distortion.
145+
///
146+
/// # Algorithm Details
147+
/// The function first checks if the image fits within the screen dimensions. If not, it calculates
148+
/// scaling factors for both width and height constraints and applies the more restrictive one.
149+
/// After applying the first constraint, it checks if the other dimension still exceeds the limit
150+
/// and applies a second scaling if necessary.
151+
///
152+
/// # Parameters
153+
/// - `width`: Original image width in pixels
154+
/// - `height`: Original image height in pixels
155+
/// - `screen_width`: Maximum allowed dimension for both width and height
141156
///
142157
/// # Returns
143158
/// A tuple of (constrained_width, constrained_height) as f64 values

0 commit comments

Comments
 (0)