refactor: inline intermediate element builders in render methods
Rust / build (macos-latest, stable) (push) Waiting to run
Rust / build (ubuntu-latest, stable) (push) Waiting to run
Rust / build (windows-latest, stable) (push) Waiting to run

This commit is contained in:
2026-11-22 18:42:59 +07:00
parent 9daee9d54d
commit 967273c402
14 changed files with 560 additions and 550 deletions
+11 -14
View File
@@ -119,18 +119,6 @@ impl Render for AppRoot {
let workspace = self.workspace.read(cx); let workspace = self.workspace.read(cx);
let main = workspace.active_main(); 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() div()
.relative() .relative()
.size_full() .size_full()
@@ -151,8 +139,17 @@ impl Render for AppRoot {
Shell::new("signed-shell") Shell::new("signed-shell")
.titlebar( .titlebar(
Titlebar::new("signed-titlebar") Titlebar::new("signed-titlebar")
.prefix(prefix) .prefix(
.tab_bar(tab_bar) 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| { .when_some(titlebar_view.render_user_menu(cx), |titlebar, menu| {
titlebar.suffix(menu) titlebar.suffix(menu)
}), }),
@@ -165,12 +165,6 @@ impl Render for RepositorySwitcher {
let list_weak = row_weak.clone(); let list_weak = row_weak.clone();
let list_on_open = on_open.clone(); let list_on_open = on_open.clone();
let list_scroll_handle = scroll_handle.clone(); let list_scroll_handle = scroll_handle.clone();
let create_hint = Kbd::binding_for_action(
&CreateRepository,
Some(REPOSITORY_KEY_CONTEXT),
window,
);
v_flex() v_flex()
.w(px(380.)) .w(px(380.))
.p_2() .p_2()
@@ -265,7 +259,14 @@ impl Render for RepositorySwitcher {
.full_width(true) .full_width(true)
.icon(Icon::named(IconRole::CirclePlus)) .icon(Icon::named(IconRole::CirclePlus))
.child(div().flex_1().child("Create Repository")) .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| { .on_click(move |_, window, cx| {
log_dropped(create_weak.update(cx, |this, cx| { log_dropped(create_weak.update(cx, |this, cx| {
this.close(cx); this.close(cx);
+25 -24
View File
@@ -213,30 +213,31 @@ impl Render for Workspace {
.gap_2() .gap_2()
.when(self.details.len() > 1, |this| { .when(self.details.len() > 1, |this| {
let close_weak = weak.clone(); let close_weak = weak.clone();
let tabs = Tabs::new("signed-detail-tabs") this.child(
.variant(TabsVariant::Pill) Tabs::new("signed-detail-tabs")
.overflow_scroll(true) .variant(TabsVariant::Pill)
.selected(selected) .overflow_scroll(true)
.tabs(move |_, cx| { .selected(selected)
details .tabs(move |_, cx| {
.iter() details
.map(|(id, view)| match view { .iter()
Some(view) => view.tab(id.clone().into(), cx).closeable(true), .map(|(id, view)| match view {
None => Tab::new(id.clone(), id.clone()).closeable(true), Some(view) => view.tab(id.clone().into(), cx).closeable(true),
}) None => Tab::new(id.clone(), id.clone()).closeable(true),
.collect() })
}) .collect()
.on_change(move |index, _, cx| { })
log_dropped(weak.update(cx, |workspace, cx| { .on_change(move |index, _, cx| {
workspace.activate_detail_at(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| { .on_close(move |index, _, cx| {
workspace.close_detail_at(index, cx); log_dropped(close_weak.update(cx, |workspace, cx| {
})); workspace.close_detail_at(index, cx);
}); }));
this.child(tabs) }),
)
}) })
.child(div().flex_1().min_h_0().w_full().children(body)) .child(div().flex_1().min_h_0().w_full().children(body))
} }
+31 -31
View File
@@ -437,36 +437,6 @@ impl Render for CodeViewState {
let bounds_cell: std::rc::Rc<std::cell::RefCell<Option<Bounds<Pixels>>>> = let bounds_cell: std::rc::Rc<std::cell::RefCell<Option<Bounds<Pixels>>>> =
std::rc::Rc::new(std::cell::RefCell::new(None)); 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() div()
.id((id.clone(), "view")) .id((id.clone(), "view"))
.relative() .relative()
@@ -596,7 +566,37 @@ impl Render for CodeViewState {
.absolute() .absolute()
.inset_0(), .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( .child(
Scrollbar::vertical((self.id.clone(), "v-scrollbar"), self.handle.clone()) Scrollbar::vertical((self.id.clone(), "v-scrollbar"), self.handle.clone())
.visibility(ScrollbarVisibility::Platform), .visibility(ScrollbarVisibility::Platform),
+92 -90
View File
@@ -428,37 +428,6 @@ where
let state = cx.entity(); let state = cx.entity();
let open = self.highlight.is_some(); 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<RefCell<Option<Bounds<Pixels>>>> = Rc::new(RefCell::new(None)); let wrapper_bounds: Rc<RefCell<Option<Bounds<Pixels>>>> = Rc::new(RefCell::new(None));
div() div()
@@ -525,7 +494,39 @@ where
.top_0() .top_0()
.bottom_0() .bottom_0()
.items_center() .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| { .when(open, |wrapper| {
let visible = self.visible.clone(); let visible = self.visible.clone();
@@ -633,66 +634,67 @@ where
.map(|bounds| bounds.size.width) .map(|bounds| bounds.size.width)
.unwrap_or(COMBOBOX_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( wrapper.child(crate::components::menu::anchored_overlay(
None, 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, None,
)) ))
}) })
+73 -73
View File
@@ -30,8 +30,8 @@ use gpui::prelude::FluentBuilder;
use gpui::{ use gpui::{
AnyElement, App, Context, ElementId, Entity, InteractiveElement as _, IntoElement, KeyBinding, AnyElement, App, Context, ElementId, Entity, InteractiveElement as _, IntoElement, KeyBinding,
MouseButton, ParentElement as _, Render, Role, SharedString, StatefulInteractiveElement as _, MouseButton, ParentElement as _, Render, Role, SharedString, StatefulInteractiveElement as _,
StyleRefinement, Styled as _, Subscription, UniformListScrollHandle, Window, actions, StyleRefinement, Styled as _, Subscription, UniformListScrollHandle, Window, actions, deferred,
deferred, div, relative, rems, uniform_list, div, relative, rems, uniform_list,
}; };
use crate::components::common::{ use crate::components::common::{
@@ -459,75 +459,6 @@ impl Render for CommandPaletteState {
.into_any_element() .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( deferred(
div() div()
.absolute() .absolute()
@@ -536,8 +467,77 @@ impl Render for CommandPaletteState {
.justify_center() .justify_center()
.items_start() .items_start()
.pt(titlebar_height) .pt(titlebar_height)
.child(scrim) .child(
.child(panel), 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) .with_priority(DIALOG_LAYER)
.into_any_element() .into_any_element()
+37 -37
View File
@@ -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() let trigger = h_flex()
.debug_selector({ .debug_selector({
let id = self.id.clone(); let id = self.id.clone();
@@ -380,7 +344,43 @@ impl RenderOnce for DropdownMenu {
.child(main); .child(main);
let trigger = if split { 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 { } else {
trigger trigger
}; };
+124 -115
View File
@@ -1459,35 +1459,42 @@ fn text_row(
block_frame(quote, Rems::ZERO, bottom, ctx.block_id, cx).map(|frame| match marker { block_frame(quote, Rems::ZERO, bottom, ctx.block_id, cx).map(|frame| match marker {
Some(marker) => { Some(marker) => {
let line_height = rems(1.2); 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( frame.child(
div().flex().items_start().child(marker_cell).child( div()
div() .flex()
.flex_1() .items_start()
.min_w_0() .child(
.child(paragraph_child(items, ctx, cx)), 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)), None => frame.child(paragraph_child(items, ctx, cx)),
@@ -1622,54 +1629,54 @@ fn code_row(
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join("\n"); .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( indented_frame(
indent, 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() .into_any_element()
} }
@@ -1702,50 +1709,52 @@ fn table_row(
let row_count = table.rows.len(); let row_count = table.rows.len();
let mut cell_ix = 0usize; 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( indented_frame(
indent, 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() .into_any_element()
} }
+45 -47
View File
@@ -29,10 +29,10 @@ use gpui::{
StyleRefinement, Styled as _, Window, div, StyleRefinement, Styled as _, Window, div,
}; };
use crate::components::common::{StyledExt as _, floating_panel, v_flex};
use crate::components::menu::{ use crate::components::menu::{
ChangeHandler, TriggerBoundsCell, anchored_overlay, focus_capture, trigger_toggle, 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}; use crate::theme::{ActiveTheme as _, POPOVER_MIN_WIDTH};
/// The element the panel anchors below, built during render. /// 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 focus = crate::components::common::focus_handle(&self.id, window, cx);
let content = self.content.map(|content| content(window, cx)); let content = self.content.map(|content| content(window, cx));
let panel = floating_panel( wrapper.child(anchored_overlay(
cx, None,
radius.overlay, floating_panel(
v_flex() cx,
.id("popover-panel") radius.overlay,
.debug_selector(|| "popover-panel".to_string()) v_flex()
.occlude() .id("popover-panel")
.track_focus(&focus) .debug_selector(|| "popover-panel".to_string())
.role(Role::Dialog) .occlude()
.aria_label(label) .track_focus(&focus)
.min_w(POPOVER_MIN_WIDTH) .role(Role::Dialog)
.text_color(colors.surface_foreground), .aria_label(label)
shadows, .min_w(POPOVER_MIN_WIDTH)
) .text_color(colors.surface_foreground),
.overflow_hidden() shadows,
.on_mouse_down_out({ )
let on_change = on_change.clone(); .overflow_hidden()
let trigger_bounds = trigger_bounds.clone(); .on_mouse_down_out({
move |event, window, cx| { let on_change = on_change.clone();
if trigger_bounds let trigger_bounds = trigger_bounds.clone();
.borrow() move |event, window, cx| {
.is_some_and(|bounds| bounds.contains(&event.position)) if trigger_bounds
{ .borrow()
return; .is_some_and(|bounds| bounds.contains(&event.position))
} {
if let Some(on_change) = &on_change { return;
on_change(false, window, cx); }
}
}
})
.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 { if let Some(on_change) = &on_change {
on_change(false, window, cx); on_change(false, window, cx);
} }
cx.stop_propagation();
} }
} })
}) .on_key_down({
.when_some(content, |panel, content| panel.child(content)) let on_change = on_change.clone();
.child(focus_capture( move |event: &KeyDownEvent, window, cx| {
focus.clone(), if event.keystroke.key == "escape" {
move |window, cx| !focus.contains_focused(window, cx), if let Some(on_change) = &on_change {
)); on_change(false, window, cx);
}
wrapper.child(anchored_overlay( cx.stop_propagation();
None, }
panel.into_any_element(), }
})
.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)), Some(("popover-enter", enter_duration)),
)) ))
}) })
+22 -22
View File
@@ -108,31 +108,31 @@ impl RenderOnce for ScrollArea {
let mut pane_style = self.style.clone(); let mut pane_style = self.style.clone();
pane_style.padding = Default::default(); 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() div()
.relative() .relative()
.refine_style(&self.style) .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| { .when_some(self.handle, |wrapper, handle| {
let id = self.id.clone(); let id = self.id.clone();
+3 -4
View File
@@ -340,7 +340,7 @@ where
.collect() .collect()
}; };
let menu = Menu::new(self.id) Menu::new(self.id)
.open(is_open) .open(is_open)
.on_change({ .on_change({
let open = open.clone(); let open = open.clone();
@@ -353,8 +353,7 @@ where
} }
}) })
.trigger(trigger) .trigger(trigger)
.items(items); .items(items)
.when_some(selected_index, |menu, index| menu.initial_selection(index))
menu.when_some(selected_index, |menu, index| menu.initial_selection(index))
} }
} }
+35 -35
View File
@@ -439,40 +439,6 @@ impl RenderOnce for Sidebar {
}) })
.collect(); .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(); let theme = cx.theme();
v_flex() v_flex()
@@ -487,7 +453,41 @@ impl RenderOnce for Sidebar {
.border_r(BORDER_WIDTH) .border_r(BORDER_WIDTH)
.border_color(theme.colors.border) .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())) .when(material && grain, |sidebar| sidebar.child(grain_overlay()))
} }
} }
+31 -30
View File
@@ -1274,33 +1274,6 @@ impl RenderOnce for Tabs {
return root.children(strip); return root.children(strip);
}; };
let container_canvas = canvas(
{
let key = measure_key.clone();
move |bounds, _, cx| {
cx.default_global::<TabsMeasurements>()
.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::<TabsMeasurements>()
.record_trigger(&key, bounds.size.width);
}
},
|_, _, _, _| {},
)
.absolute()
.inset_0();
let control = match popover { let control = match popover {
Some(popover) => div().flex_none().relative().child(popover), Some(popover) => div().flex_none().relative().child(popover),
None => div().flex_none().relative().child( None => div().flex_none().relative().child(
@@ -1316,7 +1289,21 @@ impl RenderOnce for Tabs {
.overflow_hidden() .overflow_hidden()
.p(shadow_bleed) .p(shadow_bleed)
.m(-shadow_bleed) .m(-shadow_bleed)
.child(container_canvas) .child(
canvas(
{
let key = measure_key.clone();
move |bounds, _, cx| {
cx.default_global::<TabsMeasurements>()
.record_container(&key, bounds.size.width);
*root_bounds.borrow_mut() = Some(bounds);
}
},
|_, _, _, _| {},
)
.absolute()
.inset(shadow_bleed),
)
.child( .child(
div() div()
.flex_none() .flex_none()
@@ -1325,7 +1312,22 @@ impl RenderOnce for Tabs {
.when(self.variant.is_capsule(), |row| row.items_center()) .when(self.variant.is_capsule(), |row| row.items_center())
.children(strip), .children(strip),
) )
.child(control.child(trigger_canvas)) .child(
control.child(
canvas(
{
let key = measure_key;
move |bounds, _, cx| {
cx.default_global::<TabsMeasurements>()
.record_trigger(&key, bounds.size.width);
}
},
|_, _, _, _| {},
)
.absolute()
.inset_0(),
),
)
} else if self.overflow_scroll { } else if self.overflow_scroll {
root.min_w_0() root.min_w_0()
.overflow_x_scroll() .overflow_x_scroll()
@@ -1345,4 +1347,3 @@ impl RenderOnce for Tabs {
}) })
} }
} }
+23 -21
View File
@@ -249,26 +249,6 @@ impl RenderOnce for Resizable {
.refine_style(&self.style) .refine_style(&self.style)
.children(self.panes.into_iter().enumerate().flat_map(|(ix, pane)| { .children(self.panes.into_iter().enumerate().flat_map(|(ix, pane)| {
let remainder = ix + 1 == pane_count; 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(|| { let divider = (!remainder).then(|| {
// The positional index is a stable id: panes are append-only, never reordered. // The positional index is a stable id: panes are append-only, never reordered.
@@ -291,7 +271,29 @@ impl RenderOnce for Resizable {
.into_any_element() .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| { .when(pane_count > 0, |group| {
group.child( group.child(