forge
Explore
Log in

Don't you dare go Hollow

Picture viewer is the picture alone over a scrim with the name under it (click or Esc closes)

Browse files at this commit

247bfb279bdd435bde4a04864c8af1959c39ab43Ahmet Kaan GümüşParent: 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
Show full message
🎨 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
crates/client/src/avatar.rsmodified+17 -9
@@ -5,19 +5,27 @@ use common::{
55 };
66 use image::{DynamicImage, RgbImage, codecs::jpeg::JpegEncoder, imageops::FilterType};
77
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+];
915
1016 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)?);
1518
1619 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+ }
2129 }
2230 }
2331
crates/client/src/gui.rsmodified+70 -20
@@ -1,5 +1,5 @@
11 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};
33
44 use common::{
55 call::{GetAvatar, GetSettings, MarkRead},
@@ -246,29 +246,69 @@ pub fn picture_of(community: &Community, avatars: &HashMap<Id, Arc<Image>>) -> O
246246 avatar_id.and_then(|id| avatars.get(&id)).cloned()
247247 }
248248
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+
249261 pub fn zoomable(
262+ entity: &Entity<Yumush>,
250263 id: impl Into<ElementId>,
251264 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;
257270 };
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))
270305 })
271- .into_any_element()
306+ .child(parts::words(
307+ zoom.name.clone(),
308+ parts::Text::Title,
309+ parts::Ink::Paper,
310+ t,
311+ ))
272312 }
273313
274314 pub fn community_name(community: &Community) -> &str {
@@ -569,6 +609,7 @@ pub struct Yumush {
569609 share_apps_seen: std::cell::Cell<Instant>,
570610 share_apps_task: Option<gpui_kit::Task<()>>,
571611 wordmark_flips: u32,
612+ zoom: Option<Rc<Zoom>>,
572613 share_tab: common::share::Kind,
573614 camera_modes: Vec<common::share::Mode>,
574615 camera_devices: Vec<String>,
@@ -639,6 +680,7 @@ impl Yumush {
639680 share_apps_seen: std::cell::Cell::new(Instant::now()),
640681 share_apps_task: None,
641682 wordmark_flips: 0,
683+ zoom: None,
642684 share_tab: common::share::Kind::Screen,
643685 camera_modes: Vec::new(),
644686 camera_devices: Vec::new(),
@@ -1353,7 +1395,10 @@ impl Render for Yumush {
13531395 .track_focus(&self.focus)
13541396 .on_action(cx.listener(|this, _: &FocusFind, window, cx| this.open_jump(window, cx)))
13551397 .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 {
13571402 this.close_jump(window, cx);
13581403 } else if this.fullscreen {
13591404 this.toggle_fullscreen(cx);
@@ -1379,5 +1424,10 @@ impl Render for Yumush {
13791424 .then(|| self.jump_box(palette, cx))
13801425 .flatten(),
13811426 )
1427+ .children(
1428+ self.zoom
1429+ .as_ref()
1430+ .map(|zoom| zoom_view(zoom, &cx.entity(), palette.tokens)),
1431+ )
13821432 }
13831433 }
crates/client/src/gui/chat.rsmodified+6 -2
@@ -1488,6 +1488,7 @@ impl Yumush {
14881488 .gap(px(space::SM))
14891489 .children(community.map(|community| {
14901490 super::zoomable(
1491+ entity,
14911492 "header_picture",
14921493 super::community_icon(
14931494 palette,
@@ -1496,8 +1497,11 @@ impl Yumush {
14961497 super::text(super::style::text::CAPTION),
14971498 &self.chat.avatars,
14981499 ),
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+ ),
15011505 )
15021506 }))
15031507 .child(super::parts::words(
crates/client/src/gui/profile.rsmodified+24 -12
@@ -282,18 +282,30 @@ impl Card {
282282 .gap(px(space::LG))
283283 .child(
284284 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+ )
297309 .child(
298310 stack(space::XXS)
299311 .min_w_0()
crates/client/src/gui/style.rsmodified+9 -0
@@ -55,6 +55,13 @@ impl Tokens {
5555 color(self.colors().ground)
5656 }
5757
58+ pub fn scrim(self) -> Hsla {
59+ Hsla {
60+ a: SCRIM,
61+ ..self.ground()
62+ }
63+ }
64+
5865 pub fn raise(self) -> Hsla {
5966 color(self.colors().raise)
6067 }
@@ -104,6 +111,8 @@ impl Tokens {
104111 }
105112 }
106113
114+const SCRIM: f32 = 0.94;
115+
107116 pub const PICKS: &[Hue] = Hue::ALL.split_last().unwrap().1;
108117
109118 const PICTURE_SIDE: u32 = 16;
crates/common/src/constant.rsmodified+2 -2
@@ -13,8 +13,8 @@ pub const MAXIMUM_POLL_OPTIONS: usize = 10;
1313 pub const MAXIMUM_POLL_QUESTION_LENGTH: usize = 128;
1414 pub const MAXIMUM_POLL_OPTION_LENGTH: usize = 64;
1515 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;
1818 pub const MAXIMUM_ANNOUNCEMENT_LENGTH: usize = 500;
1919 pub const MAXIMUM_STATUS_LENGTH: usize = 64;
2020 pub const MAXIMUM_DEVICE_NAME_LENGTH: usize = 64;
crates/common/src/error.rsmodified+1 -1
@@ -53,7 +53,7 @@ impl Display for Problem {
5353 Problem::Characters => write!(f, "contains forbidden character"),
5454 Problem::MultiLine => write!(f, "contains line break"),
5555 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"),
5757 }
5858 }
5959 }
crates/common/src/frame.rsmodified+1 -1
@@ -19,7 +19,7 @@ pub enum FrameError {
1919 Decode(#[from] bitcode::Error),
2020 }
2121
22-pub const UP_MAX: u32 = 64 << 10;
22+pub const UP_MAX: u32 = 128 << 10;
2323 pub const DOWN_MAX: u32 = 16 << 20;
2424
2525 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> {
113113 problem: Problem::NotJpeg,
114114 }
115115 })?;
116- if image.width() != AVATAR_SIZE || image.height() != AVATAR_SIZE {
116+ if image.width() != image.height() || image.width() > AVATAR_SIZE {
117117 return Err(CommonError::Invalid {
118118 field: Field::Avatar,
119119 problem: Problem::Dimensions {