diff --git a/Cargo.lock b/Cargo.lock index 434d543a8..baaa5080b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,6 +8,7 @@ version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3b7f7f85a7e5f68090000ed7622545829afd484d210358702ae4cb97dd0c320" dependencies = [ + "enumn", "uuid", ] @@ -692,7 +693,7 @@ dependencies = [ "bitflags 2.11.1", "cexpr", "clang-sys", - "itertools 0.11.0", + "itertools 0.13.0", "log", "prettyplease", "proc-macro2", @@ -1196,7 +1197,7 @@ dependencies = [ [[package]] name = "collections" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#aeeacf5439b2d30d01e38d65d767e6f31b255ecc" +source = "git+https://github.com/zed-industries/zed#1a246efd7e1b83ab568ec5e3e6c1a43a42e1abba" dependencies = [ "gpui_util", "indexmap", @@ -1752,7 +1753,7 @@ dependencies = [ [[package]] name = "derive_refineable" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#aeeacf5439b2d30d01e38d65d767e6f31b255ecc" +source = "git+https://github.com/zed-industries/zed#1a246efd7e1b83ab568ec5e3e6c1a43a42e1abba" dependencies = [ "proc-macro2", "quote", @@ -2000,6 +2001,17 @@ dependencies = [ "syn 2.0.117", ] +[[package]] +name = "enumn" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f9ed6b3789237c8a0c1c505af1c7eb2c560df6186f01b098c3a1064ea532f38" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", +] + [[package]] name = "equator" version = "0.4.2" @@ -2118,6 +2130,9 @@ name = "fastrand" version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f1f227452a390804cdb637b74a86990f2a7d7ba4b7d5693aac9b4dd6defd8d6" +dependencies = [ + "getrandom 0.3.4", +] [[package]] name = "fax" @@ -2241,6 +2256,18 @@ dependencies = [ "spin 0.9.8", ] +[[package]] +name = "flume" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e139bc46ca777eb5efaf62df0ab8cc5fd400866427e56c68b22e414e53bd3be" +dependencies = [ + "fastrand", + "futures-core", + "futures-sink", + "spin 0.9.8", +] + [[package]] name = "fnv" version = "1.0.7" @@ -2847,7 +2874,7 @@ dependencies = [ "log", "presser", "thiserror 2.0.18", - "windows 0.58.0", + "windows 0.62.2", ] [[package]] @@ -2873,7 +2900,7 @@ dependencies = [ [[package]] name = "gpui" version = "0.2.2" -source = "git+https://github.com/zed-industries/zed#aeeacf5439b2d30d01e38d65d767e6f31b255ecc" +source = "git+https://github.com/zed-industries/zed#1a246efd7e1b83ab568ec5e3e6c1a43a42e1abba" dependencies = [ "accesskit", "anyhow", @@ -3120,7 +3147,7 @@ dependencies = [ [[package]] name = "gpui_linux" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#aeeacf5439b2d30d01e38d65d767e6f31b255ecc" +source = "git+https://github.com/zed-industries/zed#1a246efd7e1b83ab568ec5e3e6c1a43a42e1abba" dependencies = [ "accesskit", "accesskit_unix", @@ -3171,7 +3198,7 @@ dependencies = [ [[package]] name = "gpui_macos" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#aeeacf5439b2d30d01e38d65d767e6f31b255ecc" +source = "git+https://github.com/zed-industries/zed#1a246efd7e1b83ab568ec5e3e6c1a43a42e1abba" dependencies = [ "accesskit", "accesskit_macos", @@ -3218,7 +3245,7 @@ dependencies = [ [[package]] name = "gpui_macros" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#aeeacf5439b2d30d01e38d65d767e6f31b255ecc" +source = "git+https://github.com/zed-industries/zed#1a246efd7e1b83ab568ec5e3e6c1a43a42e1abba" dependencies = [ "heck 0.5.0", "proc-macro2", @@ -3229,7 +3256,7 @@ dependencies = [ [[package]] name = "gpui_platform" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#aeeacf5439b2d30d01e38d65d767e6f31b255ecc" +source = "git+https://github.com/zed-industries/zed#1a246efd7e1b83ab568ec5e3e6c1a43a42e1abba" dependencies = [ "console_error_panic_hook", "gpui", @@ -3242,7 +3269,7 @@ dependencies = [ [[package]] name = "gpui_shared_string" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#aeeacf5439b2d30d01e38d65d767e6f31b255ecc" +source = "git+https://github.com/zed-industries/zed#1a246efd7e1b83ab568ec5e3e6c1a43a42e1abba" dependencies = [ "schemars", "serde", @@ -3252,7 +3279,7 @@ dependencies = [ [[package]] name = "gpui_util" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#aeeacf5439b2d30d01e38d65d767e6f31b255ecc" +source = "git+https://github.com/zed-industries/zed#1a246efd7e1b83ab568ec5e3e6c1a43a42e1abba" dependencies = [ "anyhow", "log", @@ -3262,7 +3289,7 @@ dependencies = [ [[package]] name = "gpui_web" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#aeeacf5439b2d30d01e38d65d767e6f31b255ecc" +source = "git+https://github.com/zed-industries/zed#1a246efd7e1b83ab568ec5e3e6c1a43a42e1abba" dependencies = [ "anyhow", "console_error_panic_hook", @@ -3286,7 +3313,7 @@ dependencies = [ [[package]] name = "gpui_wgpu" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#aeeacf5439b2d30d01e38d65d767e6f31b255ecc" +source = "git+https://github.com/zed-industries/zed#1a246efd7e1b83ab568ec5e3e6c1a43a42e1abba" dependencies = [ "anyhow", "bytemuck", @@ -3315,7 +3342,7 @@ dependencies = [ [[package]] name = "gpui_windows" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#aeeacf5439b2d30d01e38d65d767e6f31b255ecc" +source = "git+https://github.com/zed-industries/zed#1a246efd7e1b83ab568ec5e3e6c1a43a42e1abba" dependencies = [ "accesskit", "accesskit_windows", @@ -3631,7 +3658,7 @@ dependencies = [ [[package]] name = "http_client" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#aeeacf5439b2d30d01e38d65d767e6f31b255ecc" +source = "git+https://github.com/zed-industries/zed#1a246efd7e1b83ab568ec5e3e6c1a43a42e1abba" dependencies = [ "anyhow", "async-compression", @@ -3651,7 +3678,7 @@ dependencies = [ [[package]] name = "http_client_tls" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#aeeacf5439b2d30d01e38d65d767e6f31b255ecc" +source = "git+https://github.com/zed-industries/zed#1a246efd7e1b83ab568ec5e3e6c1a43a42e1abba" dependencies = [ "rustls", "rustls-platform-verifier", @@ -3732,7 +3759,7 @@ dependencies = [ "js-sys", "log", "wasm-bindgen", - "windows-core 0.58.0", + "windows-core 0.62.2", ] [[package]] @@ -3893,7 +3920,6 @@ dependencies = [ "qoi", "ravif", "rayon", - "rgb", "tiff", "zune-core 0.5.1", "zune-jpeg 0.5.15", @@ -4277,7 +4303,7 @@ dependencies = [ "dirs", "dpi", "dunce", - "flume", + "flume 0.11.1", "gdkx11", "gtk", "html5ever 0.29.1", @@ -4673,7 +4699,7 @@ dependencies = [ [[package]] name = "media" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#aeeacf5439b2d30d01e38d65d767e6f31b255ecc" +source = "git+https://github.com/zed-industries/zed#1a246efd7e1b83ab568ec5e3e6c1a43a42e1abba" dependencies = [ "anyhow", "bindgen", @@ -5642,7 +5668,7 @@ checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" [[package]] name = "perf" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#aeeacf5439b2d30d01e38d65d767e6f31b255ecc" +source = "git+https://github.com/zed-industries/zed#1a246efd7e1b83ab568ec5e3e6c1a43a42e1abba" dependencies = [ "collections", "serde", @@ -6640,7 +6666,7 @@ dependencies = [ [[package]] name = "refineable" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#aeeacf5439b2d30d01e38d65d767e6f31b255ecc" +source = "git+https://github.com/zed-industries/zed#1a246efd7e1b83ab568ec5e3e6c1a43a42e1abba" dependencies = [ "derive_refineable", ] @@ -6692,7 +6718,7 @@ checksum = "19b30a45b0cd0bcca8037f3d0dc3421eaf95327a17cad11964fb8179b4fc4832" [[package]] name = "reqwest_client" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#aeeacf5439b2d30d01e38d65d767e6f31b255ecc" +source = "git+https://github.com/zed-industries/zed#1a246efd7e1b83ab568ec5e3e6c1a43a42e1abba" dependencies = [ "anyhow", "bytes", @@ -7129,12 +7155,12 @@ dependencies = [ [[package]] name = "scheduler" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#aeeacf5439b2d30d01e38d65d767e6f31b255ecc" +source = "git+https://github.com/zed-industries/zed#1a246efd7e1b83ab568ec5e3e6c1a43a42e1abba" dependencies = [ "async-task", "backtrace", "chrono", - "flume", + "flume 0.12.0", "futures", "parking_lot", "rand 0.9.4", @@ -7750,7 +7776,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "sum_tree" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#aeeacf5439b2d30d01e38d65d767e6f31b255ecc" +source = "git+https://github.com/zed-industries/zed#1a246efd7e1b83ab568ec5e3e6c1a43a42e1abba" dependencies = [ "heapless", "log", @@ -8006,9 +8032,9 @@ dependencies = [ [[package]] name = "taffy" -version = "0.10.1" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aea22054047c16c3f34d3ac473a2170be1424b1115b2a3adcf28cfb067c88859" +checksum = "73afc801dd6bd47529eaa7c7e90557f107527d1b7c9c7ed7d7803c7b8d0c357f" dependencies = [ "arrayvec", "grid", @@ -9211,7 +9237,7 @@ checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" [[package]] name = "util_macros" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#aeeacf5439b2d30d01e38d65d767e6f31b255ecc" +source = "git+https://github.com/zed-industries/zed#1a246efd7e1b83ab568ec5e3e6c1a43a42e1abba" dependencies = [ "perf", "quote", @@ -11211,7 +11237,7 @@ dependencies = [ [[package]] name = "zlog" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#aeeacf5439b2d30d01e38d65d767e6f31b255ecc" +source = "git+https://github.com/zed-industries/zed#1a246efd7e1b83ab568ec5e3e6c1a43a42e1abba" dependencies = [ "anyhow", "chrono", @@ -11228,7 +11254,7 @@ checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" [[package]] name = "ztracing" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#aeeacf5439b2d30d01e38d65d767e6f31b255ecc" +source = "git+https://github.com/zed-industries/zed#1a246efd7e1b83ab568ec5e3e6c1a43a42e1abba" dependencies = [ "tracing", "tracing-subscriber", @@ -11239,7 +11265,7 @@ dependencies = [ [[package]] name = "ztracing_macro" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#aeeacf5439b2d30d01e38d65d767e6f31b255ecc" +source = "git+https://github.com/zed-industries/zed#1a246efd7e1b83ab568ec5e3e6c1a43a42e1abba" [[package]] name = "zune-core" diff --git a/crates/ui/src/checkbox.rs b/crates/ui/src/checkbox.rs index 7ad21250e..9a9f4b9fe 100644 --- a/crates/ui/src/checkbox.rs +++ b/crates/ui/src/checkbox.rs @@ -219,109 +219,111 @@ impl RenderOnce for Checkbox { }; let radius = cx.theme().radius.min(px(4.)); - div().child( - self.base - .id(self.id.clone()) - .role(Role::CheckBox) - .aria_toggled(if checked { Toggled::True } else { Toggled::False }) - .when_some( - self.label.as_ref().map(|l| l.get_text(cx)), - |this, label| this.aria_label(label), + self.base + .id(self.id.clone()) + .role(Role::CheckBox) + .aria_toggled(if checked { + Toggled::True + } else { + Toggled::False + }) + .when_some( + self.label.as_ref().map(|l| l.get_text(cx)), + |this, label| this.aria_label(label), + ) + .when(!self.disabled, |this| { + this.track_focus( + &focus_handle + .tab_stop(self.tab_stop) + .tab_index(self.tab_index), ) - .when(!self.disabled, |this| { - this.track_focus( - &focus_handle - .tab_stop(self.tab_stop) - .tab_index(self.tab_index), - ) - }) - .h_flex() - .gap_2() - .items_start() - .line_height(relative(1.)) - .text_color(cx.theme().foreground) - .map(|this| match self.size { - Size::XSmall => this.text_xs(), - Size::Small => this.text_sm(), - Size::Medium => this.text_base(), - Size::Large => this.text_lg(), - _ => this, - }) - .when(self.disabled, |this| { - this.text_color(cx.theme().muted_foreground) - }) - .rounded(cx.theme().radius * 0.5) - .focus_ring(is_focused, px(2.), window, cx) - .refine_style(&self.style) - .child( - div() - .relative() - .map(|this| match self.size { - Size::XSmall => this.size_3(), - Size::Small => this.size_3p5(), - Size::Medium => this.size_4(), - Size::Large => this.size(rems(1.125)), - _ => this.size_4(), - }) - .flex_shrink_0() - .border_1() - .border_color(color) - .rounded(radius) - .when(cx.theme().shadow && !self.disabled, |this| this.shadow_xs()) - .map(|this| match checked { - false => this.bg(cx.theme().input_background()), - true if self.disabled => this.bg(color), - true => this.bg(cx.theme().tokens.primary), + }) + .h_flex() + .gap_2() + .items_start() + .line_height(relative(1.)) + .text_color(cx.theme().foreground) + .map(|this| match self.size { + Size::XSmall => this.text_xs(), + Size::Small => this.text_sm(), + Size::Medium => this.text_base(), + Size::Large => this.text_lg(), + _ => this, + }) + .when(self.disabled, |this| { + this.text_color(cx.theme().muted_foreground) + }) + .rounded(cx.theme().radius * 0.5) + .focus_ring(is_focused, px(2.), window, cx) + .refine_style(&self.style) + .child( + div() + .relative() + .map(|this| match self.size { + Size::XSmall => this.size_3(), + Size::Small => this.size_3p5(), + Size::Medium => this.size_4(), + Size::Large => this.size(rems(1.125)), + _ => this.size_4(), + }) + .flex_shrink_0() + .border_1() + .border_color(color) + .rounded(radius) + .when(cx.theme().shadow && !self.disabled, |this| this.shadow_xs()) + .map(|this| match checked { + false => this.bg(cx.theme().input_background()), + true if self.disabled => this.bg(color), + true => this.bg(cx.theme().tokens.primary), + }) + .child(checkbox_check_icon( + self.id, + self.size, + checked, + self.disabled, + window, + cx, + )), + ) + .when(self.label.is_some() || !self.children.is_empty(), |this| { + this.child( + v_flex() + .flex_1() + .overflow_hidden() + .line_height(relative(1.2)) + .gap_1() + .map(|this| { + if let Some(label) = self.label { + this.child( + div() + .size_full() + .text_color(cx.theme().foreground) + .when(self.disabled, |this| { + this.text_color(cx.theme().muted_foreground) + }) + .line_height(relative(1.)) + .child(label), + ) + } else { + this + } }) - .child(checkbox_check_icon( - self.id, - self.size, - checked, - self.disabled, - window, - cx, - )), + .children(self.children), ) - .when(self.label.is_some() || !self.children.is_empty(), |this| { - this.child( - v_flex() - .flex_1() - .overflow_hidden() - .line_height(relative(1.2)) - .gap_1() - .map(|this| { - if let Some(label) = self.label { - this.child( - div() - .size_full() - .text_color(cx.theme().foreground) - .when(self.disabled, |this| { - this.text_color(cx.theme().muted_foreground) - }) - .line_height(relative(1.)) - .child(label), - ) - } else { - this - } - }) - .children(self.children), - ) - }) - .on_mouse_down(gpui::MouseButton::Left, |_, window, _| { - // Avoid focus on mouse down. - window.prevent_default(); - }) - .when(!self.disabled, |this| { - this.on_click({ - let on_click = self.on_click.clone(); - move |_, window, cx| { - window.prevent_default(); - Self::handle_click(&on_click, checked, window, cx); - } - }) + }) + .on_mouse_down(gpui::MouseButton::Left, |_, window, _| { + // Avoid focus on mouse down. + window.prevent_default(); + }) + .when(!self.disabled, |this| { + this.on_click({ + let on_click = self.on_click.clone(); + move |_, window, cx| { + window.prevent_default(); + Self::handle_click(&on_click, checked, window, cx); + } }) - .map(|this| self.tooltip.apply(this)), - ) + }) + .map(|this| self.tooltip.apply(this)) } } diff --git a/crates/ui/src/form/form.rs b/crates/ui/src/form/form.rs index a6c1eeb48..aa7eb764f 100644 --- a/crates/ui/src/form/form.rs +++ b/crates/ui/src/form/form.rs @@ -1,6 +1,6 @@ use gpui::{ App, Axis, IntoElement, ParentElement, Pixels, Rems, RenderOnce, StyleRefinement, Styled, - Window, div, px, + Window, px, }; use crate::{ @@ -98,20 +98,17 @@ impl RenderOnce for Form { _ => px(8.), }; - // Add `div` wrapper to avoid sometime width not full issue. - div().child( - v_flex() - .w_full() - .gap_x(gap * 3.) - .gap_y(gap) - .grid() - .grid_cols(props.columns as u16) - .children( - self.fields - .into_iter() - .enumerate() - .map(|(ix, field)| field.props(ix, props)), - ), - ) + v_flex() + .w_full() + .gap_x(gap * 3.) + .gap_y(gap) + .grid() + .grid_cols(props.columns as u16) + .children( + self.fields + .into_iter() + .enumerate() + .map(|(ix, field)| field.props(ix, props)), + ) } } diff --git a/crates/ui/src/group_box.rs b/crates/ui/src/group_box.rs index fd59de159..334a76358 100644 --- a/crates/ui/src/group_box.rs +++ b/crates/ui/src/group_box.rs @@ -135,35 +135,32 @@ impl RenderOnce for GroupBox { GroupBoxVariant::Outline => (None, Some(cx.theme().border), true), }; - // Add `div` wrapper to avoid sometime width not full issue. - div().child( - v_flex() - .id(self.id.unwrap_or("group-box".into())) - .w_full() - .when(has_paddings, |this| this.gap_3()) - .when(!has_paddings, |this| this.gap_4()) - .refine_style(&self.style) - .when_some(self.title, |this, title| { - this.child( - div() - .text_color(cx.theme().muted_foreground) - .line_height(relative(1.)) - .refine_style(&self.title_style) - .child(title), - ) - }) - .child( - v_flex() - .when_some(bg, |this, bg| this.bg(bg)) - .when_some(border, |this, border| this.border_color(border).border_1()) - .text_color(cx.theme().group_box_foreground) - .when(has_paddings, |this| this.p_4()) - .gap_4() - .rounded(cx.theme().radius) - .refine_style(&self.content_style) - .children(self.children), - ), - ) + v_flex() + .id(self.id.unwrap_or("group-box".into())) + .w_full() + .when(has_paddings, |this| this.gap_3()) + .when(!has_paddings, |this| this.gap_4()) + .refine_style(&self.style) + .when_some(self.title, |this, title| { + this.child( + div() + .text_color(cx.theme().muted_foreground) + .line_height(relative(1.)) + .refine_style(&self.title_style) + .child(title), + ) + }) + .child( + v_flex() + .when_some(bg, |this, bg| this.bg(bg)) + .when_some(border, |this, border| this.border_color(border).border_1()) + .text_color(cx.theme().group_box_foreground) + .when(has_paddings, |this| this.p_4()) + .gap_4() + .rounded(cx.theme().radius) + .refine_style(&self.content_style) + .children(self.children), + ) } } diff --git a/crates/ui/src/radio.rs b/crates/ui/src/radio.rs index 8e9c2cc65..556e64172 100644 --- a/crates/ui/src/radio.rs +++ b/crates/ui/src/radio.rs @@ -157,103 +157,98 @@ impl RenderOnce for Radio { (border_color, bg) }; - // wrap a flex to patch for let Radio display inline - div().child( - self.base - .id(self.id.clone()) - .role(Role::RadioButton) - .aria_selected(self.checked) - .when_some( - self.label.as_ref().map(|l| l.get_text(cx)), - |this, label| this.aria_label(label), + self.base + .id(self.id.clone()) + .role(Role::RadioButton) + .aria_selected(self.checked) + .when_some( + self.label.as_ref().map(|l| l.get_text(cx)), + |this, label| this.aria_label(label), + ) + .when_some(self.position_in_set, |this, pos| { + this.aria_position_in_set(pos) + }) + .when_some(self.size_of_set, |this, size| this.aria_size_of_set(size)) + .when(!self.disabled, |this| { + this.track_focus( + &focus_handle + .tab_stop(self.tab_stop) + .tab_index(self.tab_index), ) - .when_some(self.position_in_set, |this, pos| { - this.aria_position_in_set(pos) - }) - .when_some(self.size_of_set, |this, size| { - this.aria_size_of_set(size) - }) - .when(!self.disabled, |this| { - this.track_focus( - &focus_handle - .tab_stop(self.tab_stop) - .tab_index(self.tab_index), - ) - }) - .h_flex() - .gap_x_2() - .text_color(cx.theme().foreground) - .items_start() - .line_height(relative(1.)) - .rounded(cx.theme().radius * 0.5) - .focus_ring(is_focused, px(2.), window, cx) - .map(|this| match self.size { - Size::XSmall => this.text_xs(), - Size::Small => this.text_sm(), - Size::Medium => this.text_base(), - Size::Large => this.text_lg(), - _ => this, - }) - .refine_style(&self.style) - .child( - div() - .relative() - .map(|this| match self.size { - Size::XSmall => this.size_3(), - Size::Small => this.size_3p5(), - Size::Medium => this.size_4(), - Size::Large => this.size(rems(1.125)), - _ => this.size_4(), - }) - .flex_shrink_0() - .rounded_full() - .border_1() - .border_color(border_color) - .when(cx.theme().shadow && !disabled, |this| this.shadow_xs()) - .map(|this| match self.checked { - false => this.bg(cx.theme().input_background()), - true if disabled => this.bg(bg), - true => this.bg(cx.theme().tokens.primary), + }) + .h_flex() + .gap_x_2() + .text_color(cx.theme().foreground) + .items_start() + .line_height(relative(1.)) + .rounded(cx.theme().radius * 0.5) + .focus_ring(is_focused, px(2.), window, cx) + .map(|this| match self.size { + Size::XSmall => this.text_xs(), + Size::Small => this.text_sm(), + Size::Medium => this.text_base(), + Size::Large => this.text_lg(), + _ => this, + }) + .refine_style(&self.style) + .child( + div() + .relative() + .map(|this| match self.size { + Size::XSmall => this.size_3(), + Size::Small => this.size_3p5(), + Size::Medium => this.size_4(), + Size::Large => this.size(rems(1.125)), + _ => this.size_4(), + }) + .flex_shrink_0() + .rounded_full() + .border_1() + .border_color(border_color) + .when(cx.theme().shadow && !disabled, |this| this.shadow_xs()) + .map(|this| match self.checked { + false => this.bg(cx.theme().input_background()), + true if disabled => this.bg(bg), + true => this.bg(cx.theme().tokens.primary), + }) + .child(checkbox_check_icon( + self.id, self.size, checked, disabled, window, cx, + )), + ) + .when(!self.children.is_empty() || self.label.is_some(), |this| { + this.child( + v_flex() + .w_full() + .line_height(relative(1.2)) + .gap_1() + .when_some(self.label, |this, label| { + this.child( + div() + .size_full() + .line_height(relative(1.)) + .when(self.disabled, |this| { + this.text_color(cx.theme().muted_foreground) + }) + .child(label), + ) }) - .child(checkbox_check_icon( - self.id, self.size, checked, disabled, window, cx, - )), + .children(self.children), ) - .when(!self.children.is_empty() || self.label.is_some(), |this| { - this.child( - v_flex() - .w_full() - .line_height(relative(1.2)) - .gap_1() - .when_some(self.label, |this, label| { - this.child( - div() - .size_full() - .line_height(relative(1.)) - .when(self.disabled, |this| { - this.text_color(cx.theme().muted_foreground) - }) - .child(label), - ) - }) - .children(self.children), - ) - }) - .on_mouse_down(gpui::MouseButton::Left, |_, window, _| { - // Avoid focus on mouse down. - window.prevent_default(); + }) + .on_mouse_down(gpui::MouseButton::Left, |_, window, _| { + // Avoid focus on mouse down. + window.prevent_default(); + }) + .when(!self.disabled, |this| { + this.on_click({ + let on_click = self.on_click.clone(); + move |_, window, cx| { + window.prevent_default(); + Self::handle_click(&on_click, checked, window, cx); + } }) - .when(!self.disabled, |this| { - this.on_click({ - let on_click = self.on_click.clone(); - move |_, window, cx| { - window.prevent_default(); - Self::handle_click(&on_click, checked, window, cx); - } - }) - }) - .map(|this| self.tooltip.apply(this)), - ) + }) + .map(|this| self.tooltip.apply(this)) } }