From 7962c2c50e30c73133f5b70fed9a1fecb4b8a684 Mon Sep 17 00:00:00 2001 From: Ren Amamiya Date: Fri, 20 Nov 2026 08:43:28 +0700 Subject: [PATCH] refactor(ui): use v_flex/h_flex helpers in components --- crates/ui/src/components/alert.rs | 4 +--- crates/ui/src/components/field.rs | 8 ++------ crates/ui/src/components/input.rs | 5 +---- crates/ui/src/components/list.rs | 9 ++++----- crates/ui/src/components/markdown.rs | 22 ++++++---------------- crates/ui/src/components/sidebar.rs | 4 +--- crates/ui/src/components/tabs.rs | 3 ++- crates/ui/src/components/toast.rs | 5 ++--- crates/ui/src/components/tree.rs | 6 ++---- crates/ui/src/layout/window_controls.rs | 8 ++++---- 10 files changed, 25 insertions(+), 49 deletions(-) diff --git a/crates/ui/src/components/alert.rs b/crates/ui/src/components/alert.rs index 0f1b49c..13af3f0 100644 --- a/crates/ui/src/components/alert.rs +++ b/crates/ui/src/components/alert.rs @@ -377,14 +377,12 @@ impl RenderOnce for AlertsView { let entries = self.alerts.read(cx).entries(); deferred( - div() + v_flex() .id(self.id) .absolute() .top_4() .right_4() .w(ALERT_STACK_WIDTH) - .flex() - .flex_col() .items_end() .gap_2() .children(entries.iter().rev().map(|entry| { diff --git a/crates/ui/src/components/field.rs b/crates/ui/src/components/field.rs index ec8565f..77822ac 100644 --- a/crates/ui/src/components/field.rs +++ b/crates/ui/src/components/field.rs @@ -143,9 +143,7 @@ impl RenderOnce for Field { }; let content = if self.variant == FieldVariant::Row { - div() - .flex() - .flex_col() + v_flex() .gap_1() .child( h_flex() @@ -160,9 +158,7 @@ impl RenderOnce for Field { }) .when_some(error, |field, error| field.child(error)) } else { - div() - .flex() - .flex_col() + v_flex() .gap_2() .child( v_flex() diff --git a/crates/ui/src/components/input.rs b/crates/ui/src/components/input.rs index 972d31c..b5a9f40 100644 --- a/crates/ui/src/components/input.rs +++ b/crates/ui/src/components/input.rs @@ -2247,15 +2247,12 @@ impl RenderOnce for Input { input.child(edge_zone("input-prefix", prefix)) }) .child( - div() + h_flex() .relative() .flex_1() .min_w_0() .h_full() .overflow_hidden() - .flex() - .flex_row() - .items_center() .when_some(line_height, |region, line_height| { region.items_start().line_height(line_height) }) diff --git a/crates/ui/src/components/list.rs b/crates/ui/src/components/list.rs index aba7af7..9523ec3 100644 --- a/crates/ui/src/components/list.rs +++ b/crates/ui/src/components/list.rs @@ -25,8 +25,9 @@ use gpui::{ StyleRefinement, Styled as _, Window, div, rems, }; +use crate::common::focus_handle; use crate::components::common::{ - StyledExt as _, nav_key, paint_selectable_row, selectable_label_color, + StyledExt as _, nav_key, paint_selectable_row, selectable_label_color, v_flex, }; use crate::icons::Icon; use crate::theme::ActiveTheme as _; @@ -172,7 +173,7 @@ impl RenderOnce for List { .map(|(index, _)| index) .collect(); - let focus = crate::components::common::focus_handle(&self.id, window, cx); + let focus = focus_handle(&self.id, window, cx); let label = self .a11y_label @@ -194,10 +195,8 @@ impl RenderOnce for List { }) .collect(); - div() + v_flex() .id(self.id) - .flex() - .flex_col() .gap_0p5() .text_sm() .refine_style(&self.style) diff --git a/crates/ui/src/components/markdown.rs b/crates/ui/src/components/markdown.rs index f08a3ab..068b502 100644 --- a/crates/ui/src/components/markdown.rs +++ b/crates/ui/src/components/markdown.rs @@ -45,7 +45,7 @@ use pulldown_cmark::{CodeBlockKind, Event, HeadingLevel, Options, Parser, Tag, T use crate::components::button::{Button, ButtonVariant}; use crate::components::checkbox::Checkbox; -use crate::components::common::{Sizable as _, StyledExt as _}; +use crate::components::common::{Sizable as _, StyledExt as _, h_flex, v_flex}; use crate::components::highlight::{HighlightedCode, Language, highlight, plain}; use crate::components::scrollbar::{Scrollbar, ScrollbarVisibility}; use crate::components::utils::code_line; @@ -853,10 +853,8 @@ pub fn bind_text_view_keys(cx: &mut App) { fn view_container(frame: &ViewFrame) -> Div { let clear_flag = frame.pressed_on_piece.clone(); - div() + v_flex() .w_full() - .flex() - .flex_col() .key_context(TEXT_VIEW_CONTEXT) .track_focus(&frame.focus_handle) .on_action({ @@ -1470,14 +1468,12 @@ fn render_block( /// The shared block frame: ambient text style, spacing, quote bar. fn block_frame(quote: bool, top: Rems, bottom: Rems, id: &ElementId, cx: &App) -> Div { let theme = cx.theme(); - div() + v_flex() .debug_selector({ let id = id.clone(); move || id.to_string() }) .w_full() - .flex() - .flex_col() .font_family(theme.ui_font()) .text_xs() .line_height(relative(BODY_LINE_HEIGHT)) @@ -1714,9 +1710,7 @@ fn code_row( .collect::>() .join("\n"); - let actions_row = div() - .flex() - .items_center() + let actions_row = h_flex() .justify_between() .pb_1() .when_some(language.cloned(), |row, language| { @@ -1737,10 +1731,8 @@ fn code_row( }), ); - let plate = div() + let plate = v_flex() .w_full() - .flex() - .flex_col() .rounded(theme.radius.control) .bg(theme.colors.muted) .p_2() @@ -1798,10 +1790,8 @@ fn table_row( let row_count = table.rows.len(); let mut cell_ix = 0usize; - let grid = div() + let grid = v_flex() .w_full() - .flex() - .flex_col() .border_1() .border_color(colors.border) .rounded(theme.radius.control) diff --git a/crates/ui/src/components/sidebar.rs b/crates/ui/src/components/sidebar.rs index 973aeb5..2750bee 100644 --- a/crates/ui/src/components/sidebar.rs +++ b/crates/ui/src/components/sidebar.rs @@ -378,9 +378,7 @@ impl RenderOnce for Sidebar { .handle(scroll.read(cx).clone()) .h_full() .child( - div() - .flex() - .flex_col() + v_flex() .gap_0p5() .when(padded, |content| content.p_2()) .children(children), diff --git a/crates/ui/src/components/tabs.rs b/crates/ui/src/components/tabs.rs index 83e601f..d8d3092 100644 --- a/crates/ui/src/components/tabs.rs +++ b/crates/ui/src/components/tabs.rs @@ -987,6 +987,7 @@ impl RenderOnce for Tabs { let Some(root_bounds) = measure_frame.map(|frame| frame.root_bounds) else { return root.children(strip); }; + let container_canvas = canvas( { let key = measure_key.clone(); @@ -1000,6 +1001,7 @@ impl RenderOnce for Tabs { ) .absolute() .inset(shadow_bleed); + let trigger_canvas = canvas( { let key = measure_key; @@ -1065,7 +1067,6 @@ impl Tab { let active = selected || self.pinned; let theme = cx.theme(); - let label_color = tab_label_color(ctx.variant, active, self.disabled, cx); let titlebar = ctx.variant == TabsVariant::Titlebar; diff --git a/crates/ui/src/components/toast.rs b/crates/ui/src/components/toast.rs index 9b4f34a..0405678 100644 --- a/crates/ui/src/components/toast.rs +++ b/crates/ui/src/components/toast.rs @@ -26,6 +26,7 @@ use gpui::{ use crate::components::button::{Button, ButtonVariant}; use crate::components::common::{ DismissHandler, ResultLogErr as _, Sizable as _, StyledExt as _, TOAST_LAYER, floating_panel, + v_flex, }; use crate::icons::{Icon, IconRole}; use crate::theme::{ActiveTheme as _, TOAST_MAX_WIDTH}; @@ -254,14 +255,12 @@ impl RenderOnce for ToastsView { let current = self.toasts.read(cx).current.clone(); deferred( - div() + v_flex() .id(self.id) .absolute() .left_0() .bottom_4() .w_full() - .flex() - .flex_col() .items_center() .when_some(exiting, |column, entry| { let id = entry.id; diff --git a/crates/ui/src/components/tree.rs b/crates/ui/src/components/tree.rs index eed4771..6b5cfe3 100644 --- a/crates/ui/src/components/tree.rs +++ b/crates/ui/src/components/tree.rs @@ -25,7 +25,7 @@ use gpui::{ }; use crate::components::common::{ - StyledExt as _, nav_key, paint_selectable_row, selectable_label_color, + StyledExt as _, nav_key, paint_selectable_row, selectable_label_color, v_flex, }; use crate::icons::{Icon, IconRole, icon}; use crate::theme::ActiveTheme as _; @@ -283,10 +283,8 @@ impl RenderOnce for Tree { }) .collect(); - div() + v_flex() .id(self.id) - .flex() - .flex_col() .gap_0p5() .text_sm() .refine_style(&self.style) diff --git a/crates/ui/src/layout/window_controls.rs b/crates/ui/src/layout/window_controls.rs index bfc5fac..2ed1f4f 100644 --- a/crates/ui/src/layout/window_controls.rs +++ b/crates/ui/src/layout/window_controls.rs @@ -19,6 +19,8 @@ use gpui::{ Stateful, StatefulInteractiveElement as _, Window, WindowControlArea, div, }; +#[cfg(any(target_os = "windows", target_os = "linux"))] +use crate::components::common::h_flex; #[cfg(any(target_os = "windows", target_os = "linux"))] use crate::icons::{IconRole, icon}; #[cfg(any(target_os = "windows", target_os = "linux"))] @@ -106,11 +108,9 @@ impl RenderOnce for WindowControls { let client_decorated = matches!(window.window_decorations(), Decorations::Client { .. }); - div() + h_flex() .flex_none() - .flex() - .flex_row() - .items_center() + .h_full() .gap_1() .when(client_decorated && controls.minimize, |row| { row.child(circle_button(