From 0711121586dba39f30ac76ee45d60ce3c4d2ab6b Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Sat, 18 Nov 2023 22:16:28 -0700 Subject: [PATCH] Add some test cases --- crates/gpui2/src/elements/text.rs | 2 +- crates/gpui2/src/taffy.rs | 2 +- crates/storybook2/src/stories/text.rs | 50 +++++++++++++++++++++++---- crates/storybook3/src/storybook3.rs | 19 ++++++++-- 4 files changed, 62 insertions(+), 11 deletions(-) diff --git a/crates/gpui2/src/elements/text.rs b/crates/gpui2/src/elements/text.rs index 49a63e925a..e3c63523e1 100644 --- a/crates/gpui2/src/elements/text.rs +++ b/crates/gpui2/src/elements/text.rs @@ -1,5 +1,5 @@ use crate::{ - px, AnyElement, BorrowWindow, Bounds, Component, Element, ElementId, LayoutId, Pixels, + AnyElement, BorrowWindow, Bounds, Component, Element, ElementId, LayoutId, Pixels, SharedString, Size, TextRun, ViewContext, WrappedLine, }; use parking_lot::{Mutex, MutexGuard}; diff --git a/crates/gpui2/src/taffy.rs b/crates/gpui2/src/taffy.rs index 5896011f96..81a057055a 100644 --- a/crates/gpui2/src/taffy.rs +++ b/crates/gpui2/src/taffy.rs @@ -159,7 +159,7 @@ impl TaffyLayoutEngine { .compute_layout_with_measure( id.into(), available_space.into(), - |known_dimensions, available_space, node_id, context| { + |known_dimensions, available_space, _node_id, context| { let Some(measure) = context else { return taffy::geometry::Size::default(); }; diff --git a/crates/storybook2/src/stories/text.rs b/crates/storybook2/src/stories/text.rs index 50b379cc13..512d680d37 100644 --- a/crates/storybook2/src/stories/text.rs +++ b/crates/storybook2/src/stories/text.rs @@ -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; pub struct TextStory; @@ -13,10 +15,46 @@ impl Render for TextStory { type Element = Div; fn render(&mut self, cx: &mut gpui::ViewContext) -> Self::Element { - v_stack().w_96().bg(white()).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.", - )) + v_stack() + .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. ", + "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.", + ))) } } diff --git a/crates/storybook3/src/storybook3.rs b/crates/storybook3/src/storybook3.rs index 291f8ce2ac..38b4250a50 100644 --- a/crates/storybook3/src/storybook3.rs +++ b/crates/storybook3/src/storybook3.rs @@ -1,14 +1,14 @@ use anyhow::Result; -use gpui::AssetSource; use gpui::{ div, px, size, AnyView, Bounds, Div, Render, ViewContext, VisualContext, WindowBounds, WindowOptions, }; +use gpui::{white, AssetSource}; use settings::{default_settings, Settings, SettingsStore}; use std::borrow::Cow; use std::sync::Arc; use theme::ThemeSettings; -use ui::{prelude::*, ContextMenuStory}; +use ui::{h_stack, prelude::*, ContextMenuStory}; struct Assets; @@ -65,9 +65,22 @@ impl Render for TestView { fn render(&mut self, _cx: &mut ViewContext) -> Self::Element { div() .flex() + .bg(gpui::blue()) .flex_col() .size_full() .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.", + ))), + ) } }