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

@ -649,11 +649,7 @@ impl Item for ProjectDiagnosticsEditor {
fn tab_content(&self, params: TabContentParams, _: &WindowContext) -> AnyElement {
if self.summary.error_count == 0 && self.summary.warning_count == 0 {
Label::new("No problems")
.color(if params.selected {
Color::Default
} else {
Color::Muted
})
.color(params.text_color())
.into_any_element()
} else {
h_flex()
@ -663,13 +659,10 @@ impl Item for ProjectDiagnosticsEditor {
h_flex()
.gap_1()
.child(Icon::new(IconName::XCircle).color(Color::Error))
.child(Label::new(self.summary.error_count.to_string()).color(
if params.selected {
Color::Default
} else {
Color::Muted
},
)),
.child(
Label::new(self.summary.error_count.to_string())
.color(params.text_color()),
),
)
})
.when(self.summary.warning_count > 0, |then| {
@ -677,13 +670,10 @@ impl Item for ProjectDiagnosticsEditor {
h_flex()
.gap_1()
.child(Icon::new(IconName::ExclamationTriangle).color(Color::Warning))
.child(Label::new(self.summary.warning_count.to_string()).color(
if params.selected {
Color::Default
} else {
Color::Muted
},
)),
.child(
Label::new(self.summary.warning_count.to_string())
.color(params.text_color()),
),
)
})
.into_any_element()

View file

@ -466,11 +466,7 @@ impl Item for GroupedDiagnosticsEditor {
fn tab_content(&self, params: TabContentParams, _: &WindowContext) -> AnyElement {
if self.summary.error_count == 0 && self.summary.warning_count == 0 {
Label::new("No problems")
.color(if params.selected {
Color::Default
} else {
Color::Muted
})
.color(params.text_color())
.into_any_element()
} else {
h_flex()
@ -480,13 +476,10 @@ impl Item for GroupedDiagnosticsEditor {
h_flex()
.gap_1()
.child(Icon::new(IconName::XCircle).color(Color::Error))
.child(Label::new(self.summary.error_count.to_string()).color(
if params.selected {
Color::Default
} else {
Color::Muted
},
)),
.child(
Label::new(self.summary.error_count.to_string())
.color(params.text_color()),
),
)
})
.when(self.summary.warning_count > 0, |then| {
@ -494,13 +487,10 @@ impl Item for GroupedDiagnosticsEditor {
h_flex()
.gap_1()
.child(Icon::new(IconName::ExclamationTriangle).color(Color::Warning))
.child(Label::new(self.summary.warning_count.to_string()).color(
if params.selected {
Color::Default
} else {
Color::Muted
},
)),
.child(
Label::new(self.summary.warning_count.to_string())
.color(params.text_color()),
),
)
})
.into_any_element()