| 1 | use crate::views::image_memory::bounded; |
| 2 | use gpui_kit::*; |
| 3 | use teams_core::{AnnouncementBanner, BannerBackground}; |
| 4 | |
| 5 | use crate::data::Directory; |
| 6 | |
| 7 | pub const ANNOUNCEMENT_BANNER_TAG: &str = "post/announcement-banner"; |
| 8 | pub const BANNER_COLORS: [&str; 4] = ["periwinkleBlue", "indigo", "rose", "orangeSherbet"]; |
| 9 | pub const BANNER_HEIGHT: f32 = 112.; |
| 10 | pub const BANNER_RADIUS: f32 = 8.; |
| 11 | const HEADLINE_SIZE: f32 = 24.; |
| 12 | const HEADLINE_INSET: f32 = 24.; |
| 13 | const IMAGE_SHADE: f32 = 0.3; |
| 14 | const GRADIENT_ANGLE: f32 = 120.; |
| 15 | |
| 16 | pub fn color_label(color: &str) -> &'static str { |
| 17 | match color { |
| 18 | "indigo" => "Indigo", |
| 19 | "rose" => "Rose", |
| 20 | "orangeSherbet" => "Orange sherbet", |
| 21 | _ => "Periwinkle", |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | pub fn banner_fill(color: &str) -> Background { |
| 26 | let (from, to) = match color { |
| 27 | "indigo" => (0x2F3185, 0x5B5FC7), |
| 28 | "rose" => (0xA4264F, 0xE26D8B), |
| 29 | "orangeSherbet" => (0xD8590F, 0xF5A55A), |
| 30 | _ => (0x4F52B2, 0x8B8EF0), |
| 31 | }; |
| 32 | linear_gradient( |
| 33 | GRADIENT_ANGLE, |
| 34 | linear_color_stop(rgb(from), 0.), |
| 35 | linear_color_stop(rgb(to), 1.), |
| 36 | ) |
| 37 | } |
| 38 | |
| 39 | /// The banner frame without its headline, shared with the composer. |
| 40 | pub fn banner_frame(background: &BannerBackground, directory: &Directory) -> Div { |
| 41 | let frame = div() |
| 42 | .relative() |
| 43 | .w_full() |
| 44 | .h(px(BANNER_HEIGHT)) |
| 45 | .flex() |
| 46 | .items_center() |
| 47 | .justify_center() |
| 48 | .px(px(HEADLINE_INSET)) |
| 49 | .rounded(px(BANNER_RADIUS)) |
| 50 | .overflow_hidden(); |
| 51 | match background { |
| 52 | BannerBackground::Color(color) => frame.bg(banner_fill(color)), |
| 53 | BannerBackground::LocalImage(path) => frame |
| 54 | .bg(banner_fill("")) |
| 55 | .child( |
| 56 | img(bounded(std::path::PathBuf::from(path))) |
| 57 | .absolute() |
| 58 | .inset_0() |
| 59 | .size_full() |
| 60 | .object_fit(ObjectFit::Cover), |
| 61 | ) |
| 62 | .child(div().absolute().inset_0().bg(black().opacity(IMAGE_SHADE))), |
| 63 | BannerBackground::Image(url) => { |
| 64 | let frame = frame.bg(banner_fill("")); |
| 65 | match directory.image(url) { |
| 66 | Some(entry) => frame |
| 67 | .child( |
| 68 | img(bounded(entry.path.clone())) |
| 69 | .absolute() |
| 70 | .inset_0() |
| 71 | .size_full() |
| 72 | .object_fit(ObjectFit::Cover), |
| 73 | ) |
| 74 | .child(div().absolute().inset_0().bg(black().opacity(IMAGE_SHADE))), |
| 75 | None => frame, |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | pub fn headline_style(text: Div) -> Div { |
| 82 | text.relative() |
| 83 | .text_size(px(HEADLINE_SIZE)) |
| 84 | .line_height(relative(1.25)) |
| 85 | .font_weight(FontWeight::BOLD) |
| 86 | .text_color(white()) |
| 87 | .text_center() |
| 88 | } |
| 89 | |
| 90 | pub fn announcement_banner(banner: &AnnouncementBanner, directory: &Directory) -> Div { |
| 91 | banner_frame(&banner.background, directory) |
| 92 | .debug_selector(|| ANNOUNCEMENT_BANNER_TAG.into()) |
| 93 | .child(headline_style(div().line_clamp(2).text_ellipsis()).child(banner.title.clone())) |
| 94 | } |