Picture viewer is the picture alone over a scrim with the name under it (click or Esc closes)
Browse files at this commit247bfb279bdd435bde4a04864c8af1959c39ab43Parent: 1b3b5a4- style
- picture viewer is the picture alone over a scrim with the name under it (click or Esc closes)
- avatars 512px up to 120 KB, client steps the size down to fit, server accepts any square up to 512
9 changed files +131 -48
- crates/client/src/avatar.rs +17 -9
- crates/client/src/gui.rs +70 -20
- crates/client/src/gui/chat.rs +6 -2
- crates/client/src/gui/profile.rs +24 -12
- crates/client/src/gui/style.rs +9 -0
- crates/common/src/constant.rs +2 -2
- crates/common/src/error.rs +1 -1
- crates/common/src/frame.rs +1 -1
- crates/server/src/files.rs +1 -1
crates/client/src/avatar.rsmodified+17 -9
| @@ -5,19 +5,27 @@ use common::{ | ||
| 5 | 5 | }; |
| 6 | 6 | use image::{DynamicImage, RgbImage, codecs::jpeg::JpegEncoder, imageops::FilterType}; |
| 7 | 7 | |
| 8 | -const QUALITIES: [u8; 3] = [85, 60, 40]; | |
| 8 | +const QUALITIES: [u8; 2] = [85, 60]; | |
| 9 | +const SIDES: [u32; 4] = [ | |
| 10 | + AVATAR_SIZE, | |
| 11 | + AVATAR_SIZE * 3 / 4, | |
| 12 | + AVATAR_SIZE / 2, | |
| 13 | + AVATAR_SIZE / 4, | |
| 14 | +]; | |
| 9 | 15 | |
| 10 | 16 | pub fn prepare(bytes: &[u8], maximum: u64) -> Result<Vec<u8>, Fail> { |
| 11 | - let image = image::load_from_memory(bytes).map_err(image_error)?; | |
| 12 | - let square = center_square(image) | |
| 13 | - .resize_exact(AVATAR_SIZE, AVATAR_SIZE, FilterType::Lanczos3) | |
| 14 | - .to_rgb8(); | |
| 17 | + let image = center_square(image::load_from_memory(bytes).map_err(image_error)?); | |
| 15 | 18 | |
| 16 | 19 | let mut encoded = Vec::new(); |
| 17 | - for quality in QUALITIES { | |
| 18 | - encoded = encode(&square, quality)?; | |
| 19 | - if encoded.len() as u64 <= maximum { | |
| 20 | - return Ok(encoded); | |
| 20 | + for side in SIDES { | |
| 21 | + let square = image | |
| 22 | + .resize_exact(side, side, FilterType::Lanczos3) | |
| 23 | + .to_rgb8(); | |
| 24 | + for quality in QUALITIES { | |
| 25 | + encoded = encode(&square, quality)?; | |
| 26 | + if encoded.len() as u64 <= maximum { | |
| 27 | + return Ok(encoded); | |
| 28 | + } | |
| 21 | 29 | } |
| 22 | 30 | } |
| 23 | 31 |
crates/client/src/gui.rsmodified+70 -20
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | use common::model::{Hue, Id}; |
| 2 | -use std::{collections::HashMap, fmt::Display, sync::Arc, time::Instant}; | |
| 2 | +use std::{collections::HashMap, fmt::Display, rc::Rc, sync::Arc, time::Instant}; | |
| 3 | 3 | |
| 4 | 4 | use common::{ |
| 5 | 5 | call::{GetAvatar, GetSettings, MarkRead}, |
| @@ -246,29 +246,69 @@ pub fn picture_of(community: &Community, avatars: &HashMap<Id, Arc<Image>>) -> O | ||
| 246 | 246 | avatar_id.and_then(|id| avatars.get(&id)).cloned() |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | +pub struct Zoom { | |
| 250 | + image: Arc<Image>, | |
| 251 | + round: bool, | |
| 252 | + name: String, | |
| 253 | +} | |
| 254 | + | |
| 255 | +impl Zoom { | |
| 256 | + pub fn new(image: Option<Arc<Image>>, round: bool, name: String) -> Option<Self> { | |
| 257 | + image.map(|image| Self { image, round, name }) | |
| 258 | + } | |
| 259 | +} | |
| 260 | + | |
| 249 | 261 | pub fn zoomable( |
| 262 | + entity: &Entity<Yumush>, | |
| 250 | 263 | id: impl Into<ElementId>, |
| 251 | 264 | face: Div, |
| 252 | - image: Option<Arc<Image>>, | |
| 253 | - round: bool, | |
| 254 | -) -> AnyElement { | |
| 255 | - let Some(image) = image else { | |
| 256 | - return face.into_any_element(); | |
| 265 | + zoom: Option<Zoom>, | |
| 266 | +) -> Stateful<Div> { | |
| 267 | + let face = face.id(id); | |
| 268 | + let Some(zoom) = zoom.map(Rc::new) else { | |
| 269 | + return face; | |
| 257 | 270 | }; |
| 258 | - face.id(id) | |
| 259 | - .cursor_pointer() | |
| 260 | - .on_click(move |_, window, cx| { | |
| 261 | - let image = image.clone(); | |
| 262 | - window.open_dialog(cx, move |dialog, _, _| { | |
| 263 | - let picture = img(image.clone()).size(px(size::MEDIA)); | |
| 264 | - dialog.w(px(size::MEDIA + space::XL * 2.)).child(if round { | |
| 265 | - picture.rounded_full() | |
| 266 | - } else { | |
| 267 | - picture.rounded(px(radius::LG)) | |
| 268 | - }) | |
| 269 | - }); | |
| 271 | + let entity = entity.clone(); | |
| 272 | + face.cursor_pointer().on_click(move |_, _, cx| { | |
| 273 | + let zoom = zoom.clone(); | |
| 274 | + entity.update(cx, |yumush, cx| { | |
| 275 | + yumush.zoom = Some(zoom); | |
| 276 | + cx.notify(); | |
| 277 | + }); | |
| 278 | + }) | |
| 279 | +} | |
| 280 | + | |
| 281 | +fn zoom_view(zoom: &Zoom, entity: &Entity<Yumush>, t: Tokens) -> Stateful<Div> { | |
| 282 | + let entity = entity.clone(); | |
| 283 | + let picture = img(zoom.image.clone()).size(px(size::MEDIA)); | |
| 284 | + div() | |
| 285 | + .id("zoom") | |
| 286 | + .absolute() | |
| 287 | + .inset_0() | |
| 288 | + .occlude() | |
| 289 | + .bg(t.scrim()) | |
| 290 | + .flex() | |
| 291 | + .flex_col() | |
| 292 | + .items_center() | |
| 293 | + .justify_center() | |
| 294 | + .gap(px(space::LG)) | |
| 295 | + .on_click(move |_, _, cx| { | |
| 296 | + entity.update(cx, |yumush, cx| { | |
| 297 | + yumush.zoom = None; | |
| 298 | + cx.notify(); | |
| 299 | + }) | |
| 300 | + }) | |
| 301 | + .child(if zoom.round { | |
| 302 | + picture.rounded_full() | |
| 303 | + } else { | |
| 304 | + picture.rounded(px(radius::LG)) | |
| 270 | 305 | }) |
| 271 | - .into_any_element() | |
| 306 | + .child(parts::words( | |
| 307 | + zoom.name.clone(), | |
| 308 | + parts::Text::Title, | |
| 309 | + parts::Ink::Paper, | |
| 310 | + t, | |
| 311 | + )) | |
| 272 | 312 | } |
| 273 | 313 | |
| 274 | 314 | pub fn community_name(community: &Community) -> &str { |
| @@ -569,6 +609,7 @@ pub struct Yumush { | ||
| 569 | 609 | share_apps_seen: std::cell::Cell<Instant>, |
| 570 | 610 | share_apps_task: Option<gpui_kit::Task<()>>, |
| 571 | 611 | wordmark_flips: u32, |
| 612 | + zoom: Option<Rc<Zoom>>, | |
| 572 | 613 | share_tab: common::share::Kind, |
| 573 | 614 | camera_modes: Vec<common::share::Mode>, |
| 574 | 615 | camera_devices: Vec<String>, |
| @@ -639,6 +680,7 @@ impl Yumush { | ||
| 639 | 680 | share_apps_seen: std::cell::Cell::new(Instant::now()), |
| 640 | 681 | share_apps_task: None, |
| 641 | 682 | wordmark_flips: 0, |
| 683 | + zoom: None, | |
| 642 | 684 | share_tab: common::share::Kind::Screen, |
| 643 | 685 | camera_modes: Vec::new(), |
| 644 | 686 | camera_devices: Vec::new(), |
| @@ -1353,7 +1395,10 @@ impl Render for Yumush { | ||
| 1353 | 1395 | .track_focus(&self.focus) |
| 1354 | 1396 | .on_action(cx.listener(|this, _: &FocusFind, window, cx| this.open_jump(window, cx))) |
| 1355 | 1397 | .on_action(cx.listener(|this, _: &CloseSettings, window, cx| { |
| 1356 | - if this.chat.goto.open { | |
| 1398 | + if this.zoom.is_some() { | |
| 1399 | + this.zoom = None; | |
| 1400 | + cx.notify(); | |
| 1401 | + } else if this.chat.goto.open { | |
| 1357 | 1402 | this.close_jump(window, cx); |
| 1358 | 1403 | } else if this.fullscreen { |
| 1359 | 1404 | this.toggle_fullscreen(cx); |
| @@ -1379,5 +1424,10 @@ impl Render for Yumush { | ||
| 1379 | 1424 | .then(|| self.jump_box(palette, cx)) |
| 1380 | 1425 | .flatten(), |
| 1381 | 1426 | ) |
| 1427 | + .children( | |
| 1428 | + self.zoom | |
| 1429 | + .as_ref() | |
| 1430 | + .map(|zoom| zoom_view(zoom, &cx.entity(), palette.tokens)), | |
| 1431 | + ) | |
| 1382 | 1432 | } |
| 1383 | 1433 | } |
crates/client/src/gui/chat.rsmodified+6 -2
| @@ -1488,6 +1488,7 @@ impl Yumush { | ||
| 1488 | 1488 | .gap(px(space::SM)) |
| 1489 | 1489 | .children(community.map(|community| { |
| 1490 | 1490 | super::zoomable( |
| 1491 | + entity, | |
| 1491 | 1492 | "header_picture", |
| 1492 | 1493 | super::community_icon( |
| 1493 | 1494 | palette, |
| @@ -1496,8 +1497,11 @@ impl Yumush { | ||
| 1496 | 1497 | super::text(super::style::text::CAPTION), |
| 1497 | 1498 | &self.chat.avatars, |
| 1498 | 1499 | ), |
| 1499 | - super::picture_of(community, &self.chat.avatars), | |
| 1500 | - !matches!(community.kind, CommunityKind::Group), | |
| 1500 | + super::Zoom::new( | |
| 1501 | + super::picture_of(community, &self.chat.avatars), | |
| 1502 | + !matches!(community.kind, CommunityKind::Group), | |
| 1503 | + name.to_string(), | |
| 1504 | + ), | |
| 1501 | 1505 | ) |
| 1502 | 1506 | })) |
| 1503 | 1507 | .child(super::parts::words( |
crates/client/src/gui/profile.rsmodified+24 -12
| @@ -282,18 +282,30 @@ impl Card { | ||
| 282 | 282 | .gap(px(space::LG)) |
| 283 | 283 | .child( |
| 284 | 284 | band(space::LG) |
| 285 | - .child(super::zoomable( | |
| 286 | - "profile_picture", | |
| 287 | - avatar( | |
| 288 | - palette, | |
| 289 | - &self.user, | |
| 290 | - px(size::AVATAR_LG), | |
| 291 | - text(text::BODY), | |
| 292 | - avatars, | |
| 293 | - ), | |
| 294 | - self.user.avatar_id.and_then(|id| avatars.get(&id)).cloned(), | |
| 295 | - true, | |
| 296 | - )) | |
| 285 | + .child( | |
| 286 | + super::zoomable( | |
| 287 | + entity, | |
| 288 | + "profile_picture", | |
| 289 | + avatar( | |
| 290 | + palette, | |
| 291 | + &self.user, | |
| 292 | + px(size::AVATAR_LG), | |
| 293 | + text(text::BODY), | |
| 294 | + avatars, | |
| 295 | + ), | |
| 296 | + super::Zoom::new( | |
| 297 | + self.user.avatar_id.and_then(|id| avatars.get(&id)).cloned(), | |
| 298 | + true, | |
| 299 | + self.user.username.clone(), | |
| 300 | + ), | |
| 301 | + ) | |
| 302 | + .on_click({ | |
| 303 | + let popover = popover.clone(); | |
| 304 | + move |_, window, cx| { | |
| 305 | + popover.update(cx, |state, cx| state.dismiss(window, cx)); | |
| 306 | + } | |
| 307 | + }), | |
| 308 | + ) | |
| 297 | 309 | .child( |
| 298 | 310 | stack(space::XXS) |
| 299 | 311 | .min_w_0() |
crates/client/src/gui/style.rsmodified+9 -0
| @@ -55,6 +55,13 @@ impl Tokens { | ||
| 55 | 55 | color(self.colors().ground) |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | + pub fn scrim(self) -> Hsla { | |
| 59 | + Hsla { | |
| 60 | + a: SCRIM, | |
| 61 | + ..self.ground() | |
| 62 | + } | |
| 63 | + } | |
| 64 | + | |
| 58 | 65 | pub fn raise(self) -> Hsla { |
| 59 | 66 | color(self.colors().raise) |
| 60 | 67 | } |
| @@ -104,6 +111,8 @@ impl Tokens { | ||
| 104 | 111 | } |
| 105 | 112 | } |
| 106 | 113 | |
| 114 | +const SCRIM: f32 = 0.94; | |
| 115 | + | |
| 107 | 116 | pub const PICKS: &[Hue] = Hue::ALL.split_last().unwrap().1; |
| 108 | 117 | |
| 109 | 118 | const PICTURE_SIDE: u32 = 16; |
crates/common/src/constant.rsmodified+2 -2
| @@ -13,8 +13,8 @@ pub const MAXIMUM_POLL_OPTIONS: usize = 10; | ||
| 13 | 13 | pub const MAXIMUM_POLL_QUESTION_LENGTH: usize = 128; |
| 14 | 14 | pub const MAXIMUM_POLL_OPTION_LENGTH: usize = 64; |
| 15 | 15 | pub const LOG_PAGE_LIMIT: u32 = 500; |
| 16 | -pub const AVATAR_SIZE: u32 = 128; | |
| 17 | -pub const MAXIMUM_AVATAR_BYTES: usize = 32 * 1024; | |
| 16 | +pub const AVATAR_SIZE: u32 = 512; | |
| 17 | +pub const MAXIMUM_AVATAR_BYTES: usize = 120 * 1024; | |
| 18 | 18 | pub const MAXIMUM_ANNOUNCEMENT_LENGTH: usize = 500; |
| 19 | 19 | pub const MAXIMUM_STATUS_LENGTH: usize = 64; |
| 20 | 20 | pub const MAXIMUM_DEVICE_NAME_LENGTH: usize = 64; |
crates/common/src/error.rsmodified+1 -1
| @@ -53,7 +53,7 @@ impl Display for Problem { | ||
| 53 | 53 | Problem::Characters => write!(f, "contains forbidden character"), |
| 54 | 54 | Problem::MultiLine => write!(f, "contains line break"), |
| 55 | 55 | Problem::NotJpeg => write!(f, "not JPEG"), |
| 56 | - Problem::Dimensions { expected } => write!(f, "must be {expected}x{expected} px"), | |
| 56 | + Problem::Dimensions { expected } => write!(f, "must be square, at most {expected} px"), | |
| 57 | 57 | } |
| 58 | 58 | } |
| 59 | 59 | } |
crates/common/src/frame.rsmodified+1 -1
| @@ -19,7 +19,7 @@ pub enum FrameError { | ||
| 19 | 19 | Decode(#[from] bitcode::Error), |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | -pub const UP_MAX: u32 = 64 << 10; | |
| 22 | +pub const UP_MAX: u32 = 128 << 10; | |
| 23 | 23 | pub const DOWN_MAX: u32 = 16 << 20; |
| 24 | 24 | |
| 25 | 25 | const _: () = assert!(MAXIMUM_AVATAR_BYTES as u32 + 4096 <= UP_MAX); |
crates/server/src/files.rsmodified+1 -1
| @@ -113,7 +113,7 @@ pub fn check_avatar(bytes: &[u8]) -> Result<(), ServerError> { | ||
| 113 | 113 | problem: Problem::NotJpeg, |
| 114 | 114 | } |
| 115 | 115 | })?; |
| 116 | - if image.width() != AVATAR_SIZE || image.height() != AVATAR_SIZE { | |
| 116 | + if image.width() != image.height() || image.width() > AVATAR_SIZE { | |
| 117 | 117 | return Err(CommonError::Invalid { |
| 118 | 118 | field: Field::Avatar, |
| 119 | 119 | problem: Problem::Dimensions { |