BlueGit

ict rusty-teams

Files

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

call_card.rs

call_card.rs 5.3 KiB Download Raw
1use gpui_kit::component::{h_flex, v_flex};
2use gpui_kit::prelude::FluentBuilder as _;
3use gpui_kit::*;
4
5use super::avatar::person_avatar;
6use super::message_row::{AVATAR_GAP, AVATAR_SIZE, RowAction, day_separator, new_marker};
7use super::profile_card::opens_profile;
8use super::widgets::symbol;
9use crate::data::Directory;
10use crate::rows::{CallCard, CallIcon, MessageRow};
11use crate::theme;
12
13const SERIES_START_GAP: f32 = 8.;
14const CARD_RADIUS: f32 = 12.;
15const CARD_MIN_WIDTH: f32 = 200.;
16const ICON_CIRCLE: f32 = 30.;
17const ICON_SIZE: f32 = 18.;
18const TITLE_SIZE: f32 = 13.;
19const DETAIL_SIZE: f32 = 11.;
20const JOIN_HEIGHT: f32 = 24.;
21
22pub struct CallActions {
23 pub call_back: RowAction,
24 pub join: RowAction,
25}
26
27fn icon_circle(call: &CallCard, own: bool) -> Div {
28 let (fill, glyph, tint) = match call.icon {
29 CallIcon::Missed => (theme::red().opacity(0.2), "call_missed", theme::red_soft()),
30 CallIcon::Call => (circle_fill(own), "call", theme::text()),
31 CallIcon::Video => (circle_fill(own), "videocam", theme::text()),
32 };
33 h_flex()
34 .size(px(ICON_CIRCLE))
35 .flex_none()
36 .items_center()
37 .justify_center()
38 .rounded_full()
39 .bg(fill)
40 .child(symbol(glyph, ICON_SIZE, tint))
41}
42
43fn circle_fill(own: bool) -> Hsla {
44 if own {
45 theme::reaction_on_own()
46 } else {
47 theme::popup()
48 }
49}
50
51fn detail_line(call: &CallCard, index: usize, own: bool, call_back: RowAction) -> Div {
52 let tint = if own {
53 theme::own_meta()
54 } else {
55 theme::text_muted()
56 };
57 h_flex()
58 .gap(px(4.))
59 .items_center()
60 .text_size(px(DETAIL_SIZE))
61 .text_color(tint)
62 .child(call.detail.clone())
63 .when(call.missed, |line| {
64 line.child("\u{b7}").child(
65 div()
66 .id(ElementId::Name(format!("call-back-{index}").into()))
67 .cursor_pointer()
68 .text_color(theme::accent_text())
69 .child("Call back")
70 .when_some(call_back, |link, call_back| {
71 link.on_click(move |_, _, cx| call_back(cx))
72 }),
73 )
74 })
75}
76
77fn join_button(index: usize, join: RowAction) -> Stateful<Div> {
78 h_flex()
79 .id(ElementId::Name(format!("call-join-{index}").into()))
80 .h(px(JOIN_HEIGHT))
81 .px(px(12.))
82 .flex_none()
83 .items_center()
84 .rounded(px(CARD_RADIUS))
85 .bg(theme::accent())
86 .text_color(theme::white())
87 .text_size(px(DETAIL_SIZE + 1.))
88 .font_weight(FontWeight::SEMIBOLD)
89 .cursor_pointer()
90 .hover(|button| button.opacity(0.85))
91 .child("Join")
92 .when_some(join, |button, join| {
93 button.on_click(move |_, _, cx| join(cx))
94 })
95}
96
97fn card(call: &CallCard, index: usize, own: bool, actions: CallActions) -> Div {
98 let CallActions { call_back, join } = actions;
99 let show_join = call.started && join.is_some();
100 h_flex()
101 .min_w(px(CARD_MIN_WIDTH))
102 .gap(px(8.))
103 .items_center()
104 .pt(px(8.))
105 .pr(px(12.))
106 .pb(px(8.))
107 .pl(px(8.))
108 .rounded(px(CARD_RADIUS))
109 .bg(if own {
110 theme::bubble_own()
111 } else {
112 theme::bubble_other()
113 })
114 .child(icon_circle(call, own))
115 .child(
116 v_flex()
117 .flex_1()
118 .gap(px(2.))
119 .child(
120 div()
121 .text_size(px(TITLE_SIZE))
122 .font_weight(FontWeight::SEMIBOLD)
123 .text_color(if call.missed {
124 theme::red_soft()
125 } else {
126 theme::text()
127 })
128 .child(call.title),
129 )
130 .child(detail_line(call, index, own, call_back)),
131 )
132 .when(show_join, |card| card.child(join_button(index, join)))
133}
134
135pub(super) fn call_card_row(
136 row: &MessageRow,
137 call: &CallCard,
138 index: usize,
139 directory: &Directory,
140 actions: CallActions,
141) -> AnyElement {
142 let own = row.own;
143 let body = if own {
144 h_flex()
145 .w_full()
146 .justify_end()
147 .child(card(call, index, true, actions))
148 } else {
149 h_flex()
150 .w_full()
151 .gap(px(AVATAR_GAP))
152 .items_start()
153 .child(
154 opens_profile(
155 div().id(ElementId::Name(format!("author-avatar-{index}").into())),
156 row.sender_id.as_deref(),
157 )
158 .w(px(AVATAR_SIZE))
159 .flex_none()
160 .child(person_avatar(
161 directory,
162 row.sender_id.as_deref(),
163 &row.author,
164 AVATAR_SIZE,
165 )),
166 )
167 .child(card(call, index, false, actions))
168 };
169 v_flex()
170 .w_full()
171 .px(px(20.))
172 .children(row.day_header.as_deref().map(day_separator))
173 .when(row.new_marker, |column| column.child(new_marker()))
174 .child(
175 div()
176 .id(ElementId::Name(format!("row-{index}").into()))
177 .w_full()
178 .pt(px(SERIES_START_GAP))
179 .child(body),
180 )
181 .into_any_element()
182}