Avoid doing string manipulation on render for single line label (#23227)
Release Notes: - N/A
This commit is contained in:
@@ -36,7 +36,6 @@ use crate::{prelude::*, LabelCommon, LabelLike, LabelSize, LineHeightStyle};
|
||||
pub struct Label {
|
||||
base: LabelLike,
|
||||
label: SharedString,
|
||||
single_line: bool,
|
||||
}
|
||||
|
||||
impl Label {
|
||||
@@ -53,7 +52,6 @@ impl Label {
|
||||
Self {
|
||||
base: LabelLike::new(),
|
||||
label: label.into(),
|
||||
single_line: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -170,7 +168,7 @@ impl LabelCommon for Label {
|
||||
}
|
||||
|
||||
fn single_line(mut self) -> Self {
|
||||
self.single_line = true;
|
||||
self.label = SharedString::from(self.label.replace('\n', ""));
|
||||
self.base = self.base.single_line();
|
||||
self
|
||||
}
|
||||
@@ -178,11 +176,6 @@ impl LabelCommon for Label {
|
||||
|
||||
impl RenderOnce for Label {
|
||||
fn render(self, _cx: &mut WindowContext) -> impl IntoElement {
|
||||
let target_label = if self.single_line {
|
||||
SharedString::from(self.label.replace('\n', ""))
|
||||
} else {
|
||||
self.label
|
||||
};
|
||||
self.base.child(target_label)
|
||||
self.base.child(self.label)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user