BlueGit

ict rusty-teams

Files

rusty-teams / crates / app / src / views / announcement_banner.rs

announcement_banner.rs

announcement_banner.rs 3.1 KiB Download Raw
1use crate::views::image_memory::bounded;
2use gpui_kit::*;
3use teams_core::{AnnouncementBanner, BannerBackground};
4
5use crate::data::Directory;
6
7pub const ANNOUNCEMENT_BANNER_TAG: &str = "post/announcement-banner";
8pub const BANNER_COLORS: [&str; 4] = ["periwinkleBlue", "indigo", "rose", "orangeSherbet"];
9pub const BANNER_HEIGHT: f32 = 112.;
10pub const BANNER_RADIUS: f32 = 8.;
11const HEADLINE_SIZE: f32 = 24.;
12const HEADLINE_INSET: f32 = 24.;
13const IMAGE_SHADE: f32 = 0.3;
14const GRADIENT_ANGLE: f32 = 120.;
15
16pub 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
25pub 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.
40pub 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
81pub 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
90pub 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}