From 247bfb279bdd435bde4a04864c8af1959c39ab43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sat, 28 Nov 2026 03:14:49 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20style:=20picture=20viewer=20is?= =?UTF-8?q?=20the=20picture=20alone=20over=20a=20scrim=20with=20the=20name?= =?UTF-8?q?=20under=20it=20(click=20or=20Esc=20closes);=20avatars=20512px?= =?UTF-8?q?=20up=20to=20120=20KB,=20client=20steps=20the=20size=20down=20t?= =?UTF-8?q?o=20fit,=20server=20accepts=20any=20square=20up=20to=20512?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/client/src/avatar.rs | 26 +++++---- crates/client/src/gui.rs | 90 +++++++++++++++++++++++++------- crates/client/src/gui/chat.rs | 8 ++- crates/client/src/gui/profile.rs | 36 ++++++++----- crates/client/src/gui/style.rs | 9 ++++ crates/common/src/constant.rs | 4 +- crates/common/src/error.rs | 2 +- crates/common/src/frame.rs | 2 +- crates/server/src/files.rs | 2 +- 9 files changed, 131 insertions(+), 48 deletions(-) diff --git a/crates/client/src/avatar.rs b/crates/client/src/avatar.rs index 95a20e8..5fa4d8f 100644 --- a/crates/client/src/avatar.rs +++ b/crates/client/src/avatar.rs @@ -5,19 +5,27 @@ use common::{ }; use image::{DynamicImage, RgbImage, codecs::jpeg::JpegEncoder, imageops::FilterType}; -const QUALITIES: [u8; 3] = [85, 60, 40]; +const QUALITIES: [u8; 2] = [85, 60]; +const SIDES: [u32; 4] = [ + AVATAR_SIZE, + AVATAR_SIZE * 3 / 4, + AVATAR_SIZE / 2, + AVATAR_SIZE / 4, +]; pub fn prepare(bytes: &[u8], maximum: u64) -> Result, Fail> { - let image = image::load_from_memory(bytes).map_err(image_error)?; - let square = center_square(image) - .resize_exact(AVATAR_SIZE, AVATAR_SIZE, FilterType::Lanczos3) - .to_rgb8(); + let image = center_square(image::load_from_memory(bytes).map_err(image_error)?); let mut encoded = Vec::new(); - for quality in QUALITIES { - encoded = encode(&square, quality)?; - if encoded.len() as u64 <= maximum { - return Ok(encoded); + for side in SIDES { + let square = image + .resize_exact(side, side, FilterType::Lanczos3) + .to_rgb8(); + for quality in QUALITIES { + encoded = encode(&square, quality)?; + if encoded.len() as u64 <= maximum { + return Ok(encoded); + } } } diff --git a/crates/client/src/gui.rs b/crates/client/src/gui.rs index 5f3d70f..492918c 100644 --- a/crates/client/src/gui.rs +++ b/crates/client/src/gui.rs @@ -1,5 +1,5 @@ use common::model::{Hue, Id}; -use std::{collections::HashMap, fmt::Display, sync::Arc, time::Instant}; +use std::{collections::HashMap, fmt::Display, rc::Rc, sync::Arc, time::Instant}; use common::{ call::{GetAvatar, GetSettings, MarkRead}, @@ -246,29 +246,69 @@ pub fn picture_of(community: &Community, avatars: &HashMap>) -> O avatar_id.and_then(|id| avatars.get(&id)).cloned() } +pub struct Zoom { + image: Arc, + round: bool, + name: String, +} + +impl Zoom { + pub fn new(image: Option>, round: bool, name: String) -> Option { + image.map(|image| Self { image, round, name }) + } +} + pub fn zoomable( + entity: &Entity, id: impl Into, face: Div, - image: Option>, - round: bool, -) -> AnyElement { - let Some(image) = image else { - return face.into_any_element(); + zoom: Option, +) -> Stateful
{ + let face = face.id(id); + let Some(zoom) = zoom.map(Rc::new) else { + return face; }; - face.id(id) - .cursor_pointer() - .on_click(move |_, window, cx| { - let image = image.clone(); - window.open_dialog(cx, move |dialog, _, _| { - let picture = img(image.clone()).size(px(size::MEDIA)); - dialog.w(px(size::MEDIA + space::XL * 2.)).child(if round { - picture.rounded_full() - } else { - picture.rounded(px(radius::LG)) - }) - }); + let entity = entity.clone(); + face.cursor_pointer().on_click(move |_, _, cx| { + let zoom = zoom.clone(); + entity.update(cx, |yumush, cx| { + yumush.zoom = Some(zoom); + cx.notify(); + }); + }) +} + +fn zoom_view(zoom: &Zoom, entity: &Entity, t: Tokens) -> Stateful
{ + let entity = entity.clone(); + let picture = img(zoom.image.clone()).size(px(size::MEDIA)); + div() + .id("zoom") + .absolute() + .inset_0() + .occlude() + .bg(t.scrim()) + .flex() + .flex_col() + .items_center() + .justify_center() + .gap(px(space::LG)) + .on_click(move |_, _, cx| { + entity.update(cx, |yumush, cx| { + yumush.zoom = None; + cx.notify(); + }) + }) + .child(if zoom.round { + picture.rounded_full() + } else { + picture.rounded(px(radius::LG)) }) - .into_any_element() + .child(parts::words( + zoom.name.clone(), + parts::Text::Title, + parts::Ink::Paper, + t, + )) } pub fn community_name(community: &Community) -> &str { @@ -569,6 +609,7 @@ pub struct Yumush { share_apps_seen: std::cell::Cell, share_apps_task: Option>, wordmark_flips: u32, + zoom: Option>, share_tab: common::share::Kind, camera_modes: Vec, camera_devices: Vec, @@ -639,6 +680,7 @@ impl Yumush { share_apps_seen: std::cell::Cell::new(Instant::now()), share_apps_task: None, wordmark_flips: 0, + zoom: None, share_tab: common::share::Kind::Screen, camera_modes: Vec::new(), camera_devices: Vec::new(), @@ -1353,7 +1395,10 @@ impl Render for Yumush { .track_focus(&self.focus) .on_action(cx.listener(|this, _: &FocusFind, window, cx| this.open_jump(window, cx))) .on_action(cx.listener(|this, _: &CloseSettings, window, cx| { - if this.chat.goto.open { + if this.zoom.is_some() { + this.zoom = None; + cx.notify(); + } else if this.chat.goto.open { this.close_jump(window, cx); } else if this.fullscreen { this.toggle_fullscreen(cx); @@ -1379,5 +1424,10 @@ impl Render for Yumush { .then(|| self.jump_box(palette, cx)) .flatten(), ) + .children( + self.zoom + .as_ref() + .map(|zoom| zoom_view(zoom, &cx.entity(), palette.tokens)), + ) } } diff --git a/crates/client/src/gui/chat.rs b/crates/client/src/gui/chat.rs index 64c008a..0ff541d 100644 --- a/crates/client/src/gui/chat.rs +++ b/crates/client/src/gui/chat.rs @@ -1488,6 +1488,7 @@ impl Yumush { .gap(px(space::SM)) .children(community.map(|community| { super::zoomable( + entity, "header_picture", super::community_icon( palette, @@ -1496,8 +1497,11 @@ impl Yumush { super::text(super::style::text::CAPTION), &self.chat.avatars, ), - super::picture_of(community, &self.chat.avatars), - !matches!(community.kind, CommunityKind::Group), + super::Zoom::new( + super::picture_of(community, &self.chat.avatars), + !matches!(community.kind, CommunityKind::Group), + name.to_string(), + ), ) })) .child(super::parts::words( diff --git a/crates/client/src/gui/profile.rs b/crates/client/src/gui/profile.rs index 98a985f..a8ba6e1 100644 --- a/crates/client/src/gui/profile.rs +++ b/crates/client/src/gui/profile.rs @@ -282,18 +282,30 @@ impl Card { .gap(px(space::LG)) .child( band(space::LG) - .child(super::zoomable( - "profile_picture", - avatar( - palette, - &self.user, - px(size::AVATAR_LG), - text(text::BODY), - avatars, - ), - self.user.avatar_id.and_then(|id| avatars.get(&id)).cloned(), - true, - )) + .child( + super::zoomable( + entity, + "profile_picture", + avatar( + palette, + &self.user, + px(size::AVATAR_LG), + text(text::BODY), + avatars, + ), + super::Zoom::new( + self.user.avatar_id.and_then(|id| avatars.get(&id)).cloned(), + true, + self.user.username.clone(), + ), + ) + .on_click({ + let popover = popover.clone(); + move |_, window, cx| { + popover.update(cx, |state, cx| state.dismiss(window, cx)); + } + }), + ) .child( stack(space::XXS) .min_w_0() diff --git a/crates/client/src/gui/style.rs b/crates/client/src/gui/style.rs index 511d36c..401c107 100644 --- a/crates/client/src/gui/style.rs +++ b/crates/client/src/gui/style.rs @@ -55,6 +55,13 @@ impl Tokens { color(self.colors().ground) } + pub fn scrim(self) -> Hsla { + Hsla { + a: SCRIM, + ..self.ground() + } + } + pub fn raise(self) -> Hsla { color(self.colors().raise) } @@ -104,6 +111,8 @@ impl Tokens { } } +const SCRIM: f32 = 0.94; + pub const PICKS: &[Hue] = Hue::ALL.split_last().unwrap().1; const PICTURE_SIDE: u32 = 16; diff --git a/crates/common/src/constant.rs b/crates/common/src/constant.rs index fdd00a7..1b95fd0 100644 --- a/crates/common/src/constant.rs +++ b/crates/common/src/constant.rs @@ -13,8 +13,8 @@ pub const MAXIMUM_POLL_OPTIONS: usize = 10; pub const MAXIMUM_POLL_QUESTION_LENGTH: usize = 128; pub const MAXIMUM_POLL_OPTION_LENGTH: usize = 64; pub const LOG_PAGE_LIMIT: u32 = 500; -pub const AVATAR_SIZE: u32 = 128; -pub const MAXIMUM_AVATAR_BYTES: usize = 32 * 1024; +pub const AVATAR_SIZE: u32 = 512; +pub const MAXIMUM_AVATAR_BYTES: usize = 120 * 1024; pub const MAXIMUM_ANNOUNCEMENT_LENGTH: usize = 500; pub const MAXIMUM_STATUS_LENGTH: usize = 64; pub const MAXIMUM_DEVICE_NAME_LENGTH: usize = 64; diff --git a/crates/common/src/error.rs b/crates/common/src/error.rs index 3fa0b4c..e58d186 100644 --- a/crates/common/src/error.rs +++ b/crates/common/src/error.rs @@ -53,7 +53,7 @@ impl Display for Problem { Problem::Characters => write!(f, "contains forbidden character"), Problem::MultiLine => write!(f, "contains line break"), Problem::NotJpeg => write!(f, "not JPEG"), - Problem::Dimensions { expected } => write!(f, "must be {expected}x{expected} px"), + Problem::Dimensions { expected } => write!(f, "must be square, at most {expected} px"), } } } diff --git a/crates/common/src/frame.rs b/crates/common/src/frame.rs index b829198..be16a2f 100644 --- a/crates/common/src/frame.rs +++ b/crates/common/src/frame.rs @@ -19,7 +19,7 @@ pub enum FrameError { Decode(#[from] bitcode::Error), } -pub const UP_MAX: u32 = 64 << 10; +pub const UP_MAX: u32 = 128 << 10; pub const DOWN_MAX: u32 = 16 << 20; const _: () = assert!(MAXIMUM_AVATAR_BYTES as u32 + 4096 <= UP_MAX); diff --git a/crates/server/src/files.rs b/crates/server/src/files.rs index 92d43d7..d94c964 100644 --- a/crates/server/src/files.rs +++ b/crates/server/src/files.rs @@ -113,7 +113,7 @@ pub fn check_avatar(bytes: &[u8]) -> Result<(), ServerError> { problem: Problem::NotJpeg, } })?; - if image.width() != AVATAR_SIZE || image.height() != AVATAR_SIZE { + if image.width() != image.height() || image.width() > AVATAR_SIZE { return Err(CommonError::Invalid { field: Field::Avatar, problem: Problem::Dimensions {