Add text_color helper for tab contents (#14737)

This PR adds a `text_color` method to `TabContentParams` to more easily
compute the text color to be used for tab contents.

This consolidates a number of conditionals that were scattered all over
the place to give us a singular source of truth for these colors.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-07-18 09:27:05 -04:00 committed by GitHub
parent 5d751f232c
commit 24d9374744
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 35 additions and 60 deletions

View file

@ -142,6 +142,17 @@ pub struct TabContentParams {
pub preview: bool,
}
impl TabContentParams {
/// Returns the text color to be used for the tab content.
pub fn text_color(&self) -> Color {
if self.selected {
Color::Default
} else {
Color::Muted
}
}
}
pub trait Item: FocusableView + EventEmitter<Self::Event> {
type Event;
@ -154,13 +165,9 @@ pub trait Item: FocusableView + EventEmitter<Self::Event> {
return gpui::Empty.into_any();
};
let color = if params.selected {
Color::Default
} else {
Color::Muted
};
Label::new(text).color(color).into_any_element()
Label::new(text)
.color(params.text_color())
.into_any_element()
}
/// Returns the textual contents of the tab.