tab_bar: Fix some incorrect style in TabBar. (#1078)

This change to fix some incorrect style use, that will break in Taffy
0.5.2+

Ref https://github.com/zed-industries/zed/pull/34827

- Add `Tab::empty` to create a Tab without label.
- Fix form layout in Taffy new version.
- Update GPUI for scroll API changes.
This commit is contained in:
Jason Lee 2025-07-22 13:30:04 +08:00 committed by GitHub
parent 61b7e54bfa
commit 7d3301d695
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 272 additions and 36 deletions

266
Cargo.lock generated
View file

@ -733,7 +733,7 @@ dependencies = [
"bitflags 2.9.1",
"cexpr",
"clang-sys",
"itertools 0.12.1",
"itertools 0.11.0",
"lazy_static",
"lazycell",
"log",
@ -756,7 +756,7 @@ dependencies = [
"bitflags 2.9.1",
"cexpr",
"clang-sys",
"itertools 0.13.0",
"itertools 0.11.0",
"log",
"prettyplease",
"proc-macro2",
@ -821,7 +821,7 @@ dependencies = [
[[package]]
name = "blade-graphics"
version = "0.6.0"
source = "git+https://github.com/kvark/blade?rev=416375211bb0b5826b3584dccdb6a43369e499ad#416375211bb0b5826b3584dccdb6a43369e499ad"
source = "git+https://github.com/kvark/blade?rev=e0ec4e720957edd51b945b64dd85605ea54bcfe5#e0ec4e720957edd51b945b64dd85605ea54bcfe5"
dependencies = [
"ash",
"ash-window",
@ -854,7 +854,7 @@ dependencies = [
[[package]]
name = "blade-macros"
version = "0.3.0"
source = "git+https://github.com/kvark/blade?rev=416375211bb0b5826b3584dccdb6a43369e499ad#416375211bb0b5826b3584dccdb6a43369e499ad"
source = "git+https://github.com/kvark/blade?rev=e0ec4e720957edd51b945b64dd85605ea54bcfe5#e0ec4e720957edd51b945b64dd85605ea54bcfe5"
dependencies = [
"proc-macro2",
"quote",
@ -864,7 +864,7 @@ dependencies = [
[[package]]
name = "blade-util"
version = "0.2.0"
source = "git+https://github.com/kvark/blade?rev=416375211bb0b5826b3584dccdb6a43369e499ad#416375211bb0b5826b3584dccdb6a43369e499ad"
source = "git+https://github.com/kvark/blade?rev=e0ec4e720957edd51b945b64dd85605ea54bcfe5#e0ec4e720957edd51b945b64dd85605ea54bcfe5"
dependencies = [
"blade-graphics",
"bytemuck",
@ -1432,7 +1432,7 @@ dependencies = [
[[package]]
name = "collections"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed.git#5253702200f4fb491b6608ac0a0c6df89b224b0f"
source = "git+https://github.com/zed-industries/zed.git#5a530ecd39f8be386a98cabef45c13163ff1da19"
dependencies = [
"indexmap 2.9.0",
"rustc-hash 2.1.0",
@ -1610,6 +1610,19 @@ dependencies = [
"libc",
]
[[package]]
name = "core-graphics-helmer-fork"
version = "0.24.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32eb7c354ae9f6d437a6039099ce7ecd049337a8109b23d73e48e8ffba8e9cd5"
dependencies = [
"bitflags 2.9.1",
"core-foundation 0.9.4",
"core-graphics-types 0.1.3",
"foreign-types 0.5.0",
"libc",
]
[[package]]
name = "core-graphics-types"
version = "0.1.3"
@ -1852,6 +1865,16 @@ version = "0.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4f211af61d8efdd104f96e57adf5e426ba1bc3ed7a4ead616e15e5881fd79c4d"
[[package]]
name = "ctrlc"
version = "3.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46f93780a459b7d656ef7f071fe699c4d3d2cb201c4b24d085b6ddc505276e73"
dependencies = [
"nix 0.30.1",
"windows-sys 0.59.0",
]
[[package]]
name = "cursor-icon"
version = "1.2.0"
@ -1967,7 +1990,7 @@ dependencies = [
[[package]]
name = "derive_refineable"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed.git#5253702200f4fb491b6608ac0a0c6df89b224b0f"
source = "git+https://github.com/zed-industries/zed.git#5a530ecd39f8be386a98cabef45c13163ff1da19"
dependencies = [
"proc-macro2",
"quote",
@ -3119,7 +3142,7 @@ dependencies = [
[[package]]
name = "gpui"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed.git#5253702200f4fb491b6608ac0a0c6df89b224b0f"
source = "git+https://github.com/zed-industries/zed.git#5a530ecd39f8be386a98cabef45c13163ff1da19"
dependencies = [
"anyhow",
"as-raw-xcb-connection",
@ -3175,6 +3198,7 @@ dependencies = [
"raw-window-handle",
"refineable",
"resvg",
"scap",
"schemars",
"seahash",
"semantic_version",
@ -3303,7 +3327,7 @@ dependencies = [
[[package]]
name = "gpui_macros"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed.git#5253702200f4fb491b6608ac0a0c6df89b224b0f"
source = "git+https://github.com/zed-industries/zed.git#5a530ecd39f8be386a98cabef45c13163ff1da19"
dependencies = [
"heck 0.5.0",
"proc-macro2",
@ -3314,9 +3338,9 @@ dependencies = [
[[package]]
name = "grid"
version = "0.13.0"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d196ffc1627db18a531359249b2bf8416178d84b729f3cebeb278f285fb9b58c"
checksum = "be136d9dacc2a13cc70bb6c8f902b414fb2641f8db1314637c6b7933411a8f82"
[[package]]
name = "gtk"
@ -3573,7 +3597,7 @@ dependencies = [
[[package]]
name = "http_client"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed.git#5253702200f4fb491b6608ac0a0c6df89b224b0f"
source = "git+https://github.com/zed-industries/zed.git#5a530ecd39f8be386a98cabef45c13163ff1da19"
dependencies = [
"anyhow",
"bytes",
@ -3590,7 +3614,7 @@ dependencies = [
[[package]]
name = "http_client_tls"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed.git#5253702200f4fb491b6608ac0a0c6df89b224b0f"
source = "git+https://github.com/zed-industries/zed.git#5a530ecd39f8be386a98cabef45c13163ff1da19"
dependencies = [
"rustls",
"rustls-platform-verifier",
@ -4416,7 +4440,7 @@ dependencies = [
[[package]]
name = "media"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed.git#5253702200f4fb491b6608ac0a0c6df89b224b0f"
source = "git+https://github.com/zed-industries/zed.git#5a530ecd39f8be386a98cabef45c13163ff1da19"
dependencies = [
"anyhow",
"bindgen 0.71.1",
@ -4700,6 +4724,15 @@ dependencies = [
"windows-sys 0.59.0",
]
[[package]]
name = "ntapi"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8a3895c6391c39d7fe7ebc444a87eb2991b2a0bc718fdabd071eec617fc68e4"
dependencies = [
"winapi",
]
[[package]]
name = "nu-ansi-term"
version = "0.46.0"
@ -4844,7 +4877,7 @@ version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af1844ef2428cc3e1cb900be36181049ef3d3193c63e43026cfe202983b27a56"
dependencies = [
"proc-macro-crate 3.2.0",
"proc-macro-crate 1.3.1",
"proc-macro2",
"quote",
"syn 2.0.101",
@ -4863,6 +4896,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1"
dependencies = [
"malloc_buf",
"objc_exception",
]
[[package]]
name = "objc-foundation"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9"
dependencies = [
"block",
"objc",
"objc_id",
]
[[package]]
@ -5166,6 +5211,24 @@ dependencies = [
"objc2-foundation 0.2.2",
]
[[package]]
name = "objc_exception"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad970fb455818ad6cba4c122ad012fae53ae8b4795f86378bce65e4f6bab2ca4"
dependencies = [
"cc",
]
[[package]]
name = "objc_id"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c92d4ddb4bd7b50d730c215ff871754d0da6b2178849f8a2a2ab69712d0c073b"
dependencies = [
"objc",
]
[[package]]
name = "object"
version = "0.36.7"
@ -5954,6 +6017,15 @@ version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3"
[[package]]
name = "quick-xml"
version = "0.30.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eff6510e86862b57b210fd8cbe8ed3f0d7d600b9c2863cd4549a2e033c66e956"
dependencies = [
"memchr",
]
[[package]]
name = "quick-xml"
version = "0.32.0"
@ -6317,7 +6389,7 @@ dependencies = [
[[package]]
name = "refineable"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed.git#5253702200f4fb491b6608ac0a0c6df89b224b0f"
source = "git+https://github.com/zed-industries/zed.git#5a530ecd39f8be386a98cabef45c13163ff1da19"
dependencies = [
"derive_refineable",
"workspace-hack",
@ -6472,7 +6544,7 @@ dependencies = [
[[package]]
name = "reqwest_client"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed.git#5253702200f4fb491b6608ac0a0c6df89b224b0f"
source = "git+https://github.com/zed-industries/zed.git#5a530ecd39f8be386a98cabef45c13163ff1da19"
dependencies = [
"anyhow",
"bytes",
@ -6873,6 +6945,27 @@ dependencies = [
"winapi-util",
]
[[package]]
name = "scap"
version = "0.0.8"
source = "git+https://github.com/zed-industries/scap?rev=808aa5c45b41e8f44729d02e38fd00a2fe2722e7#808aa5c45b41e8f44729d02e38fd00a2fe2722e7"
dependencies = [
"anyhow",
"cocoa 0.25.0",
"core-graphics-helmer-fork",
"log",
"objc",
"rand 0.8.5",
"screencapturekit",
"screencapturekit-sys",
"sysinfo",
"tao-core-video-sys",
"windows 0.61.1",
"windows-capture",
"x11",
"xcb",
]
[[package]]
name = "schannel"
version = "0.1.27"
@ -6920,6 +7013,29 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "screencapturekit"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a5eeeb57ac94960cfe5ff4c402be6585ae4c8d29a2cf41b276048c2e849d64e"
dependencies = [
"screencapturekit-sys",
]
[[package]]
name = "screencapturekit-sys"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22411b57f7d49e7fe08025198813ee6fd65e1ee5eff4ebc7880c12c82bde4c60"
dependencies = [
"block",
"dispatch",
"objc",
"objc-foundation",
"objc_id",
"once_cell",
]
[[package]]
name = "sctk-adwaita"
version = "0.10.1"
@ -7004,7 +7120,7 @@ checksum = "d369a96f978623eb3dc28807c4852d6cc617fed53da5d3c400feff1ef34a714a"
[[package]]
name = "semantic_version"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed.git#5253702200f4fb491b6608ac0a0c6df89b224b0f"
source = "git+https://github.com/zed-industries/zed.git#5a530ecd39f8be386a98cabef45c13163ff1da19"
dependencies = [
"anyhow",
"serde",
@ -7587,7 +7703,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
[[package]]
name = "sum_tree"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed.git#5253702200f4fb491b6608ac0a0c6df89b224b0f"
source = "git+https://github.com/zed-industries/zed.git#5a530ecd39f8be386a98cabef45c13163ff1da19"
dependencies = [
"arrayvec",
"log",
@ -7740,6 +7856,20 @@ dependencies = [
"libc",
]
[[package]]
name = "sysinfo"
version = "0.31.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "355dbe4f8799b304b05e1b0f05fc59b2a18d36645cf169607da45bde2f69a1be"
dependencies = [
"core-foundation-sys",
"libc",
"memchr",
"ntapi",
"rayon",
"windows 0.57.0",
]
[[package]]
name = "system-configuration"
version = "0.6.1"
@ -7776,9 +7906,9 @@ dependencies = [
[[package]]
name = "taffy"
version = "0.4.4"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ec17858c2d465b2f734b798b920818a974faf0babb15d7fef81818a4b2d16f1"
checksum = "e8b61630cba2afd2c851821add2e1bb1b7851a2436e839ab73b56558b009035e"
dependencies = [
"arrayvec",
"grid",
@ -7793,6 +7923,18 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8bdb6fa0dfa67b38c1e66b7041ba9dcf23b99d8121907cd31c807a332f7a0bbb"
[[package]]
name = "tao-core-video-sys"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "271450eb289cb4d8d0720c6ce70c72c8c858c93dd61fc625881616752e6b98f6"
dependencies = [
"cfg-if",
"core-foundation-sys",
"libc",
"objc",
]
[[package]]
name = "tao-macros"
version = "0.1.3"
@ -8789,7 +8931,7 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "util"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed.git#5253702200f4fb491b6608ac0a0c6df89b224b0f"
source = "git+https://github.com/zed-industries/zed.git#5a530ecd39f8be386a98cabef45c13163ff1da19"
dependencies = [
"anyhow",
"async-fs 2.1.2",
@ -9393,6 +9535,16 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows"
version = "0.57.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143"
dependencies = [
"windows-core 0.57.0",
"windows-targets 0.52.6",
]
[[package]]
name = "windows"
version = "0.58.0"
@ -9416,6 +9568,21 @@ dependencies = [
"windows-numerics",
]
[[package]]
name = "windows-capture"
version = "1.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59d10b4be8b907c7055bc7270dd68d2b920978ffacc1599dcb563a79f0e68d16"
dependencies = [
"clap",
"ctrlc",
"parking_lot",
"rayon",
"thiserror 2.0.12",
"windows 0.61.1",
"windows-future",
]
[[package]]
name = "windows-collections"
version = "0.2.0"
@ -9434,6 +9601,18 @@ dependencies = [
"windows-targets 0.52.6",
]
[[package]]
name = "windows-core"
version = "0.57.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2ed2439a290666cd67ecce2b0ffaad89c2a56b976b736e6ece670297897832d"
dependencies = [
"windows-implement 0.57.0",
"windows-interface 0.57.0",
"windows-result 0.1.2",
"windows-targets 0.52.6",
]
[[package]]
name = "windows-core"
version = "0.58.0"
@ -9470,6 +9649,17 @@ dependencies = [
"windows-link",
]
[[package]]
name = "windows-implement"
version = "0.57.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.101",
]
[[package]]
name = "windows-implement"
version = "0.58.0"
@ -9492,6 +9682,17 @@ dependencies = [
"syn 2.0.101",
]
[[package]]
name = "windows-interface"
version = "0.57.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.101",
]
[[package]]
name = "windows-interface"
version = "0.58.0"
@ -9552,6 +9753,15 @@ dependencies = [
"windows-strings 0.4.0",
]
[[package]]
name = "windows-result"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8"
dependencies = [
"windows-targets 0.52.6",
]
[[package]]
name = "windows-result"
version = "0.2.0"
@ -10112,6 +10322,18 @@ dependencies = [
"rustix 1.0.7",
]
[[package]]
name = "xcb"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1e2f212bb1a92cd8caac8051b829a6582ede155ccb60b5d5908b81b100952be"
dependencies = [
"bitflags 1.3.2",
"libc",
"quick-xml 0.30.0",
"x11",
]
[[package]]
name = "xcursor"
version = "0.3.8"

View file

@ -15,6 +15,7 @@ resolver = "2"
[workspace.dependencies]
gpui = { git = "https://github.com/zed-industries/zed.git" }
reqwest_client = { git = "https://github.com/zed-industries/zed.git" }
gpui-component = { path = "crates/ui" }
gpui-component-macros = { path = "crates/macros" }
story = { path = "crates/story" }

View file

@ -14,7 +14,7 @@ fake = { version = "2.10.0", features = ["dummy"] }
rand = "0.8"
raw-window-handle = { version = "0.6", features = ["std"] }
regex = "1"
reqwest_client = { git = "https://github.com/zed-industries/zed.git" }
reqwest_client.workspace = true
rust-embed = "8.5.0"
serde = "1"
serde_json = "1"

View file

@ -696,7 +696,7 @@ impl TabPanel {
}
Some(
Tab::new("")
Tab::empty()
.map(|this| {
if let Some(tab_name) = panel.tab_name(cx) {
this.child(tab_name)
@ -704,7 +704,6 @@ impl TabPanel {
this.child(panel.title(window, cx))
}
})
.py_2()
.selected(active)
.on_click(cx.listener({
let is_collapsed = self.collapsed;

View file

@ -394,7 +394,13 @@ impl RenderOnce for FormField {
}),
)
})
.child(div().flex_1().overflow_x_hidden().child(self.child)),
.child(
div()
.w_full()
.flex_1()
.overflow_x_hidden()
.child(self.child),
),
)
.child(
// Other

View file

@ -69,7 +69,7 @@ impl ScrollHandleOffsetable for ScrollHandle {
}
fn content_size(&self) -> Size<Pixels> {
self.padded_content_size()
self.max_offset()
}
}
@ -87,7 +87,7 @@ impl ScrollHandleOffsetable for UniformListScrollHandle {
}
fn content_size(&self) -> Size<Pixels> {
self.0.borrow().base_handle.padded_content_size()
self.0.borrow().base_handle.max_offset()
}
}

View file

@ -379,7 +379,7 @@ impl TabVariant {
pub struct Tab {
id: ElementId,
base: Div,
pub(super) label: SharedString,
pub(super) label: Option<SharedString>,
icon: Option<Icon>,
prefix: Option<AnyElement>,
suffix: Option<AnyElement>,
@ -427,8 +427,8 @@ impl Default for Tab {
fn default() -> Self {
Self {
id: ElementId::Integer(0),
base: div().gap_1(),
label: SharedString::new(""),
base: div(),
label: None,
icon: None,
children: Vec::new(),
disabled: false,
@ -446,10 +446,15 @@ impl Tab {
/// Create a new tab with a label.
pub fn new(label: impl Into<SharedString>) -> Self {
let mut this = Self::default();
this.label = label.into();
this.label = Some(label.into());
this
}
/// Create an empty tab.
pub fn empty() -> Self {
Self::default()
}
/// Create a Icon tab.
pub fn icon(icon: impl Into<Icon>) -> Self {
let mut this = Self::default();
@ -579,12 +584,12 @@ impl RenderOnce for Tab {
let inner_margins = self.variant.inner_margins(self.size);
let inner_height = self.variant.inner_height(self.size);
let height = self.variant.height(self.size);
let has_label = !self.label.is_empty();
self.base
.id(self.id)
.flex()
.flex_wrap()
.gap_1()
.items_center()
.flex_shrink_0()
.overflow_hidden()
@ -637,8 +642,11 @@ impl RenderOnce for Tab {
}
None => this
.paddings(inner_paddings)
.when(has_label, |this| this.child(self.label))
.when(!has_label, |this| this.children(self.children)),
.map(|this| match self.label {
Some(label) => this.child(label),
None => this,
})
.children(self.children),
})
.bg(tab_style.inner_bg)
.rounded(tab_style.inner_radius)

View file

@ -280,7 +280,7 @@ impl RenderOnce for TabBar {
this = this.scrollable();
for (ix, (label, disabled)) in item_labels.iter().enumerate() {
this = this.menu_with_check_and_disabled(
label.clone(),
label.clone().unwrap_or_default(),
selected_index == Some(ix),
Box::new(SelectTab(ix)),
*disabled,