diff --git a/gpui/src/elements/container.rs b/gpui/src/elements/container.rs index eeda6f206d139c210259744f9604fb30f90d1fae..abbafe4d034e76926ff79f794a286a24a727d927 100644 --- a/gpui/src/elements/container.rs +++ b/gpui/src/elements/container.rs @@ -348,6 +348,17 @@ enum Spacing { }, } +impl Padding { + pub fn uniform(padding: f32) -> Self { + Self { + top: padding, + left: padding, + bottom: padding, + right: padding, + } + } +} + impl ToJson for Padding { fn to_json(&self) -> serde_json::Value { let mut value = json!({}); diff --git a/gpui/src/elements/mouse_event_handler.rs b/gpui/src/elements/mouse_event_handler.rs index 3b28409f9fa7ee67d90401bb40357ca012558b24..2cc01c3080f22a7d3587dd4750879ee8287dc5a8 100644 --- a/gpui/src/elements/mouse_event_handler.rs +++ b/gpui/src/elements/mouse_event_handler.rs @@ -116,7 +116,8 @@ impl Element for MouseEventHandler { let hit_bounds = RectF::from_points( bounds.origin() - vec2f(self.padding.left, self.padding.top), bounds.lower_right() + vec2f(self.padding.right, self.padding.bottom), - ); + ) + .round_out(); self.state.update(cx, |state, cx| match event { Event::MouseMoved { diff --git a/zed/assets/themes/_base.toml b/zed/assets/themes/_base.toml index f8f059487a38f9ee5cfc89d76f0f0ec50f9d8a58..57f25eb26fc331311a2dc93536554471ec549602 100644 --- a/zed/assets/themes/_base.toml +++ b/zed/assets/themes/_base.toml @@ -18,7 +18,7 @@ width = 16 [workspace.tab] text = "$text.2" -padding = { left = 10, right = 10 } +padding = { left = 12, right = 12 } icon_width = 8 spacing = 10 icon_close = "$text.2.color" diff --git a/zed/src/workspace/pane.rs b/zed/src/workspace/pane.rs index c0cd6bb9fd7e47141cc633a55cb9eeb00e48ca81..31ec57354ad131f8542f211c5ee88cfb2520ad8f 100644 --- a/zed/src/workspace/pane.rs +++ b/zed/src/workspace/pane.rs @@ -185,13 +185,13 @@ impl Pane { theme.workspace.tab.label.text.font_size, ); - let mut row = Flex::row(); - for (ix, item) in self.items.iter().enumerate() { - let is_active = ix == self.active_item; + enum Tabs {} + let tabs = MouseEventHandler::new::(0, cx, |mouse_state, cx| { + let mut row = Flex::row(); + for (ix, item) in self.items.iter().enumerate() { + let is_active = ix == self.active_item; - enum Tab {} - row.add_child( - MouseEventHandler::new::(item.id(), cx, |mouse_state, cx| { + row.add_child({ let mut title = item.title(cx); if title.len() > MAX_TAB_TITLE_LEN { let mut truncated_len = MAX_TAB_TITLE_LEN; @@ -276,7 +276,7 @@ impl Pane { ) .with_child( Align::new( - ConstrainedBox::new(if is_active || mouse_state.hovered { + ConstrainedBox::new(if mouse_state.hovered { let item_id = item.id(); enum TabCloseButton {} let icon = Svg::new("icons/x.svg"); @@ -292,6 +292,7 @@ impl Pane { } }, ) + .with_padding(Padding::uniform(4.)) .with_cursor_style(CursorStyle::PointingHand) .on_click(move |cx| { cx.dispatch_action(CloseItem(item_id)) @@ -316,36 +317,37 @@ impl Pane { }) .boxed() }) - .boxed(), - ) - } + } - // Ensure there's always a minimum amount of space after the last tab, - // so that the tab's border doesn't abut the window's border. - let mut border = Border::bottom(1.0, Color::default()); - border.color = theme.workspace.tab.container.border.color; - - row.add_child( - ConstrainedBox::new( - Container::new(Empty::new().boxed()) - .with_border(border) - .boxed(), - ) - .with_min_width(20.) - .named("fixed-filler"), - ); + // Ensure there's always a minimum amount of space after the last tab, + // so that the tab's border doesn't abut the window's border. + let mut border = Border::bottom(1.0, Color::default()); + border.color = theme.workspace.tab.container.border.color; - row.add_child( - Expanded::new( - 0.0, - Container::new(Empty::new().boxed()) - .with_border(border) - .boxed(), - ) - .named("filler"), - ); + row.add_child( + ConstrainedBox::new( + Container::new(Empty::new().boxed()) + .with_border(border) + .boxed(), + ) + .with_min_width(20.) + .named("fixed-filler"), + ); + + row.add_child( + Expanded::new( + 0.0, + Container::new(Empty::new().boxed()) + .with_border(border) + .boxed(), + ) + .named("filler"), + ); + + row.boxed() + }); - ConstrainedBox::new(row.boxed()) + ConstrainedBox::new(tabs.boxed()) .with_height(line_height + 16.) .named("tabs") }