Fix the issue where large sections of label do not wrap (#118)

This commit is contained in:
Floyd Wang 2024-08-07 19:38:48 +08:00 committed by GitHub
parent 340c5fef3d
commit e07f551317
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 4 deletions

View file

@ -66,14 +66,12 @@ impl Render for TextStory {
.child(
Label::new("Font Size Label")
.text_size(px(20.))
.text_left()
.font_semibold()
.line_height(rems(1.8)),
)
.child(
div().w(px(200.)).child(
Label::new("Label should support text wrap in default, if the text is too long, it should wrap to the next line.")
.text_left()
.line_height(rems(1.8)),
),
)

View file

@ -5,7 +5,7 @@ use gpui::{
use crate::{h_flex, theme::ActiveTheme};
#[derive(Default)]
#[derive(Default, PartialEq, Eq)]
pub enum TextAlign {
#[default]
Left,
@ -93,7 +93,13 @@ impl RenderOnce for Label {
TextAlign::Center => this.justify_center(),
TextAlign::Right => this.justify_end(),
})
.child(text_display),
.map(|this| {
if self.align == TextAlign::Left {
this.child(div().size_full().child(text_display))
} else {
this.child(text_display)
}
}),
)
}
}