BlueGit

ict rusty-teams

Files

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

dialog_overlay.rs

dialog_overlay.rs 3.2 KiB Download Raw
1use gpui_kit::component::{h_flex, v_flex};
2use gpui_kit::*;
3
4use super::adaptive_card::card_view;
5use super::widgets::symbol;
6use crate::app_state::{AppHandle, AppState};
7use crate::card_state::TaskDialogState;
8use crate::theme::{self, ElevatedSurface as _};
9
10const BACKDROP_OPACITY: f32 = 0.55;
11const PANEL_MARGIN: f32 = 32.;
12const PANEL_RADIUS: f32 = 10.;
13const PANEL_PADDING: f32 = 16.;
14const HEADER_GAP: f32 = 12.;
15const TITLE_SIZE: f32 = 15.;
16const CLOSE_SIZE: f32 = 28.;
17const CLOSE_ICON_SIZE: f32 = 16.;
18const MIN_WIDTH: f32 = 360.;
19const CARD_CHROME: f32 = 2. * 12. + 2.;
20
21pub fn render_task_dialog(state: &AppState, cx: &App) -> Option<AnyElement> {
22 let dialog = state.task_dialog.as_ref()?;
23 Some(
24 div()
25 .id("task-dialog-layer")
26 .absolute()
27 .top_0()
28 .left_0()
29 .size_full()
30 .flex()
31 .items_center()
32 .justify_center()
33 .child(
34 div()
35 .id("task-dialog-backdrop")
36 .absolute()
37 .top_0()
38 .left_0()
39 .size_full()
40 .bg(black().opacity(BACKDROP_OPACITY))
41 .occlude()
42 .on_click(|_, _, cx| close(cx)),
43 )
44 .child(panel(dialog, cx))
45 .into_any_element(),
46 )
47}
48
49fn panel(dialog: &TaskDialogState, cx: &App) -> Div {
50 let width = (dialog.width as f32 + CARD_CHROME).max(MIN_WIDTH);
51 v_flex()
52 .w(px(width))
53 .max_w(relative(1.))
54 .max_h(relative(1.))
55 .m(px(PANEL_MARGIN))
56 .p(px(PANEL_PADDING))
57 .gap(px(HEADER_GAP))
58 .rounded(px(PANEL_RADIUS))
59 .dialog_surface()
60 .text_color(theme::text())
61 .occlude()
62 .child(
63 h_flex()
64 .w_full()
65 .items_center()
66 .gap(px(HEADER_GAP))
67 .child(
68 div()
69 .flex_1()
70 .min_w(px(0.))
71 .text_size(px(TITLE_SIZE))
72 .font_weight(FontWeight::SEMIBOLD)
73 .child(dialog.title.clone()),
74 )
75 .child(
76 div()
77 .id("task-dialog-close")
78 .size(px(CLOSE_SIZE))
79 .flex_none()
80 .flex()
81 .items_center()
82 .justify_center()
83 .rounded_full()
84 .cursor_pointer()
85 .hover(|button| button.bg(theme::popup_hover()))
86 .on_click(|_, _, cx| close(cx))
87 .child(symbol("close", CLOSE_ICON_SIZE, theme::text_muted())),
88 ),
89 )
90 .child(
91 div()
92 .id("task-dialog-body")
93 .w_full()
94 .flex_1()
95 .min_h(px(0.))
96 .overflow_y_scroll()
97 .child(card_view(&dialog.card, &dialog.scope, cx)),
98 )
99}
100
101fn close(cx: &mut App) {
102 cx.global::<AppHandle>()
103 .0
104 .clone()
105 .update(cx, |state, cx| state.close_task_dialog(cx));
106}