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);
+4 -3
View File
@@ -213,7 +213,8 @@ 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(
Tabs::new("signed-detail-tabs")
.variant(TabsVariant::Pill) .variant(TabsVariant::Pill)
.overflow_scroll(true) .overflow_scroll(true)
.selected(selected) .selected(selected)
@@ -235,8 +236,8 @@ impl Render for Workspace {
log_dropped(close_weak.update(cx, |workspace, cx| { log_dropped(close_weak.update(cx, |workspace, cx| {
workspace.close_detail_at(index, 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),
+46 -44
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,7 +634,9 @@ where
.map(|bounds| bounds.size.width) .map(|bounds| bounds.size.width)
.unwrap_or(COMBOBOX_WIDTH); .unwrap_or(COMBOBOX_WIDTH);
let panel = floating_panel( wrapper.child(crate::components::menu::anchored_overlay(
None,
floating_panel(
cx, cx,
radius.overlay, radius.overlay,
v_flex() v_flex()
@@ -668,12 +671,14 @@ where
if phase != gpui::DispatchPhase::Bubble { if phase != gpui::DispatchPhase::Bubble {
return; return;
} }
let on_panel = panel_bounds let on_panel =
.borrow() panel_bounds.borrow().is_some_and(|bounds| {
.is_some_and(|bounds| bounds.contains(&event.position)); bounds.contains(&event.position)
let on_wrapper = wrapper_bounds });
.borrow() let on_wrapper =
.is_some_and(|bounds| bounds.contains(&event.position)); wrapper_bounds.borrow().is_some_and(|bounds| {
bounds.contains(&event.position)
});
if on_panel || on_wrapper { if on_panel || on_wrapper {
return; return;
} }
@@ -688,11 +693,8 @@ where
) )
.absolute() .absolute()
.inset_0(), .inset_0(),
); )
.into_any_element(),
wrapper.child(crate::components::menu::anchored_overlay(
None,
panel.into_any_element(),
None, None,
)) ))
}) })
+28 -28
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,7 +459,30 @@ impl Render for CommandPaletteState {
.into_any_element() .into_any_element()
}; };
let panel = floating_panel( deferred(
div()
.absolute()
.inset_0()
.flex()
.justify_center()
.items_start()
.pt(titlebar_height)
.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, cx,
radius.overlay, radius.overlay,
v_flex() v_flex()
@@ -513,31 +536,8 @@ impl Render for CommandPaletteState {
.child(crate::components::menu::focus_capture( .child(crate::components::menu::focus_capture(
query_focus.clone(), query_focus.clone(),
move |window, cx| !query_focus.contains_focused(window, cx), 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()
.inset_0()
.flex()
.justify_center()
.items_start()
.pt(titlebar_height)
.child(scrim)
.child(panel),
) )
.with_priority(DIALOG_LAYER) .with_priority(DIALOG_LAYER)
.into_any_element() .into_any_element()
+24 -24
View File
@@ -324,7 +324,28 @@ impl RenderOnce for DropdownMenu {
}) })
}; };
let chevron_zone = h_flex() let trigger = h_flex()
.debug_selector({
let id = self.id.clone();
move || format!("{id}-trigger")
})
.control_height(self.size)
.when(icon_only, |trigger| trigger.control_width(self.size))
.rounded(radius)
.border_1()
.border_color(border)
.when_some(background, |trigger, background| trigger.bg(background))
.when(self.disabled, |trigger| trigger.opacity(DISABLED_OPACITY))
.when(!inert, |trigger| {
trigger
.track_focus(&focus)
.focus_visible(move |style| style.shadow(focus_ring(ring)))
})
.child(main);
let trigger = if split {
trigger.child(
h_flex()
.id((self.id.clone(), "chevron")) .id((self.id.clone(), "chevron"))
.debug_selector({ .debug_selector({
let id = self.id.clone(); let id = self.id.clone();
@@ -358,29 +379,8 @@ impl RenderOnce for DropdownMenu {
) )
.absolute() .absolute()
.inset_0(), .inset_0(),
); ),
)
let trigger = h_flex()
.debug_selector({
let id = self.id.clone();
move || format!("{id}-trigger")
})
.control_height(self.size)
.when(icon_only, |trigger| trigger.control_width(self.size))
.rounded(radius)
.border_1()
.border_color(border)
.when_some(background, |trigger, background| trigger.bg(background))
.when(self.disabled, |trigger| trigger.opacity(DISABLED_OPACITY))
.when(!inert, |trigger| {
trigger
.track_focus(&focus)
.focus_visible(move |style| style.shadow(focus_ring(ring)))
})
.child(main);
let trigger = if split {
trigger.child(chevron_zone)
} else { } else {
trigger trigger
}; };
+40 -31
View File
@@ -1459,7 +1459,13 @@ 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()
frame.child(
div()
.flex()
.items_start()
.child(
div()
.flex_none() .flex_none()
.w(rems(1.75)) .w(rems(1.75))
.h(line_height) .h(line_height)
@@ -1478,11 +1484,12 @@ fn text_row(
.whitespace_nowrap() .whitespace_nowrap()
.child(format!("{number}.")) .child(format!("{number}."))
.into_any_element(), .into_any_element(),
ListMarker::Task(checked) => task_toggle(checked, item_text(items), ctx), ListMarker::Task(checked) => {
}); task_toggle(checked, item_text(items), ctx)
}
frame.child( }),
div().flex().items_start().child(marker_cell).child( )
.child(
div() div()
.flex_1() .flex_1()
.min_w_0() .min_w_0()
@@ -1622,7 +1629,20 @@ fn code_row(
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join("\n"); .join("\n");
let actions_row = h_flex() indented_frame(
indent,
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() .justify_between()
.pb_1() .pb_1()
.when_some(language.cloned(), |row, language| { .when_some(language.cloned(), |row, language| {
@@ -1641,18 +1661,8 @@ fn code_row(
.on_click(move |_, _, cx| { .on_click(move |_, _, cx| {
cx.write_to_clipboard(ClipboardItem::new_string(plain.clone())); 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)| { .children(lines.lines.iter().enumerate().map(|(line_ix, line)| {
let styled = code_line(line, theme.colors, theme.ramps); let styled = code_line(line, theme.colors, theme.ramps);
let layout = styled.layout().clone(); let layout = styled.layout().clone();
@@ -1665,11 +1675,8 @@ fn code_row(
ctx.piece_context(line_ix), ctx.piece_context(line_ix),
layout, layout,
) )
})); })),
),
indented_frame(
indent,
block_frame(quote, Rems::ZERO, rems(0.75), ctx.block_id, cx).child(plate),
) )
.into_any_element() .into_any_element()
} }
@@ -1702,7 +1709,10 @@ 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() indented_frame(
indent,
block_frame(quote, Rems::ZERO, rems(0.75), ctx.block_id, cx).child(
v_flex()
.w_full() .w_full()
.border_1() .border_1()
.border_color(colors.border) .border_color(colors.border)
@@ -1732,7 +1742,9 @@ fn table_row(
.min_w_0() .min_w_0()
.px_2() .px_2()
.py_1() .py_1()
.when(row.header, |cell_element| cell_element.font_semibold()) .when(row.header, |cell_element| {
cell_element.font_semibold()
})
.child(text_child(&cell.spans, &cell_id, piece, cx)) .child(text_child(&cell.spans, &cell_id, piece, cx))
}) })
// Ragged tables pad missing cells so rows align. // Ragged tables pad missing cells so rows align.
@@ -1741,11 +1753,8 @@ fn table_row(
.map(|_| div().flex_1().min_w_0().px_2().py_1()), .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),
) )
.into_any_element() .into_any_element()
} }
+8 -10
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,7 +156,9 @@ 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(
None,
floating_panel(
cx, cx,
radius.overlay, radius.overlay,
v_flex() v_flex()
@@ -198,14 +200,10 @@ impl RenderOnce for Popover {
} }
}) })
.when_some(content, |panel, content| panel.child(content)) .when_some(content, |panel, content| panel.child(content))
.child(focus_capture( .child(focus_capture(focus.clone(), move |window, cx| {
focus.clone(), !focus.contains_focused(window, cx)
move |window, cx| !focus.contains_focused(window, cx), }))
)); .into_any_element(),
wrapper.child(anchored_overlay(
None,
panel.into_any_element(),
Some(("popover-enter", enter_duration)), Some(("popover-enter", enter_duration)),
)) ))
}) })
+7 -7
View File
@@ -108,7 +108,11 @@ 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() div()
.relative()
.refine_style(&self.style)
.child(
div()
.id(self.id.clone()) .id(self.id.clone())
.h_full() .h_full()
.overflow_hidden() .overflow_hidden()
@@ -127,12 +131,8 @@ impl RenderOnce for ScrollArea {
cx.stop_propagation(); cx.stop_propagation();
}) })
.refine_style(&pane_style) .refine_style(&pane_style)
.children(self.children); .children(self.children),
)
div()
.relative()
.refine_style(&self.style)
.child(pane.into_any_element())
.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))
} }
} }
+18 -18
View File
@@ -439,7 +439,22 @@ impl RenderOnce for Sidebar {
}) })
.collect(); .collect();
let body = div() let theme = cx.theme();
v_flex()
.id(id.clone())
.refine_style(&style)
.debug_selector(move || format!("sidebar-{debug_id}"))
.h_full()
.w(width)
.text_sm()
.when(border_right, |sidebar| {
sidebar
.border_r(BORDER_WIDTH)
.border_color(theme.colors.border)
})
.child(
div()
.id((id.clone(), "list")) .id((id.clone(), "list"))
.flex_1() .flex_1()
.min_h_0() .min_h_0()
@@ -471,23 +486,8 @@ impl RenderOnce for Sidebar {
.children(children), .children(children),
), ),
) )
.into_any_element(); .into_any_element(),
)
let theme = cx.theme();
v_flex()
.id(id.clone())
.refine_style(&style)
.debug_selector(move || format!("sidebar-{debug_id}"))
.h_full()
.w(width)
.text_sm()
.when(border_right, |sidebar| {
sidebar
.border_r(BORDER_WIDTH)
.border_color(theme.colors.border)
})
.child(body)
.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(