BlueGit

ict rusty-teams

Files

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

dialog_overlay.rs

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