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
+31 -31
View File
@@ -437,36 +437,6 @@ impl Render for CodeViewState {
let bounds_cell: std::rc::Rc<std::cell::RefCell<Option<Bounds<Pixels>>>> =
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),
+92 -90
View File
@@ -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<RefCell<Option<Bounds<Pixels>>>> = 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,
))
})
+73 -73
View File
@@ -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()
+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()
.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
};
+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 {
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::<Vec<_>>()
.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()
}
+45 -47
View File
@@ -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)),
))
})
+22 -22
View File
@@ -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();
+3 -4
View File
@@ -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))
}
}
+35 -35
View File
@@ -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()))
}
}
+31 -30
View File
@@ -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::<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 {
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::<TabsMeasurements>()
.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::<TabsMeasurements>()
.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 {
})
}
}