| 1 | use gpui_kit::component::{h_flex, v_flex}; |
| 2 | use gpui_kit::*; |
| 3 | |
| 4 | use super::adaptive_card::card_view; |
| 5 | use super::widgets::symbol; |
| 6 | use crate::app_state::{AppHandle, AppState}; |
| 7 | use crate::card_state::TaskDialogState; |
| 8 | use crate::theme; |
| 9 | |
| 10 | const BACKDROP_OPACITY: f32 = 0.55; |
| 11 | const PANEL_MARGIN: f32 = 32.; |
| 12 | const PANEL_RADIUS: f32 = 12.; |
| 13 | const PANEL_PADDING: f32 = 16.; |
| 14 | const HEADER_GAP: f32 = 12.; |
| 15 | const TITLE_SIZE: f32 = 15.; |
| 16 | const CLOSE_SIZE: f32 = 28.; |
| 17 | const CLOSE_ICON_SIZE: f32 = 16.; |
| 18 | const MIN_WIDTH: f32 = 360.; |
| 19 | const CARD_CHROME: f32 = 2. * 12. + 2.; |
| 20 | |
| 21 | pub 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 | |
| 49 | fn 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 | .bg(theme::background()) |
| 60 | .border_1() |
| 61 | .border_color(theme::border_strong()) |
| 62 | .text_color(theme::text()) |
| 63 | .occlude() |
| 64 | .child( |
| 65 | h_flex() |
| 66 | .w_full() |
| 67 | .items_center() |
| 68 | .gap(px(HEADER_GAP)) |
| 69 | .child( |
| 70 | div() |
| 71 | .flex_1() |
| 72 | .min_w(px(0.)) |
| 73 | .text_size(px(TITLE_SIZE)) |
| 74 | .font_weight(FontWeight::SEMIBOLD) |
| 75 | .child(dialog.title.clone()), |
| 76 | ) |
| 77 | .child( |
| 78 | div() |
| 79 | .id("task-dialog-close") |
| 80 | .size(px(CLOSE_SIZE)) |
| 81 | .flex_none() |
| 82 | .flex() |
| 83 | .items_center() |
| 84 | .justify_center() |
| 85 | .rounded_full() |
| 86 | .cursor_pointer() |
| 87 | .hover(|button| button.bg(theme::row_hover())) |
| 88 | .on_click(|_, _, cx| close(cx)) |
| 89 | .child(symbol("close", CLOSE_ICON_SIZE, theme::text_muted())), |
| 90 | ), |
| 91 | ) |
| 92 | .child( |
| 93 | div() |
| 94 | .id("task-dialog-body") |
| 95 | .w_full() |
| 96 | .flex_1() |
| 97 | .min_h(px(0.)) |
| 98 | .overflow_y_scroll() |
| 99 | .child(card_view(&dialog.card, &dialog.scope, cx)), |
| 100 | ) |
| 101 | } |
| 102 | |
| 103 | fn close(cx: &mut App) { |
| 104 | cx.global::<AppHandle>() |
| 105 | .0 |
| 106 | .clone() |
| 107 | .update(cx, |state, cx| state.close_task_dialog(cx)); |
| 108 | } |