Render close icons on all tabs when tab bar is hovered

This commit is contained in:
Nathan Sobo
2021-09-17 16:45:09 -07:00
parent cab577406d
commit b5c76ccc95
+34 -33
View File
@@ -185,13 +185,13 @@ impl Pane {
theme.workspace.tab.label.text.font_size, theme.workspace.tab.label.text.font_size,
); );
let mut row = Flex::row(); enum Tabs {}
for (ix, item) in self.items.iter().enumerate() { let tabs = MouseEventHandler::new::<Tabs, _, _, _>(0, cx, |mouse_state, cx| {
let is_active = ix == self.active_item; 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({
row.add_child(
MouseEventHandler::new::<Tab, _, _, _>(item.id(), cx, |mouse_state, cx| {
let mut title = item.title(cx); let mut title = item.title(cx);
if title.len() > MAX_TAB_TITLE_LEN { if title.len() > MAX_TAB_TITLE_LEN {
let mut truncated_len = MAX_TAB_TITLE_LEN; let mut truncated_len = MAX_TAB_TITLE_LEN;
@@ -276,7 +276,7 @@ impl Pane {
) )
.with_child( .with_child(
Align::new( Align::new(
ConstrainedBox::new(if is_active || mouse_state.hovered { ConstrainedBox::new(if mouse_state.hovered {
let item_id = item.id(); let item_id = item.id();
enum TabCloseButton {} enum TabCloseButton {}
let icon = Svg::new("icons/x.svg"); let icon = Svg::new("icons/x.svg");
@@ -316,36 +316,37 @@ impl Pane {
}) })
.boxed() .boxed()
}) })
.boxed(), }
)
}
// Ensure there's always a minimum amount of space after the last tab, // 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. // so that the tab's border doesn't abut the window's border.
let mut border = Border::bottom(1.0, Color::default()); let mut border = Border::bottom(1.0, Color::default());
border.color = theme.workspace.tab.container.border.color; border.color = theme.workspace.tab.container.border.color;
row.add_child( row.add_child(
ConstrainedBox::new( ConstrainedBox::new(
Container::new(Empty::new().boxed()) Container::new(Empty::new().boxed())
.with_border(border) .with_border(border)
.boxed(), .boxed(),
) )
.with_min_width(20.) .with_min_width(20.)
.named("fixed-filler"), .named("fixed-filler"),
); );
row.add_child( row.add_child(
Expanded::new( Expanded::new(
0.0, 0.0,
Container::new(Empty::new().boxed()) Container::new(Empty::new().boxed())
.with_border(border) .with_border(border)
.boxed(), .boxed(),
) )
.named("filler"), .named("filler"),
); );
ConstrainedBox::new(row.boxed()) row.boxed()
});
ConstrainedBox::new(tabs.boxed())
.with_height(line_height + 16.) .with_height(line_height + 16.)
.named("tabs") .named("tabs")
} }