mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-26 10:40:54 +00:00
Remove line breaks when displaying file names in the project panel (#10231)
- Fixed #8603 For the label title of the project panel, I find that there is no place to use to get the title of the label to do some operations, it should be safe to modify it, but I'm not sure how we need to modify the problem, I can think of two scenarios: 1. Modify every place where you don't want multiple lines to appear 2. Make the label only display a single line (e.g. provide a new parameter, or a new label type?)
This commit is contained in:
parent
26299fb8c9
commit
664efef76b
4 changed files with 29 additions and 5 deletions
|
@ -60,7 +60,7 @@ impl Render for Breadcrumbs {
|
|||
let mut text_style = cx.text_style();
|
||||
text_style.color = Color::Muted.color(cx);
|
||||
|
||||
StyledText::new(segment.text)
|
||||
StyledText::new(segment.text.replace('\n', ""))
|
||||
.with_highlights(&text_style, segment.highlights.unwrap_or_default())
|
||||
.into_any()
|
||||
});
|
||||
|
|
|
@ -83,6 +83,7 @@ impl Item for ImageView {
|
|||
.to_string_lossy()
|
||||
.to_string();
|
||||
Label::new(title)
|
||||
.single_line()
|
||||
.color(if selected {
|
||||
Color::Default
|
||||
} else {
|
||||
|
|
|
@ -1442,9 +1442,11 @@ impl ProjectPanel {
|
|||
if let (Some(editor), true) = (Some(&self.filename_editor), show_editor) {
|
||||
h_flex().h_6().w_full().child(editor.clone())
|
||||
} else {
|
||||
h_flex()
|
||||
.h_6()
|
||||
.child(Label::new(file_name).color(filename_text_color))
|
||||
h_flex().h_6().child(
|
||||
Label::new(file_name)
|
||||
.single_line()
|
||||
.color(filename_text_color),
|
||||
)
|
||||
}
|
||||
.ml_1(),
|
||||
)
|
||||
|
|
|
@ -34,6 +34,7 @@ use crate::{prelude::*, LabelCommon, LabelLike, LabelSize, LineHeightStyle};
|
|||
pub struct Label {
|
||||
base: LabelLike,
|
||||
label: SharedString,
|
||||
single_line: bool,
|
||||
}
|
||||
|
||||
impl Label {
|
||||
|
@ -50,8 +51,23 @@ impl Label {
|
|||
Self {
|
||||
base: LabelLike::new(),
|
||||
label: label.into(),
|
||||
single_line: false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Make the label display in a single line mode
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use ui::prelude::*;
|
||||
///
|
||||
/// let my_label = Label::new("Hello, World!").single_line(true);
|
||||
/// ```
|
||||
pub fn single_line(mut self) -> Self {
|
||||
self.single_line = true;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl LabelCommon for Label {
|
||||
|
@ -114,6 +130,11 @@ impl LabelCommon for Label {
|
|||
|
||||
impl RenderOnce for Label {
|
||||
fn render(self, _cx: &mut WindowContext) -> impl IntoElement {
|
||||
self.base.child(self.label)
|
||||
let target_label = if self.single_line {
|
||||
SharedString::from(self.label.replace('\n', ""))
|
||||
} else {
|
||||
self.label
|
||||
};
|
||||
self.base.child(target_label)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue