mirror of
https://github.com/zed-industries/zed.git
synced 2024-09-18 18:08:07 +03:00
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:
parent
5d751f232c
commit
24d9374744
@ -417,11 +417,7 @@ impl Item for ChannelView {
|
|||||||
.gap_2()
|
.gap_2()
|
||||||
.child(
|
.child(
|
||||||
Label::new(channel_name)
|
Label::new(channel_name)
|
||||||
.color(if params.selected {
|
.color(params.text_color())
|
||||||
Color::Default
|
|
||||||
} else {
|
|
||||||
Color::Muted
|
|
||||||
})
|
|
||||||
.italic(params.preview),
|
.italic(params.preview),
|
||||||
)
|
)
|
||||||
.when_some(status, |element, status| {
|
.when_some(status, |element, status| {
|
||||||
|
@ -649,11 +649,7 @@ impl Item for ProjectDiagnosticsEditor {
|
|||||||
fn tab_content(&self, params: TabContentParams, _: &WindowContext) -> AnyElement {
|
fn tab_content(&self, params: TabContentParams, _: &WindowContext) -> AnyElement {
|
||||||
if self.summary.error_count == 0 && self.summary.warning_count == 0 {
|
if self.summary.error_count == 0 && self.summary.warning_count == 0 {
|
||||||
Label::new("No problems")
|
Label::new("No problems")
|
||||||
.color(if params.selected {
|
.color(params.text_color())
|
||||||
Color::Default
|
|
||||||
} else {
|
|
||||||
Color::Muted
|
|
||||||
})
|
|
||||||
.into_any_element()
|
.into_any_element()
|
||||||
} else {
|
} else {
|
||||||
h_flex()
|
h_flex()
|
||||||
@ -663,13 +659,10 @@ impl Item for ProjectDiagnosticsEditor {
|
|||||||
h_flex()
|
h_flex()
|
||||||
.gap_1()
|
.gap_1()
|
||||||
.child(Icon::new(IconName::XCircle).color(Color::Error))
|
.child(Icon::new(IconName::XCircle).color(Color::Error))
|
||||||
.child(Label::new(self.summary.error_count.to_string()).color(
|
.child(
|
||||||
if params.selected {
|
Label::new(self.summary.error_count.to_string())
|
||||||
Color::Default
|
.color(params.text_color()),
|
||||||
} else {
|
),
|
||||||
Color::Muted
|
|
||||||
},
|
|
||||||
)),
|
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.when(self.summary.warning_count > 0, |then| {
|
.when(self.summary.warning_count > 0, |then| {
|
||||||
@ -677,13 +670,10 @@ impl Item for ProjectDiagnosticsEditor {
|
|||||||
h_flex()
|
h_flex()
|
||||||
.gap_1()
|
.gap_1()
|
||||||
.child(Icon::new(IconName::ExclamationTriangle).color(Color::Warning))
|
.child(Icon::new(IconName::ExclamationTriangle).color(Color::Warning))
|
||||||
.child(Label::new(self.summary.warning_count.to_string()).color(
|
.child(
|
||||||
if params.selected {
|
Label::new(self.summary.warning_count.to_string())
|
||||||
Color::Default
|
.color(params.text_color()),
|
||||||
} else {
|
),
|
||||||
Color::Muted
|
|
||||||
},
|
|
||||||
)),
|
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.into_any_element()
|
.into_any_element()
|
||||||
|
@ -466,11 +466,7 @@ impl Item for GroupedDiagnosticsEditor {
|
|||||||
fn tab_content(&self, params: TabContentParams, _: &WindowContext) -> AnyElement {
|
fn tab_content(&self, params: TabContentParams, _: &WindowContext) -> AnyElement {
|
||||||
if self.summary.error_count == 0 && self.summary.warning_count == 0 {
|
if self.summary.error_count == 0 && self.summary.warning_count == 0 {
|
||||||
Label::new("No problems")
|
Label::new("No problems")
|
||||||
.color(if params.selected {
|
.color(params.text_color())
|
||||||
Color::Default
|
|
||||||
} else {
|
|
||||||
Color::Muted
|
|
||||||
})
|
|
||||||
.into_any_element()
|
.into_any_element()
|
||||||
} else {
|
} else {
|
||||||
h_flex()
|
h_flex()
|
||||||
@ -480,13 +476,10 @@ impl Item for GroupedDiagnosticsEditor {
|
|||||||
h_flex()
|
h_flex()
|
||||||
.gap_1()
|
.gap_1()
|
||||||
.child(Icon::new(IconName::XCircle).color(Color::Error))
|
.child(Icon::new(IconName::XCircle).color(Color::Error))
|
||||||
.child(Label::new(self.summary.error_count.to_string()).color(
|
.child(
|
||||||
if params.selected {
|
Label::new(self.summary.error_count.to_string())
|
||||||
Color::Default
|
.color(params.text_color()),
|
||||||
} else {
|
),
|
||||||
Color::Muted
|
|
||||||
},
|
|
||||||
)),
|
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.when(self.summary.warning_count > 0, |then| {
|
.when(self.summary.warning_count > 0, |then| {
|
||||||
@ -494,13 +487,10 @@ impl Item for GroupedDiagnosticsEditor {
|
|||||||
h_flex()
|
h_flex()
|
||||||
.gap_1()
|
.gap_1()
|
||||||
.child(Icon::new(IconName::ExclamationTriangle).color(Color::Warning))
|
.child(Icon::new(IconName::ExclamationTriangle).color(Color::Warning))
|
||||||
.child(Label::new(self.summary.warning_count.to_string()).color(
|
.child(
|
||||||
if params.selected {
|
Label::new(self.summary.warning_count.to_string())
|
||||||
Color::Default
|
.color(params.text_color()),
|
||||||
} else {
|
),
|
||||||
Color::Muted
|
|
||||||
},
|
|
||||||
)),
|
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.into_any_element()
|
.into_any_element()
|
||||||
|
@ -80,11 +80,7 @@ impl Item for ImageView {
|
|||||||
.to_string();
|
.to_string();
|
||||||
Label::new(title)
|
Label::new(title)
|
||||||
.single_line()
|
.single_line()
|
||||||
.color(if params.selected {
|
.color(params.text_color())
|
||||||
Color::Default
|
|
||||||
} else {
|
|
||||||
Color::Muted
|
|
||||||
})
|
|
||||||
.italic(params.preview)
|
.italic(params.preview)
|
||||||
.into_any_element()
|
.into_any_element()
|
||||||
}
|
}
|
||||||
|
@ -994,11 +994,7 @@ impl Item for TerminalView {
|
|||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.child(Label::new(title).color(if params.selected {
|
.child(Label::new(title).color(params.text_color()))
|
||||||
Color::Default
|
|
||||||
} else {
|
|
||||||
Color::Muted
|
|
||||||
}))
|
|
||||||
.into_any()
|
.into_any()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,6 +142,17 @@ pub struct TabContentParams {
|
|||||||
pub preview: bool,
|
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> {
|
pub trait Item: FocusableView + EventEmitter<Self::Event> {
|
||||||
type Event;
|
type Event;
|
||||||
|
|
||||||
@ -154,13 +165,9 @@ pub trait Item: FocusableView + EventEmitter<Self::Event> {
|
|||||||
return gpui::Empty.into_any();
|
return gpui::Empty.into_any();
|
||||||
};
|
};
|
||||||
|
|
||||||
let color = if params.selected {
|
Label::new(text)
|
||||||
Color::Default
|
.color(params.text_color())
|
||||||
} else {
|
.into_any_element()
|
||||||
Color::Muted
|
|
||||||
};
|
|
||||||
|
|
||||||
Label::new(text).color(color).into_any_element()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the textual contents of the tab.
|
/// Returns the textual contents of the tab.
|
||||||
|
Loading…
Reference in New Issue
Block a user