diff --git a/crates/client/Cargo.toml b/crates/client/Cargo.toml index e32a4e9..688dd10 100644 --- a/crates/client/Cargo.toml +++ b/crates/client/Cargo.toml @@ -37,6 +37,7 @@ rustls-platform-verifier = "0.7.1" sysinfo = { version = "0.40.4", default-features = false, features = ["system"] } flate2 = "1.1.11" emojis = "0.9.1" +resvg = "0.50.0" [target.'cfg(any(target_os = "linux", target_os = "windows"))'.dependencies] nokhwa = { version = "0.10.11", default-features = false, features = ["input-native"] } diff --git a/crates/client/src/gui.rs b/crates/client/src/gui.rs index 4e6918e..c0db314 100644 --- a/crates/client/src/gui.rs +++ b/crates/client/src/gui.rs @@ -336,7 +336,7 @@ pub fn community_icon( .flex_shrink_0() .rounded(px(radius::SM)) .overflow_hidden() - .child(img(image.clone()).size_full()), + .child(img(image.clone()).size_full().rounded(px(radius::SM))), None => { badge(palette, community.id, &community.name, size, font).rounded(px(radius::SM)) } @@ -611,6 +611,7 @@ pub struct Yumush { share_apps_seen: std::cell::Cell, share_apps_task: Option>, wordmark_flips: u32, + wordmark_flipped: Option, zoom: Option>, emoji_group: usize, share_tab: common::share::Kind, @@ -683,6 +684,7 @@ impl Yumush { share_apps_seen: std::cell::Cell::new(Instant::now()), share_apps_task: None, wordmark_flips: 0, + wordmark_flipped: None, zoom: None, emoji_group: 0, share_tab: common::share::Kind::Screen, diff --git a/crates/client/src/gui/sidebar.rs b/crates/client/src/gui/sidebar.rs index 22c0955..f60a012 100644 --- a/crates/client/src/gui/sidebar.rs +++ b/crates/client/src/gui/sidebar.rs @@ -32,13 +32,15 @@ use super::{ widget::{bare_input, compact_frame, icon_button}, }; +const RAIL: f32 = size::AVATAR + space::XS * 2.; + impl Yumush { pub(super) fn sidebar(&self, entity: &Entity, palette: Palette) -> impl IntoElement { let collapsed = self.chat.sidebar_collapsed; let (from, to, id) = if collapsed { - (size::SIDEBAR, size::ROW, "sidebar_collapsing") + (size::SIDEBAR, RAIL, "sidebar_collapsing") } else { - (size::ROW, size::SIDEBAR, "sidebar_expanding") + (RAIL, size::SIDEBAR, "sidebar_expanding") }; let content = if collapsed { self.collapsed_sidebar(entity, palette).into_any_element() @@ -64,13 +66,21 @@ impl Yumush { fn collapsed_sidebar(&self, entity: &Entity, palette: Palette) -> Div { div() .h_full() - .w(px(size::ROW)) + .w(px(RAIL)) .flex() .flex_col() .items_center() .justify_between() .py(px(space::MD)) - .child(self.collapse_button(entity, palette)) + .child( + div() + .flex() + .flex_col() + .items_center() + .gap(px(space::MD)) + .child(logo_mark(palette)) + .child(self.collapse_button(entity, palette)), + ) .child( div() .flex() @@ -119,13 +129,16 @@ impl Yumush { move |_, _, cx| { entity.update(cx, |yumush, cx| { yumush.wordmark_flips += 1; + yumush.wordmark_flipped = Some(std::time::Instant::now()); cx.notify(); }) } }) .flex() + .items_center() + .child(logo_mark(palette).mr(px(space::XXS))) .child("yumu") - .child(wordmark_tail(self.wordmark_flips)), + .child(wordmark_tail(self.wordmark_flips, self.wordmark_flipped)), ) .child(self.collapse_button(entity, palette)) .child(icon_button( @@ -1337,7 +1350,15 @@ const CEDILLA_DROP: f32 = 0.45; const H_SHRINK: f32 = 0.6; const MORPH: std::time::Duration = std::time::Duration::from_millis(420); -fn wordmark_tail(flips: u32) -> AnyElement { +fn logo_mark(palette: Palette) -> gpui_kit::Svg { + gpui_kit::svg() + .path(crate::logo::PATH) + .size(px(size::CHIP)) + .flex_none() + .text_color(palette.text) +} + +fn wordmark_tail(flips: u32, flipped: Option) -> AnyElement { let em = super::style::text::TITLE / super::style::text::UI; let turkish = flips % 2 == 1; let progress = move |delta: f32| if turkish { delta } else { 1. - delta }; @@ -1353,11 +1374,12 @@ fn wordmark_tail(flips: u32) -> AnyElement { .child("h") }; let tail = div().relative(); - if flips == 0 { + if !flipped.is_some_and(|at| at.elapsed() < MORPH) { + let p = if turkish { 1. } else { 0. }; return tail - .child(s(0.)) - .child(cedilla(0.)) - .child(h(0.)) + .child(s(p)) + .child(cedilla(p)) + .child(h(p)) .into_any_element(); } let animation = || gpui_kit::Animation::new(MORPH).with_easing(gpui_kit::ease_in_out); diff --git a/crates/client/src/lib.rs b/crates/client/src/lib.rs index 899ea8c..1da41a9 100644 --- a/crates/client/src/lib.rs +++ b/crates/client/src/lib.rs @@ -8,6 +8,7 @@ pub mod avatar; pub mod embed; pub mod emoji; pub mod gui; +pub mod logo; pub mod marks; pub mod media; pub mod net; diff --git a/crates/client/src/logo.rs b/crates/client/src/logo.rs new file mode 100644 index 0000000..c3e60c9 --- /dev/null +++ b/crates/client/src/logo.rs @@ -0,0 +1,40 @@ +use std::borrow::Cow; + +use gpui_kit::{AssetSource, SharedString, assets::AllAssets}; + +pub const PATH: &str = "yumush/logo.svg"; + +const MARK: &str = + r#""#; + +fn svg(background: &str, ink: &str) -> String { + format!( + r#"{background}{MARK}"# + ) +} + +pub fn mark() -> String { + svg("", "#000") +} + +pub fn icon() -> String { + svg( + r##""##, + "#ece5d8", + ) +} + +pub struct Assets; + +impl AssetSource for Assets { + fn load(&self, path: &str) -> gpui_kit::Result>> { + if path == PATH { + return Ok(Some(Cow::Owned(mark().into_bytes()))); + } + AllAssets.load(path) + } + + fn list(&self, path: &str) -> gpui_kit::Result> { + AllAssets.list(path) + } +} diff --git a/crates/client/src/main.rs b/crates/client/src/main.rs index 4001ee6..9f8eab8 100644 --- a/crates/client/src/main.rs +++ b/crates/client/src/main.rs @@ -11,7 +11,7 @@ use client::{ }; use gpui_kit::{ App, AppContext, Bounds, Entity, QuitMode, TitlebarOptions, Window, WindowBounds, - WindowOptions, application, assets::AllAssets, component::Root, px, size, + WindowOptions, application, component::Root, px, size, }; use tracing::Level; @@ -45,7 +45,7 @@ fn main() { let (network_handle, network_event_receiver) = net::start(Server::load()); application() - .with_assets(AllAssets) + .with_assets(client::logo::Assets) .with_quit_mode(QuitMode::Explicit) .run(move |cx: &mut App| { gui::init(cx); @@ -95,7 +95,7 @@ fn gallery(spec: String) { return; }; application() - .with_assets(AllAssets) + .with_assets(client::logo::Assets) .run(move |cx: &mut App| { gui::init(cx); settings::apply(state.theme(), state.font_size(), cx); diff --git a/crates/client/src/tray.rs b/crates/client/src/tray.rs index f070e0e..4118944 100644 --- a/crates/client/src/tray.rs +++ b/crates/client/src/tray.rs @@ -67,10 +67,6 @@ impl TrayState { #[cfg(any(target_os = "linux", target_os = "windows"))] const ICON_SIZE: i32 = 32; #[cfg(any(target_os = "linux", target_os = "windows"))] -const ICON_COLOR: [u8; 3] = [0x7c, 0x6c, 0xf2]; -#[cfg(any(target_os = "linux", target_os = "windows"))] -const ICON_DROPS: [(f32, f32, f32); 2] = [(13.0, 18.0, 11.0), (24.0, 9.0, 6.0)]; -#[cfg(any(target_os = "linux", target_os = "windows"))] const BADGE: (f32, f32, f32) = (25.0, 25.0, 7.0); #[cfg(any(target_os = "linux", target_os = "windows"))] const UNREAD_COLOR: [u8; 3] = [0xe6, 0xe6, 0xe6]; @@ -83,6 +79,27 @@ fn coverage(x: f32, y: f32, (cx, cy, radius): (f32, f32, f32)) -> f32 { (radius - distance + 0.5).clamp(0.0, 1.0) } +#[cfg(any(target_os = "linux", target_os = "windows"))] +fn logo() -> Vec<([u8; 3], u8)> { + let tree = + resvg::usvg::Tree::from_str(&crate::logo::icon(), &Default::default()).expect("logo svg"); + let mut pixmap = + resvg::tiny_skia::Pixmap::new(ICON_SIZE as u32, ICON_SIZE as u32).expect("icon size"); + resvg::render( + &tree, + resvg::tiny_skia::Transform::default(), + &mut pixmap.as_mut(), + ); + pixmap + .pixels() + .iter() + .map(|pixel| { + let color = pixel.demultiply(); + ([color.red(), color.green(), color.blue()], color.alpha()) + }) + .collect() +} + #[cfg(any(target_os = "linux", target_os = "windows"))] fn pixels(badge: Badge) -> impl Iterator { let dot = match badge { @@ -90,19 +107,16 @@ fn pixels(badge: Badge) -> impl Iterator { Badge::Unread => Some(UNREAD_COLOR), Badge::Mention => Some(MENTION_COLOR), }; - (0..ICON_SIZE * ICON_SIZE).map(move |index| { - let x = (index % ICON_SIZE) as f32 + 0.5; - let y = (index / ICON_SIZE) as f32 + 0.5; - let base = ICON_DROPS - .iter() - .map(|drop| coverage(x, y, *drop)) - .fold(0.0, f32::max); - let (color, alpha) = match dot { - Some(color) if coverage(x, y, BADGE) > 0.0 => (color, coverage(x, y, BADGE)), - Some(_) if coverage(x, y, (BADGE.0, BADGE.1, BADGE.2 + 2.0)) > 0.0 => (ICON_COLOR, 0.0), - _ => (ICON_COLOR, base), - }; - (color, (alpha * 255.0) as u8) + logo().into_iter().enumerate().map(move |(index, base)| { + let x = (index as i32 % ICON_SIZE) as f32 + 0.5; + let y = (index as i32 / ICON_SIZE) as f32 + 0.5; + match dot { + Some(color) if coverage(x, y, BADGE) > 0.0 => { + (color, (coverage(x, y, BADGE) * 255.0) as u8) + } + Some(_) if coverage(x, y, (BADGE.0, BADGE.1, BADGE.2 + 2.0)) > 0.0 => (base.0, 0), + _ => base, + } }) } @@ -294,3 +308,17 @@ mod windows { (receiver, handle) } } + +#[cfg(all(test, any(target_os = "linux", target_os = "windows")))] +mod tests { + #[test] + fn logo_renders() { + let pixels = super::logo(); + assert_eq!(pixels.len(), (super::ICON_SIZE * super::ICON_SIZE) as usize); + assert!( + pixels + .iter() + .any(|(color, alpha)| *alpha == 255 && color[0] > 200) + ); + } +}