Add some test cases
This commit is contained in:
parent
cf47ed2c5f
commit
0711121586
4 changed files with 62 additions and 11 deletions
|
@ -1,5 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
px, AnyElement, BorrowWindow, Bounds, Component, Element, ElementId, LayoutId, Pixels,
|
AnyElement, BorrowWindow, Bounds, Component, Element, ElementId, LayoutId, Pixels,
|
||||||
SharedString, Size, TextRun, ViewContext, WrappedLine,
|
SharedString, Size, TextRun, ViewContext, WrappedLine,
|
||||||
};
|
};
|
||||||
use parking_lot::{Mutex, MutexGuard};
|
use parking_lot::{Mutex, MutexGuard};
|
||||||
|
|
|
@ -159,7 +159,7 @@ impl TaffyLayoutEngine {
|
||||||
.compute_layout_with_measure(
|
.compute_layout_with_measure(
|
||||||
id.into(),
|
id.into(),
|
||||||
available_space.into(),
|
available_space.into(),
|
||||||
|known_dimensions, available_space, node_id, context| {
|
|known_dimensions, available_space, _node_id, context| {
|
||||||
let Some(measure) = context else {
|
let Some(measure) = context else {
|
||||||
return taffy::geometry::Size::default();
|
return taffy::geometry::Size::default();
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
use gpui::{div, white, Div, ParentComponent, Render, Styled, View, VisualContext, WindowContext};
|
use gpui::{
|
||||||
|
blue, div, red, white, Div, ParentComponent, Render, Styled, View, VisualContext, WindowContext,
|
||||||
|
};
|
||||||
use ui::v_stack;
|
use ui::v_stack;
|
||||||
|
|
||||||
pub struct TextStory;
|
pub struct TextStory;
|
||||||
|
@ -13,10 +15,46 @@ 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 {
|
||||||
v_stack().w_96().bg(white()).child(concat!(
|
v_stack()
|
||||||
"The quick brown fox jumps over the lazy dog. ",
|
.bg(blue())
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.child(div().max_w_96().bg(white()).child(concat!(
|
||||||
|
"max-width: 96. 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.",
|
||||||
))
|
))),
|
||||||
|
)
|
||||||
|
.child(div().h_5())
|
||||||
|
.child(div().flex().flex_col().w_96().bg(white()).child(concat!(
|
||||||
|
"flex-col. width: 96; The quick brown fox jumps over the lazy dog. ",
|
||||||
|
"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.",
|
||||||
|
)))
|
||||||
|
.child(div().h_5())
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.child(div().min_w_96().bg(white()).child(concat!(
|
||||||
|
"min-width: 96. The quick brown fox jumps over the lazy dog. ",
|
||||||
|
"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.",
|
||||||
|
))))
|
||||||
|
.child(div().h_5())
|
||||||
|
.child(div().flex().w_96().bg(white()).child(div().overflow_hidden().child(concat!(
|
||||||
|
"flex-row. width 96. overflow-hidden. The quick brown fox jumps over the lazy dog. ",
|
||||||
|
"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.",
|
||||||
|
))))
|
||||||
|
// NOTE: When rendering text in a horizonal flex container,
|
||||||
|
// Taffy will not pass width constraints down from the parent.
|
||||||
|
// To fix this, render text in a praent with overflow: hidden, which
|
||||||
|
.child(div().h_5())
|
||||||
|
.child(div().flex().w_96().bg(red()).child(concat!(
|
||||||
|
"flex-row. width 96. The quick brown fox jumps over the lazy dog. ",
|
||||||
|
"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.",
|
||||||
|
)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use gpui::AssetSource;
|
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, px, size, AnyView, Bounds, Div, Render, ViewContext, VisualContext, WindowBounds,
|
div, px, size, AnyView, Bounds, Div, Render, ViewContext, VisualContext, WindowBounds,
|
||||||
WindowOptions,
|
WindowOptions,
|
||||||
};
|
};
|
||||||
|
use gpui::{white, AssetSource};
|
||||||
use settings::{default_settings, Settings, SettingsStore};
|
use settings::{default_settings, Settings, SettingsStore};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use theme::ThemeSettings;
|
use theme::ThemeSettings;
|
||||||
use ui::{prelude::*, ContextMenuStory};
|
use ui::{h_stack, prelude::*, ContextMenuStory};
|
||||||
|
|
||||||
struct Assets;
|
struct Assets;
|
||||||
|
|
||||||
|
@ -65,9 +65,22 @@ impl Render for TestView {
|
||||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Element {
|
fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Element {
|
||||||
div()
|
div()
|
||||||
.flex()
|
.flex()
|
||||||
|
.bg(gpui::blue())
|
||||||
.flex_col()
|
.flex_col()
|
||||||
.size_full()
|
.size_full()
|
||||||
.font("Helvetica")
|
.font("Helvetica")
|
||||||
.child(self.story.clone())
|
.child(div().h_5())
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.w_96()
|
||||||
|
.bg(white())
|
||||||
|
.relative()
|
||||||
|
.child(div().child(concat!(
|
||||||
|
"The quick brown fox jumps over the lazy dog. ",
|
||||||
|
"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.",
|
||||||
|
))),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue