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::{
5 };5 };
6 use image::{DynamicImage, RgbImage, codecs::jpeg::JpegEncoder, imageops::FilterType};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 pub fn prepare(bytes: &[u8], maximum: u64) -> Result<Vec<u8>, Fail> {16 pub fn prepare(bytes: &[u8], maximum: u64) -> Result<Vec<u8>, Fail> {
11- let image = image::load_from_memory(bytes).map_err(image_error)?;17+ let image = center_square(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();
15 18
16 let mut encoded = Vec::new();19 let mut encoded = Vec::new();
17- for quality in QUALITIES {20+ for side in SIDES {
18- encoded = encode(&square, quality)?;21+ let square = image
19- if encoded.len() as u64 <= maximum {22+ .resize_exact(side, side, FilterType::Lanczos3)
20- return Ok(encoded);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 use common::model::{Hue, Id};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 use common::{4 use common::{
5 call::{GetAvatar, GetSettings, MarkRead},5 call::{GetAvatar, GetSettings, MarkRead},
@@ -246,29 +246,69 @@ pub fn picture_of(community: &Community, avatars: &HashMap<Id, Arc<Image>>) -> O
246 avatar_id.and_then(|id| avatars.get(&id)).cloned()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 pub fn zoomable(261 pub fn zoomable(
262+ entity: &Entity<Yumush>,
250 id: impl Into<ElementId>,263 id: impl Into<ElementId>,
251 face: Div,264 face: Div,
252- image: Option<Arc<Image>>,265+ zoom: Option<Zoom>,
253- round: bool,266+) -> Stateful<Div> {
254-) -> AnyElement {267+ let face = face.id(id);
255- let Some(image) = image else {268+ let Some(zoom) = zoom.map(Rc::new) else {
256- return face.into_any_element();269+ return face;
257 };270 };
258- face.id(id)271+ let entity = entity.clone();
259- .cursor_pointer()272+ face.cursor_pointer().on_click(move |_, _, cx| {
260- .on_click(move |_, window, cx| {273+ let zoom = zoom.clone();
261- let image = image.clone();274+ entity.update(cx, |yumush, cx| {
262- window.open_dialog(cx, move |dialog, _, _| {275+ yumush.zoom = Some(zoom);
263- let picture = img(image.clone()).size(px(size::MEDIA));276+ cx.notify();
264- dialog.w(px(size::MEDIA + space::XL * 2.)).child(if round {277+ });
265- picture.rounded_full()278+ })
266- } else {279+}
267- picture.rounded(px(radius::LG))280+
268- })281+fn zoom_view(zoom: &Zoom, entity: &Entity<Yumush>, t: Tokens) -> Stateful<Div> {
269- });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 pub fn community_name(community: &Community) -> &str {314 pub fn community_name(community: &Community) -> &str {
@@ -569,6 +609,7 @@ pub struct Yumush {
569 share_apps_seen: std::cell::Cell<Instant>,609 share_apps_seen: std::cell::Cell<Instant>,
570 share_apps_task: Option<gpui_kit::Task<()>>,610 share_apps_task: Option<gpui_kit::Task<()>>,
571 wordmark_flips: u32,611 wordmark_flips: u32,
612+ zoom: Option<Rc<Zoom>>,
572 share_tab: common::share::Kind,613 share_tab: common::share::Kind,
573 camera_modes: Vec<common::share::Mode>,614 camera_modes: Vec<common::share::Mode>,
574 camera_devices: Vec<String>,615 camera_devices: Vec<String>,
@@ -639,6 +680,7 @@ impl Yumush {
639 share_apps_seen: std::cell::Cell::new(Instant::now()),680 share_apps_seen: std::cell::Cell::new(Instant::now()),
640 share_apps_task: None,681 share_apps_task: None,
641 wordmark_flips: 0,682 wordmark_flips: 0,
683+ zoom: None,
642 share_tab: common::share::Kind::Screen,684 share_tab: common::share::Kind::Screen,
643 camera_modes: Vec::new(),685 camera_modes: Vec::new(),
644 camera_devices: Vec::new(),686 camera_devices: Vec::new(),
@@ -1353,7 +1395,10 @@ impl Render for Yumush {
1353 .track_focus(&self.focus)1395 .track_focus(&self.focus)
1354 .on_action(cx.listener(|this, _: &FocusFind, window, cx| this.open_jump(window, cx)))1396 .on_action(cx.listener(|this, _: &FocusFind, window, cx| this.open_jump(window, cx)))
1355 .on_action(cx.listener(|this, _: &CloseSettings, window, cx| {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 this.close_jump(window, cx);1402 this.close_jump(window, cx);
1358 } else if this.fullscreen {1403 } else if this.fullscreen {
1359 this.toggle_fullscreen(cx);1404 this.toggle_fullscreen(cx);
@@ -1379,5 +1424,10 @@ impl Render for Yumush {
1379 .then(|| self.jump_box(palette, cx))1424 .then(|| self.jump_box(palette, cx))
1380 .flatten(),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 .gap(px(space::SM))1488 .gap(px(space::SM))
1489 .children(community.map(|community| {1489 .children(community.map(|community| {
1490 super::zoomable(1490 super::zoomable(
1491+ entity,
1491 "header_picture",1492 "header_picture",
1492 super::community_icon(1493 super::community_icon(
1493 palette,1494 palette,
@@ -1496,8 +1497,11 @@ impl Yumush {
1496 super::text(super::style::text::CAPTION),1497 super::text(super::style::text::CAPTION),
1497 &self.chat.avatars,1498 &self.chat.avatars,
1498 ),1499 ),
1499- super::picture_of(community, &self.chat.avatars),1500+ super::Zoom::new(
1500- !matches!(community.kind, CommunityKind::Group),1501+ super::picture_of(community, &self.chat.avatars),
1502+ !matches!(community.kind, CommunityKind::Group),
1503+ name.to_string(),
1504+ ),
1501 )1505 )
1502 }))1506 }))
1503 .child(super::parts::words(1507 .child(super::parts::words(
crates/client/src/gui/profile.rsmodified+24 -12
@@ -282,18 +282,30 @@ impl Card {
282 .gap(px(space::LG))282 .gap(px(space::LG))
283 .child(283 .child(
284 band(space::LG)284 band(space::LG)
285- .child(super::zoomable(285+ .child(
286- "profile_picture",286+ super::zoomable(
287- avatar(287+ entity,
288- palette,288+ "profile_picture",
289- &self.user,289+ avatar(
290- px(size::AVATAR_LG),290+ palette,
291- text(text::BODY),291+ &self.user,
292- avatars,292+ px(size::AVATAR_LG),
293- ),293+ text(text::BODY),
294- self.user.avatar_id.and_then(|id| avatars.get(&id)).cloned(),294+ avatars,
295- true,295+ ),
296- ))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 .child(309 .child(
298 stack(space::XXS)310 stack(space::XXS)
299 .min_w_0()311 .min_w_0()
crates/client/src/gui/style.rsmodified+9 -0
@@ -55,6 +55,13 @@ impl Tokens {
55 color(self.colors().ground)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 pub fn raise(self) -> Hsla {65 pub fn raise(self) -> Hsla {
59 color(self.colors().raise)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 pub const PICKS: &[Hue] = Hue::ALL.split_last().unwrap().1;116 pub const PICKS: &[Hue] = Hue::ALL.split_last().unwrap().1;
108 117
109 const PICTURE_SIDE: u32 = 16;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 pub const MAXIMUM_POLL_QUESTION_LENGTH: usize = 128;13 pub const MAXIMUM_POLL_QUESTION_LENGTH: usize = 128;
14 pub const MAXIMUM_POLL_OPTION_LENGTH: usize = 64;14 pub const MAXIMUM_POLL_OPTION_LENGTH: usize = 64;
15 pub const LOG_PAGE_LIMIT: u32 = 500;15 pub const LOG_PAGE_LIMIT: u32 = 500;
16-pub const AVATAR_SIZE: u32 = 128;16+pub const AVATAR_SIZE: u32 = 512;
17-pub const MAXIMUM_AVATAR_BYTES: usize = 32 * 1024;17+pub const MAXIMUM_AVATAR_BYTES: usize = 120 * 1024;
18 pub const MAXIMUM_ANNOUNCEMENT_LENGTH: usize = 500;18 pub const MAXIMUM_ANNOUNCEMENT_LENGTH: usize = 500;
19 pub const MAXIMUM_STATUS_LENGTH: usize = 64;19 pub const MAXIMUM_STATUS_LENGTH: usize = 64;
20 pub const MAXIMUM_DEVICE_NAME_LENGTH: usize = 64;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 Problem::Characters => write!(f, "contains forbidden character"),53 Problem::Characters => write!(f, "contains forbidden character"),
54 Problem::MultiLine => write!(f, "contains line break"),54 Problem::MultiLine => write!(f, "contains line break"),
55 Problem::NotJpeg => write!(f, "not JPEG"),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 Decode(#[from] bitcode::Error),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 pub const DOWN_MAX: u32 = 16 << 20;23 pub const DOWN_MAX: u32 = 16 << 20;
24 24
25 const _: () = assert!(MAXIMUM_AVATAR_BYTES as u32 + 4096 <= UP_MAX);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 problem: Problem::NotJpeg,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 return Err(CommonError::Invalid {117 return Err(CommonError::Invalid {
118 field: Field::Avatar,118 field: Field::Avatar,
119 problem: Problem::Dimensions {119 problem: Problem::Dimensions {