Fix text wrapping when a child of a v_stack()
This commit is contained in:
parent
8837045abb
commit
7172ce37b1
2 changed files with 9 additions and 3 deletions
|
@ -64,13 +64,18 @@ impl<V: 'static> Element<V> for Text {
|
||||||
|
|
||||||
let layout_id = cx.request_measured_layout(Default::default(), rem_size, {
|
let layout_id = cx.request_measured_layout(Default::default(), rem_size, {
|
||||||
let element_state = element_state.clone();
|
let element_state = element_state.clone();
|
||||||
move |known_dimensions, _| {
|
move |known_dimensions, available_space| {
|
||||||
|
let wrap_width = known_dimensions.width.or(match available_space.width {
|
||||||
|
crate::AvailableSpace::Definite(x) => Some(x),
|
||||||
|
_ => None,
|
||||||
|
});
|
||||||
|
|
||||||
let Some(lines) = text_system
|
let Some(lines) = text_system
|
||||||
.shape_text(
|
.shape_text(
|
||||||
&text,
|
&text,
|
||||||
font_size,
|
font_size,
|
||||||
&runs[..],
|
&runs[..],
|
||||||
known_dimensions.width, // Wrap if we know the width.
|
wrap_width, // Wrap if we know the width.
|
||||||
)
|
)
|
||||||
.log_err()
|
.log_err()
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use gpui::{div, white, Div, ParentComponent, Render, Styled, View, VisualContext, WindowContext};
|
use gpui::{div, white, Div, ParentComponent, Render, Styled, View, VisualContext, WindowContext};
|
||||||
|
use ui::v_stack;
|
||||||
|
|
||||||
pub struct TextStory;
|
pub struct TextStory;
|
||||||
|
|
||||||
|
@ -12,7 +13,7 @@ impl Render for TextStory {
|
||||||
type Element = Div<Self>;
|
type Element = Div<Self>;
|
||||||
|
|
||||||
fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> Self::Element {
|
fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> Self::Element {
|
||||||
div().size_full().bg(white()).child(concat!(
|
v_stack().w_96().bg(white()).child(concat!(
|
||||||
"The quick brown fox jumps over the lazy dog. ",
|
"The quick brown fox jumps over the lazy dog. ",
|
||||||
"Meanwhile, the lazy dog decided it was time for a change. ",
|
"Meanwhile, the lazy dog decided it was time for a change. ",
|
||||||
"He started daily workout routines, ate healthier and became the fastest dog in town.",
|
"He started daily workout routines, ate healthier and became the fastest dog in town.",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue