Make method chaining for flex_grow() and flex_shrink().

This commit is contained in:
DESKTOP-QJ11IGB\bowen 2026-05-30 23:28:41 +08:00
parent e2e7a6769e
commit f00358a391
37 changed files with 80 additions and 65 deletions

View file

@ -767,7 +767,7 @@ impl Render for AcpTools {
} else {
div()
.size_full()
.flex_grow()
.flex_grow_1()
.child(
list(
connection.list_state.clone(),

View file

@ -4948,7 +4948,7 @@ impl AgentPanel {
h_flex()
.key_context("TitleEditor")
.group("title_editor")
.flex_grow()
.flex_grow_1()
.w_full()
.min_w_0()
.max_w_full()

View file

@ -650,7 +650,7 @@ impl Render for AgentRegistryPage {
let scroll_handle = &self.list;
this.child(
uniform_list("registry-entries", count, cx.processor(Self::render_agents))
.flex_grow()
.flex_grow_1()
.pb_4()
.track_scroll(scroll_handle),
)

View file

@ -2624,7 +2624,7 @@ impl ThreadView {
v_flex()
.when_some(max_content_width, |this, max_w| this.flex_basis(max_w))
.when(max_content_width.is_none(), |this| this.w_full())
.flex_shrink()
.flex_shrink_1()
.flex_grow_0()
.max_w_full()
.bg(self.activity_bar_bg(cx))
@ -3726,7 +3726,7 @@ impl ThreadView {
.when_some(max_content_width, |this, max_w| this.flex_basis(max_w))
.when(max_content_width.is_none(), |this| this.w_full())
.when(fills_container, |this| this.h_full())
.flex_shrink()
.flex_shrink_1()
.flex_grow_0()
.justify_between()
.gap_2()
@ -5100,7 +5100,7 @@ impl ThreadView {
}),
)
.with_sizing_behavior(gpui::ListSizingBehavior::Auto)
.flex_grow()
.flex_grow_1()
}
fn render_entry(

View file

@ -1580,7 +1580,7 @@ impl PickerDelegate for ProjectPickerDelegate {
.child(
h_flex()
.gap_3()
.flex_grow()
.flex_grow_1()
.child(highlighted_match.render(window, cx)),
)
.tooltip(Tooltip::text(tooltip_path))

View file

@ -49,7 +49,7 @@ impl Render for Breadcrumbs {
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let element = h_flex()
.id("breadcrumb-container")
.flex_grow()
.flex_grow_1()
.h_8()
.overflow_x_scroll()
.text_ui(cx);

View file

@ -520,7 +520,7 @@ impl ComponentPreview {
}
}),
)
.flex_grow()
.flex_grow_1()
.with_sizing_behavior(gpui::ListSizingBehavior::Auto)
.into_any_element()
},

View file

@ -1574,7 +1574,7 @@ impl Render for VariableList {
.with_horizontal_sizing_behavior(gpui::ListHorizontalSizingBehavior::Unconstrained)
.gap_1_5()
.size_full()
.flex_grow(),
.flex_grow_1(),
)
.children(self.open_context_menu.as_ref().map(|(menu, position, _)| {
deferred(

View file

@ -6655,7 +6655,7 @@ pub fn render_breadcrumb_text(
) -> gpui::AnyElement {
const MAX_SEGMENTS: usize = 12;
let element = h_flex().flex_grow().text_ui(cx);
let element = h_flex().flex_grow_1().text_ui(cx);
let prefix_end_ix = cmp::min(segments.len(), MAX_SEGMENTS / 2);
let suffix_start_ix = cmp::max(

View file

@ -210,7 +210,7 @@ impl RenderOnce for SplitEditorView {
.child(
div()
.id("split-editor-left")
.flex_shrink()
.flex_shrink_1()
.min_w_0()
.h_full()
.flex_basis(DefiniteLength::Fraction(left_ratio))
@ -221,7 +221,7 @@ impl RenderOnce for SplitEditorView {
.child(
div()
.id("split-editor-right")
.flex_shrink()
.flex_shrink_1()
.min_w_0()
.h_full()
.flex_basis(DefiniteLength::Fraction(right_ratio))

View file

@ -1772,7 +1772,7 @@ impl Render for ExtensionsPage {
let scroll_handle = &self.list;
this.child(
uniform_list("entries", count, cx.processor(Self::render_extensions))
.flex_grow()
.flex_grow_1()
.pb_4()
.track_scroll(scroll_handle),
)

View file

@ -1526,7 +1526,7 @@ impl PickerDelegate for BranchListDelegate {
h_flex()
.w_full()
.gap_2p5()
.flex_grow()
.flex_grow_1()
.child(
Icon::new(entry_icon)
.color(if is_checked_branch {

View file

@ -419,11 +419,11 @@ impl CommitModal {
.child(
h_flex()
.gap_1()
.flex_shrink()
.flex_shrink_1()
.overflow_x_hidden()
.child(
h_flex()
.flex_shrink()
.flex_shrink_1()
.overflow_x_hidden()
.child(branch_picker),
)

View file

@ -1113,7 +1113,7 @@ impl Render for CommitView {
.bg(cx.theme().colors().editor_background)
.child(self.render_header(window, cx))
.when(!self.editor.read(cx).is_empty(cx), |this| {
this.child(div().flex_grow().child(self.editor.clone()))
this.child(div().flex_grow_1().child(self.editor.clone()))
})
}
}

View file

@ -4876,7 +4876,7 @@ impl GitPanel {
.border_color(cx.theme().colors().border.opacity(0.8))
.child(
div()
.flex_grow()
.flex_grow_1()
.overflow_hidden()
.max_w(relative(0.85))
.child(
@ -5792,7 +5792,7 @@ impl GitPanel {
})
.group("entries")
.size_full()
.flex_grow()
.flex_grow_1()
.with_width_from_item(self.max_width_item_index)
.track_scroll(&self.scroll_handle),
)

View file

@ -200,6 +200,7 @@ pub trait Styled: Sized {
fn flex_none(mut self) -> Self {
self.style().flex_grow = Some(0.);
self.style().flex_shrink = Some(0.);
self.style().flex_basis = Some(Length::Auto);
self
}
@ -210,34 +211,48 @@ pub trait Styled: Sized {
self
}
/// Sets the element to allow a flex item to grow to fill any available space.
/// Sets the flex item's grow factor.
/// [Docs](https://tailwindcss.com/docs/flex-grow)
fn flex_grow(mut self) -> Self {
self.style().flex_grow = Some(1.);
fn flex_grow(mut self, grow: f32) -> Self {
self.style().flex_grow = Some(grow);
self
}
/// Sets the element to prevent a flex item from growing.
/// Disables flex item growth (flex-grow: 0).
/// [Docs](https://tailwindcss.com/docs/flex-grow#dont-grow)
fn flex_grow_0(mut self) -> Self {
self.style().flex_grow = Some(0.);
self
}
/// Sets the element to allow a flex item to shrink if needed.
/// [Docs](https://tailwindcss.com/docs/flex-shrink)
fn flex_shrink(mut self) -> Self {
self.style().flex_shrink = Some(1.);
/// Enables flex item growth (flex-grow: 1).
/// [Docs](https://tailwindcss.com/docs/flex-grow#grow-1)
fn flex_grow_1(mut self) -> Self {
self.style().flex_grow = Some(1.);
self
}
/// Sets the element to prevent a flex item from shrinking.
/// Sets the flex item's shrink factor.
/// [Docs](https://tailwindcss.com/docs/flex-shrink)
fn flex_shrink(mut self, shrink: f32) -> Self {
self.style().flex_shrink = Some(shrink);
self
}
/// Disables flex item shrinking (flex-shrink: 0).
/// [Docs](https://tailwindcss.com/docs/flex-shrink#dont-shrink)
fn flex_shrink_0(mut self) -> Self {
self.style().flex_shrink = Some(0.);
self
}
/// Enables flex item shrinking (flex-shrink: 1).
/// [Docs](https://tailwindcss.com/docs/flex-shrink#shrink-1)
fn flex_shrink_1(mut self) -> Self {
self.style().flex_shrink = Some(1.);
self
}
/// Sets the element to allow flex items to wrap.
/// [Docs](https://tailwindcss.com/docs/flex-wrap#wrap-normally)
fn flex_wrap(mut self) -> Self {

View file

@ -3468,7 +3468,7 @@ impl Render for ActionArgumentsEditor {
.min_h_8()
.min_w_48()
.px_2()
.flex_grow()
.flex_grow_1()
.rounded_md()
.bg(cx.theme().colors().editor_background)
.border_1()

View file

@ -350,7 +350,7 @@ impl Render for LivekitWindow {
.overflow_y_scroll()
.flex()
.flex_col()
.flex_grow()
.flex_grow_1()
.children(self.remote_participants.iter().map(|(identity, state)| {
div()
.h(px(1080.0))

View file

@ -4786,9 +4786,9 @@ impl OutlinePanel {
};
v_flex()
.flex_shrink()
.flex_shrink_1()
.size_full()
.child(list_contents.size_full().flex_shrink())
.child(list_contents.size_full().flex_shrink_1())
.custom_scrollbars(
Scrollbars::for_settings::<OutlinePanelSettingsScrollbarProxy>()
.tracked_scroll_handle(&self.scroll_handle.clone())

View file

@ -881,7 +881,7 @@ impl<D: PickerDelegate> Picker<D> {
.when_some(self.widest_item, |el, widest_item| {
el.with_width_from_item(Some(widest_item))
})
.flex_grow()
.flex_grow_1()
.py(DynamicSpacing::Base04.rems(cx))
.track_scroll(&scroll_handle)
.into_any_element(),
@ -892,7 +892,7 @@ impl<D: PickerDelegate> Picker<D> {
}),
)
.with_sizing_behavior(sizing_behavior)
.flex_grow()
.flex_grow_1()
.py(DynamicSpacing::Base04.rems(cx))
.into_any_element(),
}
@ -1140,7 +1140,7 @@ impl<D: PickerDelegate> Render for Picker<D> {
v_flex()
.id("element-container")
.relative()
.flex_grow()
.flex_grow_1()
.when_some(self.max_height, |div, max_h| div.max_h(max_h))
.overflow_hidden()
.children(self.delegate.render_header(window, cx))
@ -1167,7 +1167,7 @@ impl<D: PickerDelegate> Render for Picker<D> {
el.when_some(self.delegate.no_matches_text(window, cx), |el, text| {
el.child(
v_flex()
.flex_grow()
.flex_grow_1()
.py(DynamicSpacing::Base04.rems(cx))
.child(
ListItem::new("empty_state")

View file

@ -6932,7 +6932,7 @@ impl Render for ProjectPanel {
div()
.id("project-panel-blank-area")
.block_mouse_except_scroll()
.flex_grow()
.flex_grow_1()
.on_scroll_wheel({
let scroll_handle = self.scroll_handle.clone();
let entity_id = cx.entity().entity_id();

View file

@ -1561,7 +1561,7 @@ impl PickerDelegate for RecentProjectsDelegate {
h_flex()
.id("project_info_container")
.gap_2p5()
.flex_grow()
.flex_grow_1()
.when(self.has_any_non_local_projects, |this| {
this.child(Icon::new(icon).color(Color::Muted))
})

View file

@ -369,7 +369,7 @@ impl PickerDelegate for SidebarRecentProjectsDelegate {
.child(
h_flex()
.gap_3()
.flex_grow()
.flex_grow_1()
.when(self.has_any_non_local_projects, |this| {
this.child(Icon::new(icon).color(Color::Muted))
})

View file

@ -172,7 +172,7 @@ impl picker::PickerDelegate for WslPickerDelegate {
.spacing(ui::ListItemSpacing::Sparse)
.child(
h_flex()
.flex_grow()
.flex_grow_1()
.gap_3()
.child(Icon::new(IconName::Linux))
.child(v_flex().child(HighlightedLabel::new(

View file

@ -362,7 +362,7 @@ impl PickerDelegate for KernelPickerDelegate {
.child(icon.color(Color::Default).size(IconSize::Medium))
.child(
v_flex()
.flex_grow()
.flex_grow_1()
.overflow_x_hidden()
.gap_0p5()
.child(
@ -371,7 +371,7 @@ impl PickerDelegate for KernelPickerDelegate {
.child(
div()
.overflow_x_hidden()
.flex_shrink()
.flex_shrink_1()
.text_ellipsis()
.child(
Label::new(spec.name())

View file

@ -2199,7 +2199,7 @@ impl Render for ProjectSearchBar {
let input_base_styles = |panel: InputPanel| {
input_base_styles(search.border_color_for(panel, cx), |div| match panel {
InputPanel::Query | InputPanel::Replacement => div.w(input_width),
InputPanel::Include | InputPanel::Exclude => div.flex_grow(),
InputPanel::Include | InputPanel::Exclude => div.flex_grow_1(),
})
};
let theme_colors = cx.theme().colors();

View file

@ -898,7 +898,7 @@ impl SkillCreator {
// than squeezing the body editor below its minimum height.
v_flex()
.id("skill-creator-form-fields")
.flex_grow()
.flex_grow_1()
.flex_shrink_0()
.gap_4()
.child(
@ -914,7 +914,7 @@ impl SkillCreator {
.child(Divider::horizontal())
.child(
v_flex()
.flex_grow()
.flex_grow_1()
.flex_shrink_0()
.gap_2()
.child(Label::new("Skill Content"))

View file

@ -1378,7 +1378,7 @@ impl Item for TerminalView {
v_flex()
.gap_1()
.child(Label::new(title.clone()))
.child(h_flex().flex_grow().child(Divider::horizontal()))
.child(h_flex().flex_grow_1().child(Divider::horizontal()))
.child(
Label::new(format!("Process ID (PID): {}", pid))
.color(Color::Muted)

View file

@ -76,7 +76,7 @@ impl RenderOnce for SplitButton {
.when(self.style == SplitButtonStyle::Transparent, |this| {
this.gap_px()
})
.child(div().flex_grow().child(match self.left {
.child(div().flex_grow_1().child(match self.left {
SplitButtonKind::ButtonLike(button) => button.into_any_element(),
SplitButtonKind::IconButton(icon) => icon.into_any_element(),
}))

View file

@ -652,7 +652,7 @@ pub fn render_table_row(
// restrict_scroll_to_axis lets vertical scroll events pass through to the list.
let mut scrollable_section = div()
.id(("table-row-scrollable", row_index as u64))
.flex_grow()
.flex_grow_1()
.overflow_x_scroll()
.flex()
.child(
@ -769,7 +769,7 @@ pub fn render_table_header(
);
let mut scrollable_section = div()
.id("table-header-scrollable")
.flex_grow()
.flex_grow_1()
.overflow_x_scroll()
.flex()
.child(inner);
@ -1136,7 +1136,7 @@ impl RenderOnce for Table {
})
.child({
let content = div()
.flex_grow()
.flex_grow_1()
.w_full()
.relative()
.overflow_hidden()
@ -1180,7 +1180,7 @@ impl RenderOnce for Table {
},
)
.size_full()
.flex_grow()
.flex_grow_1()
.with_sizing_behavior(ListSizingBehavior::Auto)
.with_horizontal_sizing_behavior(horizontal_sizing)
.when_some(
@ -1208,7 +1208,7 @@ impl RenderOnce for Table {
}
})
.size_full()
.flex_grow()
.flex_grow_1()
.with_sizing_behavior(ListSizingBehavior::Auto),
),
})
@ -1237,7 +1237,7 @@ impl RenderOnce for Table {
let mut h_scroll_container = div()
.id("table-h-scroll")
.overflow_x_scroll()
.flex_grow()
.flex_grow_1()
.h_full()
.track_scroll(&state.read(cx).horizontal_scroll_handle)
.child(table);

View file

@ -336,7 +336,7 @@ impl RenderOnce for ListItem {
}))
.child(
h_flex()
.flex_grow()
.flex_grow_1()
.flex_shrink_0()
.flex_basis(relative(0.25))
.gap(DynamicSpacing::Base06.rems(cx))
@ -354,16 +354,16 @@ impl RenderOnce for ListItem {
.when_some(self.end_slot, |this, end_slot| {
this.child(match self.end_slot_visibility {
EndSlotVisibility::Always => {
h_flex().flex_shrink().overflow_hidden().child(end_slot)
h_flex().flex_shrink_1().overflow_hidden().child(end_slot)
}
EndSlotVisibility::OnHover => h_flex()
.flex_shrink()
.flex_shrink_1()
.overflow_hidden()
.visible_on_hover("list_item")
.child(end_slot),
EndSlotVisibility::SwapOnHover(hover_slot) => h_flex()
.relative()
.flex_shrink()
.flex_shrink_1()
.child(h_flex().visible_on_hover("list_item").child(hover_slot))
.child(
h_flex()

View file

@ -129,7 +129,7 @@ impl RenderOnce for TabBar {
.child(
h_flex()
.id("tabs")
.flex_grow()
.flex_grow_1()
.overflow_x_scroll()
.when_some(self.scroll_handle, |cx, scroll_handle| {
cx.track_scroll(&scroll_handle)

View file

@ -193,7 +193,7 @@ impl RenderOnce for TreeViewItem {
h_flex()
.id("nested_inner_tree_view_item")
.w_full()
.flex_grow()
.flex_grow_1()
.child(
Label::new(label)
.when(!self.selected, |this| this.color(Color::Muted)),

View file

@ -176,7 +176,7 @@ impl Render for InputField {
.w_full()
.px_2()
.py_1p5()
.flex_grow()
.flex_grow_1()
.text_color(style.text_color)
.rounded_md()
.bg(style.background_color)

View file

@ -3630,7 +3630,7 @@ impl Pane {
.id("tab_bar_drop_target")
.min_w_6()
.h(Tab::container_height(cx))
.flex_grow()
.flex_grow_1()
// HACK: This empty child is currently necessary to force the drop target to appear
// despite us setting a min width above.
.child("")
@ -3674,7 +3674,7 @@ impl Pane {
.debug_selector(|| "pinned_tabs_border".into())
.min_w_6()
.h(Tab::container_height(cx))
.flex_grow()
.flex_grow_1()
.border_l_1()
.border_color(cx.theme().colors().border)
// HACK: This empty child is currently necessary to force the drop target to appear

View file

@ -344,7 +344,7 @@ impl QuickActionBar {
.child(
div()
.overflow_x_hidden()
.flex_grow()
.flex_grow_1()
.whitespace_nowrap()
.child(
Label::new(if let Some(name) = current_kernel_name {

View file

@ -518,7 +518,7 @@ impl Render for TelemetryLogView {
} else {
div()
.size_full()
.flex_grow()
.flex_grow_1()
.child(
list(self.list_state.clone(), cx.processor(Self::render_entry))
.with_sizing_behavior(gpui::ListSizingBehavior::Auto)