diff --git a/crates/signed_app/src/app/mod.rs b/crates/signed_app/src/app/mod.rs index 293c8ff..cd12ec4 100644 --- a/crates/signed_app/src/app/mod.rs +++ b/crates/signed_app/src/app/mod.rs @@ -119,18 +119,6 @@ impl Render for AppRoot { let workspace = self.workspace.read(cx); let main = workspace.active_main(); - let prefix = h_flex() - .gap_1() - .child(titlebar_view.render_new_repository()) - .child(titlebar_view.render_explore()) - .child(titlebar_view.repository_switcher()); - - let tab_bar = h_flex() - .gap_1() - .when_some(titlebar_view.render_repo_tabs(workspace), |bar, tabs| { - bar.child(tabs) - }); - div() .relative() .size_full() @@ -151,8 +139,17 @@ impl Render for AppRoot { Shell::new("signed-shell") .titlebar( Titlebar::new("signed-titlebar") - .prefix(prefix) - .tab_bar(tab_bar) + .prefix( + h_flex() + .gap_1() + .child(titlebar_view.render_new_repository()) + .child(titlebar_view.render_explore()) + .child(titlebar_view.repository_switcher()), + ) + .tab_bar(h_flex().gap_1().when_some( + titlebar_view.render_repo_tabs(workspace), + |bar, tabs| bar.child(tabs), + )) .when_some(titlebar_view.render_user_menu(cx), |titlebar, menu| { titlebar.suffix(menu) }), diff --git a/crates/signed_app/src/titlebar/repository_switcher.rs b/crates/signed_app/src/titlebar/repository_switcher.rs index 4190776..99a1721 100644 --- a/crates/signed_app/src/titlebar/repository_switcher.rs +++ b/crates/signed_app/src/titlebar/repository_switcher.rs @@ -165,12 +165,6 @@ impl Render for RepositorySwitcher { let list_weak = row_weak.clone(); let list_on_open = on_open.clone(); let list_scroll_handle = scroll_handle.clone(); - let create_hint = Kbd::binding_for_action( - &CreateRepository, - Some(REPOSITORY_KEY_CONTEXT), - window, - ); - v_flex() .w(px(380.)) .p_2() @@ -265,7 +259,14 @@ impl Render for RepositorySwitcher { .full_width(true) .icon(Icon::named(IconRole::CirclePlus)) .child(div().flex_1().child("Create Repository")) - .when_some(create_hint, |button, hint| button.child(hint)) + .when_some( + Kbd::binding_for_action( + &CreateRepository, + Some(REPOSITORY_KEY_CONTEXT), + window, + ), + |button, hint| button.child(hint), + ) .on_click(move |_, window, cx| { log_dropped(create_weak.update(cx, |this, cx| { this.close(cx); diff --git a/crates/signed_app/src/workspace.rs b/crates/signed_app/src/workspace.rs index d23ef91..5dcad26 100644 --- a/crates/signed_app/src/workspace.rs +++ b/crates/signed_app/src/workspace.rs @@ -213,30 +213,31 @@ impl Render for Workspace { .gap_2() .when(self.details.len() > 1, |this| { let close_weak = weak.clone(); - let tabs = Tabs::new("signed-detail-tabs") - .variant(TabsVariant::Pill) - .overflow_scroll(true) - .selected(selected) - .tabs(move |_, cx| { - details - .iter() - .map(|(id, view)| match view { - Some(view) => view.tab(id.clone().into(), cx).closeable(true), - None => Tab::new(id.clone(), id.clone()).closeable(true), - }) - .collect() - }) - .on_change(move |index, _, cx| { - log_dropped(weak.update(cx, |workspace, cx| { - workspace.activate_detail_at(index, cx); - })); - }) - .on_close(move |index, _, cx| { - log_dropped(close_weak.update(cx, |workspace, cx| { - workspace.close_detail_at(index, cx); - })); - }); - this.child(tabs) + this.child( + Tabs::new("signed-detail-tabs") + .variant(TabsVariant::Pill) + .overflow_scroll(true) + .selected(selected) + .tabs(move |_, cx| { + details + .iter() + .map(|(id, view)| match view { + Some(view) => view.tab(id.clone().into(), cx).closeable(true), + None => Tab::new(id.clone(), id.clone()).closeable(true), + }) + .collect() + }) + .on_change(move |index, _, cx| { + log_dropped(weak.update(cx, |workspace, cx| { + workspace.activate_detail_at(index, cx); + })); + }) + .on_close(move |index, _, cx| { + log_dropped(close_weak.update(cx, |workspace, cx| { + workspace.close_detail_at(index, cx); + })); + }), + ) }) .child(div().flex_1().min_h_0().w_full().children(body)) } diff --git a/crates/ui/src/components/code.rs b/crates/ui/src/components/code.rs index 1cf079f..f7e01b4 100644 --- a/crates/ui/src/components/code.rs +++ b/crates/ui/src/components/code.rs @@ -437,36 +437,6 @@ impl Render for CodeViewState { let bounds_cell: std::rc::Rc>>> = std::rc::Rc::new(std::cell::RefCell::new(None)); - let rows = uniform_list((id.clone(), "rows"), line_count, { - let id = id.clone(); - let state = state.clone(); - move |range, _window, cx| { - let code = state.read(cx); - let active_line = code.active_line; - let theme = cx.theme(); - - range - .map(|line_ix| { - code.render_row( - &id, - line_ix, - active_line == Some(line_ix), - selection, - theme.mono_font, - theme.colors, - theme.ramps, - text_size, - line_height, - cx, - ) - }) - .collect() - } - }) - .track_scroll(&self.handle) - .h_full() - .w_full(); - div() .id((id.clone(), "view")) .relative() @@ -596,7 +566,37 @@ impl Render for CodeViewState { .absolute() .inset_0(), ) - .child(rows) + .child( + uniform_list((id.clone(), "rows"), line_count, { + let id = id.clone(); + let state = state.clone(); + move |range, _window, cx| { + let code = state.read(cx); + let active_line = code.active_line; + let theme = cx.theme(); + + range + .map(|line_ix| { + code.render_row( + &id, + line_ix, + active_line == Some(line_ix), + selection, + theme.mono_font, + theme.colors, + theme.ramps, + text_size, + line_height, + cx, + ) + }) + .collect() + } + }) + .track_scroll(&self.handle) + .h_full() + .w_full(), + ) .child( Scrollbar::vertical((self.id.clone(), "v-scrollbar"), self.handle.clone()) .visibility(ScrollbarVisibility::Platform), diff --git a/crates/ui/src/components/combobox.rs b/crates/ui/src/components/combobox.rs index 1aff129..5fb457e 100644 --- a/crates/ui/src/components/combobox.rs +++ b/crates/ui/src/components/combobox.rs @@ -428,37 +428,6 @@ where let state = cx.entity(); let open = self.highlight.is_some(); - let chevron = h_flex() - .id((id.clone(), "chevron")) - .cursor_pointer() - .on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation()) - .on_click({ - let state = state.clone(); - move |_, window, cx| { - let focus = state.read(cx).query.read(cx).focus_handle(); - window.focus(&focus, cx); - state.update(cx, |state, cx| { - if state.highlight.is_some() { - state.highlight = None; - } else { - if state.selected.is_some() { - state.refilter(""); - } else { - let query = state.query.read(cx).value().to_string(); - state.refilter(&query); - } - state.highlight = Some(0); - } - cx.notify(); - }); - } - }) - .child( - icon(IconRole::ChevronDown) - .size(self.size.dense_icon_rems()) - .color(colors.muted_foreground), - ); - let wrapper_bounds: Rc>>> = Rc::new(RefCell::new(None)); div() @@ -525,7 +494,39 @@ where .top_0() .bottom_0() .items_center() - .child(chevron), + .child( + h_flex() + .id((id.clone(), "chevron")) + .cursor_pointer() + .on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation()) + .on_click({ + let state = state.clone(); + move |_, window, cx| { + let focus = state.read(cx).query.read(cx).focus_handle(); + window.focus(&focus, cx); + state.update(cx, |state, cx| { + if state.highlight.is_some() { + state.highlight = None; + } else { + if state.selected.is_some() { + state.refilter(""); + } else { + let query = + state.query.read(cx).value().to_string(); + state.refilter(&query); + } + state.highlight = Some(0); + } + cx.notify(); + }); + } + }) + .child( + icon(IconRole::ChevronDown) + .size(self.size.dense_icon_rems()) + .color(colors.muted_foreground), + ), + ), ) .when(open, |wrapper| { let visible = self.visible.clone(); @@ -633,66 +634,67 @@ where .map(|bounds| bounds.size.width) .unwrap_or(COMBOBOX_WIDTH); - let panel = floating_panel( - cx, - radius.overlay, - v_flex() - .id((id.clone(), "panel")) - .debug_selector({ - let id = id.clone(); - move || format!("{id}-panel") - }) - .w(popup_width) - .p_1() - .text_color(colors.foreground), - shadows, - ) - .overflow_hidden() - .child(rows) - .child( - canvas( - { - let cell = panel_bounds.clone(); - move |bounds, _window, _cx| *cell.borrow_mut() = Some(bounds) - }, - { - let state = state.clone(); - let panel_bounds = panel_bounds.clone(); - let wrapper_bounds = wrapper_bounds.clone(); - move |_, _, window, _cx| { - window.on_mouse_event({ - let state = state.clone(); - let panel_bounds = panel_bounds.clone(); - let wrapper_bounds = wrapper_bounds.clone(); - move |event: &MouseDownEvent, phase, _window, cx| { - if phase != gpui::DispatchPhase::Bubble { - return; - } - let on_panel = panel_bounds - .borrow() - .is_some_and(|bounds| bounds.contains(&event.position)); - let on_wrapper = wrapper_bounds - .borrow() - .is_some_and(|bounds| bounds.contains(&event.position)); - if on_panel || on_wrapper { - return; - } - state.update(cx, |state, cx| { - state.highlight = None; - cx.notify(); - }); - } - }); - } - }, - ) - .absolute() - .inset_0(), - ); - wrapper.child(crate::components::menu::anchored_overlay( None, - panel.into_any_element(), + floating_panel( + cx, + radius.overlay, + v_flex() + .id((id.clone(), "panel")) + .debug_selector({ + let id = id.clone(); + move || format!("{id}-panel") + }) + .w(popup_width) + .p_1() + .text_color(colors.foreground), + shadows, + ) + .overflow_hidden() + .child(rows) + .child( + canvas( + { + let cell = panel_bounds.clone(); + move |bounds, _window, _cx| *cell.borrow_mut() = Some(bounds) + }, + { + let state = state.clone(); + let panel_bounds = panel_bounds.clone(); + let wrapper_bounds = wrapper_bounds.clone(); + move |_, _, window, _cx| { + window.on_mouse_event({ + let state = state.clone(); + let panel_bounds = panel_bounds.clone(); + let wrapper_bounds = wrapper_bounds.clone(); + move |event: &MouseDownEvent, phase, _window, cx| { + if phase != gpui::DispatchPhase::Bubble { + return; + } + let on_panel = + panel_bounds.borrow().is_some_and(|bounds| { + bounds.contains(&event.position) + }); + let on_wrapper = + wrapper_bounds.borrow().is_some_and(|bounds| { + bounds.contains(&event.position) + }); + if on_panel || on_wrapper { + return; + } + state.update(cx, |state, cx| { + state.highlight = None; + cx.notify(); + }); + } + }); + } + }, + ) + .absolute() + .inset_0(), + ) + .into_any_element(), None, )) }) diff --git a/crates/ui/src/components/command_palette.rs b/crates/ui/src/components/command_palette.rs index 89d30b8..5dd709a 100644 --- a/crates/ui/src/components/command_palette.rs +++ b/crates/ui/src/components/command_palette.rs @@ -30,8 +30,8 @@ use gpui::prelude::FluentBuilder; use gpui::{ AnyElement, App, Context, ElementId, Entity, InteractiveElement as _, IntoElement, KeyBinding, MouseButton, ParentElement as _, Render, Role, SharedString, StatefulInteractiveElement as _, - StyleRefinement, Styled as _, Subscription, UniformListScrollHandle, Window, actions, - deferred, div, relative, rems, uniform_list, + StyleRefinement, Styled as _, Subscription, UniformListScrollHandle, Window, actions, deferred, + div, relative, rems, uniform_list, }; use crate::components::common::{ @@ -459,75 +459,6 @@ impl Render for CommandPaletteState { .into_any_element() }; - let panel = floating_panel( - cx, - radius.overlay, - v_flex() - .id((id.clone(), "panel")) - .debug_selector({ - let id = id.clone(); - move || format!("{id}-panel") - }) - .key_context(COMMAND_PALETTE_CONTEXT) - .role(Role::Dialog) - .aria_label(self.name.clone()) - .w_full() - .max_w(relative(0.6)) - .p_2() - .gap_2() - .text_color(colors.foreground), - shadows, - ) - .overflow_hidden() - .refine_style(&self.style) - .on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation()) - .on_action({ - let state = state.clone(); - move |_: &HighlightNext, _window, cx| { - state.update(cx, |state, cx| state.move_highlight(1, cx)); - } - }) - .on_action({ - let state = state.clone(); - move |_: &HighlightPrevious, _window, cx| { - state.update(cx, |state, cx| state.move_highlight(-1, cx)); - } - }) - .on_action({ - let state = state.clone(); - move |_: &Choose, window, cx| { - state.update(cx, |state, cx| state.choose(window, cx)); - } - }) - .on_action({ - let state = state.clone(); - move |_: &Dismiss, window, cx| { - state.update(cx, |state, cx| state.dismiss(window, cx)); - } - }) - .child( - Input::new((id.clone(), "query"), self.query.clone()) - .placeholder(self.placeholder.clone()), - ) - .child(rows) - .child(crate::components::menu::focus_capture( - query_focus.clone(), - move |window, cx| !query_focus.contains_focused(window, cx), - )); - - let scrim = div() - .absolute() - .inset_0() - .bg(colors.overlay) - .occlude() - .on_mouse_down(MouseButton::Left, { - let state = state.clone(); - move |_, _window, cx| { - state.update(cx, |state, cx| state.close(cx)); - cx.stop_propagation(); - } - }); - deferred( div() .absolute() @@ -536,8 +467,77 @@ impl Render for CommandPaletteState { .justify_center() .items_start() .pt(titlebar_height) - .child(scrim) - .child(panel), + .child( + div() + .absolute() + .inset_0() + .bg(colors.overlay) + .occlude() + .on_mouse_down(MouseButton::Left, { + let state = state.clone(); + move |_, _window, cx| { + state.update(cx, |state, cx| state.close(cx)); + cx.stop_propagation(); + } + }), + ) + .child( + floating_panel( + cx, + radius.overlay, + v_flex() + .id((id.clone(), "panel")) + .debug_selector({ + let id = id.clone(); + move || format!("{id}-panel") + }) + .key_context(COMMAND_PALETTE_CONTEXT) + .role(Role::Dialog) + .aria_label(self.name.clone()) + .w_full() + .max_w(relative(0.6)) + .p_2() + .gap_2() + .text_color(colors.foreground), + shadows, + ) + .overflow_hidden() + .refine_style(&self.style) + .on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation()) + .on_action({ + let state = state.clone(); + move |_: &HighlightNext, _window, cx| { + state.update(cx, |state, cx| state.move_highlight(1, cx)); + } + }) + .on_action({ + let state = state.clone(); + move |_: &HighlightPrevious, _window, cx| { + state.update(cx, |state, cx| state.move_highlight(-1, cx)); + } + }) + .on_action({ + let state = state.clone(); + move |_: &Choose, window, cx| { + state.update(cx, |state, cx| state.choose(window, cx)); + } + }) + .on_action({ + let state = state.clone(); + move |_: &Dismiss, window, cx| { + state.update(cx, |state, cx| state.dismiss(window, cx)); + } + }) + .child( + Input::new((id.clone(), "query"), self.query.clone()) + .placeholder(self.placeholder.clone()), + ) + .child(rows) + .child(crate::components::menu::focus_capture( + query_focus.clone(), + move |window, cx| !query_focus.contains_focused(window, cx), + )), + ), ) .with_priority(DIALOG_LAYER) .into_any_element() diff --git a/crates/ui/src/components/dropdown_menu.rs b/crates/ui/src/components/dropdown_menu.rs index eaf59ef..0c2b6cb 100644 --- a/crates/ui/src/components/dropdown_menu.rs +++ b/crates/ui/src/components/dropdown_menu.rs @@ -324,42 +324,6 @@ impl RenderOnce for DropdownMenu { }) }; - let chevron_zone = h_flex() - .id((self.id.clone(), "chevron")) - .debug_selector({ - let id = self.id.clone(); - move || format!("{id}-chevron") - }) - .relative() - .h_full() - .control_dense_padding_x(self.size) - .rounded_r(radius) - .rounded_l_none() - .border_l_1() - .border_color(border) - .when(self.open, |zone| zone.bg(pressed)) - .when(!inert, |zone| { - zone.cursor_pointer() - .hover(move |style| style.bg(hover)) - .active(move |style| style.bg(pressed)) - }) - .child( - icon(IconRole::ChevronDown) - .size(self.size.dense_icon_rems()) - .color(foreground), - ) - .child( - canvas( - { - let cell = chevron_bounds.clone(); - move |bounds, _window, _cx| *cell.borrow_mut() = Some(bounds) - }, - |_, _, _, _| {}, - ) - .absolute() - .inset_0(), - ); - let trigger = h_flex() .debug_selector({ let id = self.id.clone(); @@ -380,7 +344,43 @@ impl RenderOnce for DropdownMenu { .child(main); let trigger = if split { - trigger.child(chevron_zone) + trigger.child( + h_flex() + .id((self.id.clone(), "chevron")) + .debug_selector({ + let id = self.id.clone(); + move || format!("{id}-chevron") + }) + .relative() + .h_full() + .control_dense_padding_x(self.size) + .rounded_r(radius) + .rounded_l_none() + .border_l_1() + .border_color(border) + .when(self.open, |zone| zone.bg(pressed)) + .when(!inert, |zone| { + zone.cursor_pointer() + .hover(move |style| style.bg(hover)) + .active(move |style| style.bg(pressed)) + }) + .child( + icon(IconRole::ChevronDown) + .size(self.size.dense_icon_rems()) + .color(foreground), + ) + .child( + canvas( + { + let cell = chevron_bounds.clone(); + move |bounds, _window, _cx| *cell.borrow_mut() = Some(bounds) + }, + |_, _, _, _| {}, + ) + .absolute() + .inset_0(), + ), + ) } else { trigger }; diff --git a/crates/ui/src/components/markdown.rs b/crates/ui/src/components/markdown.rs index 0b94e6f..d617287 100644 --- a/crates/ui/src/components/markdown.rs +++ b/crates/ui/src/components/markdown.rs @@ -1459,35 +1459,42 @@ fn text_row( block_frame(quote, Rems::ZERO, bottom, ctx.block_id, cx).map(|frame| match marker { Some(marker) => { let line_height = rems(1.2); - let marker_cell = div() - .flex_none() - .w(rems(1.75)) - .h(line_height) - .flex() - .items_center() - .justify_end() - .pr_1() - .child(match marker { - ListMarker::Bullet => div() - .size_1() - .rounded(theme.radius.full) - .bg(theme.colors.muted_foreground) - .into_any_element(), - ListMarker::Ordered(number) => div() - .text_color(theme.colors.muted_foreground) - .whitespace_nowrap() - .child(format!("{number}.")) - .into_any_element(), - ListMarker::Task(checked) => task_toggle(checked, item_text(items), ctx), - }); frame.child( - div().flex().items_start().child(marker_cell).child( - div() - .flex_1() - .min_w_0() - .child(paragraph_child(items, ctx, cx)), - ), + div() + .flex() + .items_start() + .child( + div() + .flex_none() + .w(rems(1.75)) + .h(line_height) + .flex() + .items_center() + .justify_end() + .pr_1() + .child(match marker { + ListMarker::Bullet => div() + .size_1() + .rounded(theme.radius.full) + .bg(theme.colors.muted_foreground) + .into_any_element(), + ListMarker::Ordered(number) => div() + .text_color(theme.colors.muted_foreground) + .whitespace_nowrap() + .child(format!("{number}.")) + .into_any_element(), + ListMarker::Task(checked) => { + task_toggle(checked, item_text(items), ctx) + } + }), + ) + .child( + div() + .flex_1() + .min_w_0() + .child(paragraph_child(items, ctx, cx)), + ), ) } None => frame.child(paragraph_child(items, ctx, cx)), @@ -1622,54 +1629,54 @@ fn code_row( .collect::>() .join("\n"); - let actions_row = h_flex() - .justify_between() - .pb_1() - .when_some(language.cloned(), |row, language| { - row.child( - div() - .text_xs() - .text_color(theme.colors.muted_foreground) - .child(language), - ) - }) - .child( - Button::new((ctx.block_id.clone(), "copy-code")) - .label("Copy") - .variant(ButtonVariant::Ghost) - .debug_selector(|| "copy-code".to_string()) - .on_click(move |_, _, cx| { - cx.write_to_clipboard(ClipboardItem::new_string(plain.clone())); - }), - ); - - let plate = v_flex() - .w_full() - .rounded(theme.radius.control) - .bg(theme.colors.muted) - .p_2() - .font_family(theme.mono_font) - .text_xs() - .line_height(relative(CODE_LINE_HEIGHT)) - .overflow_hidden() - .child(actions_row) - .children(lines.lines.iter().enumerate().map(|(line_ix, line)| { - let styled = code_line(line, theme.colors, theme.ramps); - let layout = styled.layout().clone(); - with_selection_handlers( - div() - .h(line_height) - .whitespace_nowrap() - .overflow_hidden() - .child(styled), - ctx.piece_context(line_ix), - layout, - ) - })); - indented_frame( indent, - block_frame(quote, Rems::ZERO, rems(0.75), ctx.block_id, cx).child(plate), + block_frame(quote, Rems::ZERO, rems(0.75), ctx.block_id, cx).child( + v_flex() + .w_full() + .rounded(theme.radius.control) + .bg(theme.colors.muted) + .p_2() + .font_family(theme.mono_font) + .text_xs() + .line_height(relative(CODE_LINE_HEIGHT)) + .overflow_hidden() + .child( + h_flex() + .justify_between() + .pb_1() + .when_some(language.cloned(), |row, language| { + row.child( + div() + .text_xs() + .text_color(theme.colors.muted_foreground) + .child(language), + ) + }) + .child( + Button::new((ctx.block_id.clone(), "copy-code")) + .label("Copy") + .variant(ButtonVariant::Ghost) + .debug_selector(|| "copy-code".to_string()) + .on_click(move |_, _, cx| { + cx.write_to_clipboard(ClipboardItem::new_string(plain.clone())); + }), + ), + ) + .children(lines.lines.iter().enumerate().map(|(line_ix, line)| { + let styled = code_line(line, theme.colors, theme.ramps); + let layout = styled.layout().clone(); + with_selection_handlers( + div() + .h(line_height) + .whitespace_nowrap() + .overflow_hidden() + .child(styled), + ctx.piece_context(line_ix), + layout, + ) + })), + ), ) .into_any_element() } @@ -1702,50 +1709,52 @@ fn table_row( let row_count = table.rows.len(); let mut cell_ix = 0usize; - let grid = v_flex() - .w_full() - .border_1() - .border_color(colors.border) - .rounded(theme.radius.control) - .overflow_hidden() - .children(table.rows.iter().enumerate().map(|(row_index, row)| { - div() - .w_full() - .flex() - .when(row_index + 1 < row_count, |row_element| { - row_element.border_b_1().border_color(colors.border) - }) - .when(row.header, |row_element| row_element.bg(colors.muted)) - .children( - row.cells - .iter() - .enumerate() - .map(|(column_index, cell)| { - let cell_id = ElementId::from(SharedString::from(format!( - "{}-cell-{row_index}-{column_index}", - ctx.block_id - ))); - let piece = ctx.piece_context(cell_ix); - cell_ix += 1; - div() - .flex_1() - .min_w_0() - .px_2() - .py_1() - .when(row.header, |cell_element| cell_element.font_semibold()) - .child(text_child(&cell.spans, &cell_id, piece, cx)) - }) - // Ragged tables pad missing cells so rows align. - .chain( - (row.cells.len()..width) - .map(|_| div().flex_1().min_w_0().px_2().py_1()), - ), - ) - })); - indented_frame( indent, - block_frame(quote, Rems::ZERO, rems(0.75), ctx.block_id, cx).child(grid), + block_frame(quote, Rems::ZERO, rems(0.75), ctx.block_id, cx).child( + v_flex() + .w_full() + .border_1() + .border_color(colors.border) + .rounded(theme.radius.control) + .overflow_hidden() + .children(table.rows.iter().enumerate().map(|(row_index, row)| { + div() + .w_full() + .flex() + .when(row_index + 1 < row_count, |row_element| { + row_element.border_b_1().border_color(colors.border) + }) + .when(row.header, |row_element| row_element.bg(colors.muted)) + .children( + row.cells + .iter() + .enumerate() + .map(|(column_index, cell)| { + let cell_id = ElementId::from(SharedString::from(format!( + "{}-cell-{row_index}-{column_index}", + ctx.block_id + ))); + let piece = ctx.piece_context(cell_ix); + cell_ix += 1; + div() + .flex_1() + .min_w_0() + .px_2() + .py_1() + .when(row.header, |cell_element| { + cell_element.font_semibold() + }) + .child(text_child(&cell.spans, &cell_id, piece, cx)) + }) + // Ragged tables pad missing cells so rows align. + .chain( + (row.cells.len()..width) + .map(|_| div().flex_1().min_w_0().px_2().py_1()), + ), + ) + })), + ), ) .into_any_element() } diff --git a/crates/ui/src/components/popover.rs b/crates/ui/src/components/popover.rs index c6c67af..5bfdcb1 100644 --- a/crates/ui/src/components/popover.rs +++ b/crates/ui/src/components/popover.rs @@ -29,10 +29,10 @@ use gpui::{ StyleRefinement, Styled as _, Window, div, }; +use crate::components::common::{StyledExt as _, floating_panel, v_flex}; use crate::components::menu::{ ChangeHandler, TriggerBoundsCell, anchored_overlay, focus_capture, trigger_toggle, }; -use crate::components::common::{StyledExt as _, floating_panel, v_flex}; use crate::theme::{ActiveTheme as _, POPOVER_MIN_WIDTH}; /// The element the panel anchors below, built during render. @@ -156,56 +156,54 @@ impl RenderOnce for Popover { let focus = crate::components::common::focus_handle(&self.id, window, cx); let content = self.content.map(|content| content(window, cx)); - let panel = floating_panel( - cx, - radius.overlay, - v_flex() - .id("popover-panel") - .debug_selector(|| "popover-panel".to_string()) - .occlude() - .track_focus(&focus) - .role(Role::Dialog) - .aria_label(label) - .min_w(POPOVER_MIN_WIDTH) - .text_color(colors.surface_foreground), - shadows, - ) - .overflow_hidden() - .on_mouse_down_out({ - let on_change = on_change.clone(); - let trigger_bounds = trigger_bounds.clone(); - move |event, window, cx| { - if trigger_bounds - .borrow() - .is_some_and(|bounds| bounds.contains(&event.position)) - { - return; - } - if let Some(on_change) = &on_change { - on_change(false, window, cx); - } - } - }) - .on_key_down({ - let on_change = on_change.clone(); - move |event: &KeyDownEvent, window, cx| { - if event.keystroke.key == "escape" { + wrapper.child(anchored_overlay( + None, + floating_panel( + cx, + radius.overlay, + v_flex() + .id("popover-panel") + .debug_selector(|| "popover-panel".to_string()) + .occlude() + .track_focus(&focus) + .role(Role::Dialog) + .aria_label(label) + .min_w(POPOVER_MIN_WIDTH) + .text_color(colors.surface_foreground), + shadows, + ) + .overflow_hidden() + .on_mouse_down_out({ + let on_change = on_change.clone(); + let trigger_bounds = trigger_bounds.clone(); + move |event, window, cx| { + if trigger_bounds + .borrow() + .is_some_and(|bounds| bounds.contains(&event.position)) + { + return; + } if let Some(on_change) = &on_change { on_change(false, window, cx); } - cx.stop_propagation(); } - } - }) - .when_some(content, |panel, content| panel.child(content)) - .child(focus_capture( - focus.clone(), - move |window, cx| !focus.contains_focused(window, cx), - )); - - wrapper.child(anchored_overlay( - None, - panel.into_any_element(), + }) + .on_key_down({ + let on_change = on_change.clone(); + move |event: &KeyDownEvent, window, cx| { + if event.keystroke.key == "escape" { + if let Some(on_change) = &on_change { + on_change(false, window, cx); + } + cx.stop_propagation(); + } + } + }) + .when_some(content, |panel, content| panel.child(content)) + .child(focus_capture(focus.clone(), move |window, cx| { + !focus.contains_focused(window, cx) + })) + .into_any_element(), Some(("popover-enter", enter_duration)), )) }) diff --git a/crates/ui/src/components/scroll_area.rs b/crates/ui/src/components/scroll_area.rs index f470b1b..80d53f1 100644 --- a/crates/ui/src/components/scroll_area.rs +++ b/crates/ui/src/components/scroll_area.rs @@ -108,31 +108,31 @@ impl RenderOnce for ScrollArea { let mut pane_style = self.style.clone(); pane_style.padding = Default::default(); - let pane = div() - .id(self.id.clone()) - .h_full() - .overflow_hidden() - .when(self.axes != ScrollAxes::Horizontal, |area| { - area.overflow_y_scroll() - }) - .when(self.axes != ScrollAxes::Vertical, |area| { - area.overflow_x_scroll() - }) - .when_some(self.handle.clone(), |area, handle| { - area.track_scroll(&handle) - }) - .when_some(self.a11y_label, |area, label| area.aria_label(label)) - .on_scroll(|_, _, cx| { - // Keep wheel events from scrolling an outer scroll area too. - cx.stop_propagation(); - }) - .refine_style(&pane_style) - .children(self.children); - div() .relative() .refine_style(&self.style) - .child(pane.into_any_element()) + .child( + div() + .id(self.id.clone()) + .h_full() + .overflow_hidden() + .when(self.axes != ScrollAxes::Horizontal, |area| { + area.overflow_y_scroll() + }) + .when(self.axes != ScrollAxes::Vertical, |area| { + area.overflow_x_scroll() + }) + .when_some(self.handle.clone(), |area, handle| { + area.track_scroll(&handle) + }) + .when_some(self.a11y_label, |area, label| area.aria_label(label)) + .on_scroll(|_, _, cx| { + // Keep wheel events from scrolling an outer scroll area too. + cx.stop_propagation(); + }) + .refine_style(&pane_style) + .children(self.children), + ) .when_some(self.handle, |wrapper, handle| { let id = self.id.clone(); diff --git a/crates/ui/src/components/select.rs b/crates/ui/src/components/select.rs index 1bd491f..23d3b31 100644 --- a/crates/ui/src/components/select.rs +++ b/crates/ui/src/components/select.rs @@ -340,7 +340,7 @@ where .collect() }; - let menu = Menu::new(self.id) + Menu::new(self.id) .open(is_open) .on_change({ let open = open.clone(); @@ -353,8 +353,7 @@ where } }) .trigger(trigger) - .items(items); - - menu.when_some(selected_index, |menu, index| menu.initial_selection(index)) + .items(items) + .when_some(selected_index, |menu, index| menu.initial_selection(index)) } } diff --git a/crates/ui/src/components/sidebar.rs b/crates/ui/src/components/sidebar.rs index ec06f45..ae53030 100644 --- a/crates/ui/src/components/sidebar.rs +++ b/crates/ui/src/components/sidebar.rs @@ -439,40 +439,6 @@ impl RenderOnce for Sidebar { }) .collect(); - let body = div() - .id((id.clone(), "list")) - .flex_1() - .min_h_0() - .track_focus(&focus) - .focusable() - .tab_stop(true) - .role(Role::List) - .aria_label(label) - .on_key_down({ - let on_change = on_change.clone(); - move |event: &KeyDownEvent, window, cx| { - if nav_key(&selectable, selected, &event.keystroke.key, |next| { - if let Some(on_change) = &on_change { - on_change(next, window, cx); - } - }) { - cx.stop_propagation(); - } - } - }) - .child( - ScrollArea::new(scroll_area_id) - .handle(scroll.read(cx).clone()) - .h_full() - .child( - v_flex() - .gap_0p5() - .when(padded, |content| content.p_2()) - .children(children), - ), - ) - .into_any_element(); - let theme = cx.theme(); v_flex() @@ -487,7 +453,41 @@ impl RenderOnce for Sidebar { .border_r(BORDER_WIDTH) .border_color(theme.colors.border) }) - .child(body) + .child( + div() + .id((id.clone(), "list")) + .flex_1() + .min_h_0() + .track_focus(&focus) + .focusable() + .tab_stop(true) + .role(Role::List) + .aria_label(label) + .on_key_down({ + let on_change = on_change.clone(); + move |event: &KeyDownEvent, window, cx| { + if nav_key(&selectable, selected, &event.keystroke.key, |next| { + if let Some(on_change) = &on_change { + on_change(next, window, cx); + } + }) { + cx.stop_propagation(); + } + } + }) + .child( + ScrollArea::new(scroll_area_id) + .handle(scroll.read(cx).clone()) + .h_full() + .child( + v_flex() + .gap_0p5() + .when(padded, |content| content.p_2()) + .children(children), + ), + ) + .into_any_element(), + ) .when(material && grain, |sidebar| sidebar.child(grain_overlay())) } } diff --git a/crates/ui/src/components/tabs.rs b/crates/ui/src/components/tabs.rs index cf61bbf..06d3c9d 100644 --- a/crates/ui/src/components/tabs.rs +++ b/crates/ui/src/components/tabs.rs @@ -1274,33 +1274,6 @@ impl RenderOnce for Tabs { return root.children(strip); }; - let container_canvas = canvas( - { - let key = measure_key.clone(); - move |bounds, _, cx| { - cx.default_global::() - .record_container(&key, bounds.size.width); - *root_bounds.borrow_mut() = Some(bounds); - } - }, - |_, _, _, _| {}, - ) - .absolute() - .inset(shadow_bleed); - - let trigger_canvas = canvas( - { - let key = measure_key; - move |bounds, _, cx| { - cx.default_global::() - .record_trigger(&key, bounds.size.width); - } - }, - |_, _, _, _| {}, - ) - .absolute() - .inset_0(); - let control = match popover { Some(popover) => div().flex_none().relative().child(popover), None => div().flex_none().relative().child( @@ -1316,7 +1289,21 @@ impl RenderOnce for Tabs { .overflow_hidden() .p(shadow_bleed) .m(-shadow_bleed) - .child(container_canvas) + .child( + canvas( + { + let key = measure_key.clone(); + move |bounds, _, cx| { + cx.default_global::() + .record_container(&key, bounds.size.width); + *root_bounds.borrow_mut() = Some(bounds); + } + }, + |_, _, _, _| {}, + ) + .absolute() + .inset(shadow_bleed), + ) .child( div() .flex_none() @@ -1325,7 +1312,22 @@ impl RenderOnce for Tabs { .when(self.variant.is_capsule(), |row| row.items_center()) .children(strip), ) - .child(control.child(trigger_canvas)) + .child( + control.child( + canvas( + { + let key = measure_key; + move |bounds, _, cx| { + cx.default_global::() + .record_trigger(&key, bounds.size.width); + } + }, + |_, _, _, _| {}, + ) + .absolute() + .inset_0(), + ), + ) } else if self.overflow_scroll { root.min_w_0() .overflow_x_scroll() @@ -1345,4 +1347,3 @@ impl RenderOnce for Tabs { }) } } - diff --git a/crates/ui/src/layout/resizable.rs b/crates/ui/src/layout/resizable.rs index 6dbd402..55ffa29 100644 --- a/crates/ui/src/layout/resizable.rs +++ b/crates/ui/src/layout/resizable.rs @@ -249,26 +249,6 @@ impl RenderOnce for Resizable { .refine_style(&self.style) .children(self.panes.into_iter().enumerate().flat_map(|(ix, pane)| { let remainder = ix + 1 == pane_count; - let pane_element = div() - .overflow_hidden() - .when(remainder, |pane_element| { - pane_element - .flex_1() - .when(axis == Axis::Vertical, |p| p.min_h(pane.min)) - .when(axis == Axis::Horizontal, |p| p.min_w(pane.min)) - }) - .when(!remainder, |pane_element| { - pane_element - .flex_none() - .when(axis == Axis::Vertical, |p| p.h(sizes[ix]).w_full()) - .when(axis == Axis::Horizontal, |p| p.w(sizes[ix]).h_full()) - }) - .when_some(debug_selector.clone(), |pane_element, selector| { - let prefix = selector(); - pane_element.debug_selector(move || format!("{prefix}-{ix}")) - }) - .child(pane.content) - .into_any_element(); let divider = (!remainder).then(|| { // The positional index is a stable id: panes are append-only, never reordered. @@ -291,7 +271,29 @@ impl RenderOnce for Resizable { .into_any_element() }); - std::iter::once(pane_element).chain(divider) + std::iter::once( + div() + .overflow_hidden() + .when(remainder, |pane_element| { + pane_element + .flex_1() + .when(axis == Axis::Vertical, |p| p.min_h(pane.min)) + .when(axis == Axis::Horizontal, |p| p.min_w(pane.min)) + }) + .when(!remainder, |pane_element| { + pane_element + .flex_none() + .when(axis == Axis::Vertical, |p| p.h(sizes[ix]).w_full()) + .when(axis == Axis::Horizontal, |p| p.w(sizes[ix]).h_full()) + }) + .when_some(debug_selector.clone(), |pane_element, selector| { + let prefix = selector(); + pane_element.debug_selector(move || format!("{prefix}-{ix}")) + }) + .child(pane.content) + .into_any_element(), + ) + .chain(divider) })) .when(pane_count > 0, |group| { group.child(