Skip to main content

waft_material/
card.rs

1//! Flutter counterpart: material_ui's `card.dart`.
2
3use waft_embedder::{Clip, Color};
4use waft_foundation::App;
5use waft_painting::{
6    BorderRadiusGeometry, BorderSide, EdgeInsetsGeometry, RoundedRectangleBorder, ShapeBorderRef,
7};
8use waft_widgets::{
9    BuildContext, IntoWidget, KeyRef, Padding, Semantics, StatelessWidget, WidgetRef,
10};
11
12use crate::card_theme::CardThemeDataGetters;
13use crate::card_theme::{CardTheme, CardThemeData};
14use crate::generated::card_defaults_m3::CardDefaultsM3;
15use crate::generated::filled_card_defaults_m3::FilledCardDefaultsM3;
16use crate::generated::outlined_card_defaults_m3::OutlinedCardDefaultsM3;
17use crate::material::{Material, MaterialType};
18use crate::theme::Theme;
19
20#[derive(Clone, Copy, Debug, PartialEq, Eq)]
21enum CardVariant {
22    Elevated,
23    Filled,
24    Outlined,
25}
26
27/// A Material Design card: a panel with slightly rounded corners and an
28/// elevation shadow.
29///
30/// A card is a sheet of [`Material`] used to represent some related information,
31/// for example an album, a geographical location, a meal, contact details, etc.
32///
33/// Sometimes the primary action area of a card is the card itself. Cards can be
34/// one large touch target that shows a detail screen when tapped.
35///
36/// For Material Design 2 (when `ThemeData::use_material3` is false), there is a
37/// single card type: the elevated card. In that mode the named constructors
38/// ([`Card::filled`], [`Card::outlined`]) behave the same as the default [`Card::new`].
39///
40/// For Material Design 3 (when `ThemeData::use_material3` is true), three visual
41/// variants are available: the default [`Card::new`] (elevated), [`Card::filled`], and
42/// [`Card::outlined`]. All variants share the same theme class, [`CardThemeData`],
43/// so theme properties (for example [`CardThemeData::shape`]) apply to every card
44/// variant within the theme's scope.
45///
46/// See also:
47///
48///  * `ListTile`, to display icons and text in a card.
49///  * `ShowDialog`, to display a modal card.
50///  * <https://material.io/design/components/cards.html>
51///  * <https://m3.material.io/components/cards>
52#[derive(Debug)]
53pub struct Card {
54    pub key: Option<KeyRef>,
55
56    /// The card's background color.
57    ///
58    /// Defines the card's [`Material::color`].
59    ///
60    /// If this property is null then the ambient [`CardTheme::color`] is used. If that is null,
61    /// and `ThemeData::use_material3` is true, then `ColorScheme::surface_container_low` of
62    /// `ThemeData::color_scheme` is used. Otherwise, `ThemeData::card_color` is used.
63    pub color: Option<Color>,
64
65    /// The color to paint the shadow below the card.
66    ///
67    /// If null then the ambient [`CardThemeData::shadow_color`] is used.
68    /// If that's null too, then the overall theme's `ThemeData::shadow_color`
69    /// (default black) is used.
70    pub shadow_color: Option<Color>,
71
72    /// The color used as an overlay on [`color`](Self::color) to indicate elevation.
73    ///
74    /// This is not recommended for use. [Material 3 spec](https://m3.material.io/styles/color/the-color-system/color-roles)
75    /// introduced a set of tone-based surfaces and surface containers in its `ColorScheme`,
76    /// which provide more flexibility. The intention is to eventually remove surface tint color
77    /// from the framework.
78    ///
79    /// If this is null, no overlay will be applied. Otherwise this color
80    /// will be composited on top of [`color`](Self::color) with an opacity related
81    /// to [`elevation`](Self::elevation) and used to paint the background of the card.
82    ///
83    /// The default is `Colors::TRANSPARENT`.
84    ///
85    /// See [`Material::surface_tint_color`] for more details on how this
86    /// overlay is applied.
87    pub surface_tint_color: Option<Color>,
88
89    /// The z-coordinate at which to place this card. This controls the size of
90    /// the shadow below the card.
91    ///
92    /// Defines the card's [`Material::elevation`].
93    ///
94    /// If this property is null then the ambient [`CardThemeData::elevation`] is
95    /// used. If that's null, the default value is 1.0.
96    pub elevation: Option<f64>,
97
98    /// The shape of the card's [`Material`].
99    ///
100    /// Defines the card's [`Material::shape`].
101    ///
102    /// If null, the ambient [`CardTheme::shape`] from `ThemeData::card_theme` is used.
103    /// If that is also null, the shape defaults to a [`RoundedRectangleBorder`].
104    /// The default corner radius is 12.0 when `ThemeData::use_material3` is true,
105    /// and 4.0 otherwise. For Material 3 outlined cards, the default [`shape`](Self::shape)
106    /// also includes a border side (see `OutlinedBorder::side`).
107    pub shape: Option<ShapeBorderRef>,
108
109    /// Whether to paint the [`shape`](Self::shape) border in front of the
110    /// [`child`](Self::child).
111    ///
112    /// The default value is true.
113    /// If false, the border will be painted behind the [`child`](Self::child).
114    pub border_on_foreground: bool,
115
116    /// The content will be clipped (or not) according to this option.
117    ///
118    /// If this property is null then the ambient [`CardThemeData::clip_behavior`] is
119    /// used. If that's null then the behavior will be [`Clip::None`].
120    pub clip_behavior: Option<Clip>,
121
122    /// The empty space that surrounds the card.
123    ///
124    /// Defines the card's outer `Container::margin`.
125    ///
126    /// If this property is null then the ambient [`CardThemeData::margin`] is used.
127    /// If that's null, the default margin is 4.0 logical pixels on
128    /// all sides: `EdgeInsets::all(4.0)`.
129    pub margin: Option<EdgeInsetsGeometry>,
130
131    /// Whether this widget represents a single semantic container, or if false
132    /// a collection of individual semantic nodes.
133    ///
134    /// Defaults to true.
135    ///
136    /// Setting this flag to true will attempt to merge all child semantics into
137    /// this node. Setting this flag to false will force all child semantic nodes
138    /// to be explicit.
139    ///
140    /// This flag should be false if the card contains multiple different types
141    /// of content.
142    pub semantic_container: bool,
143
144    /// The widget below this widget in the tree.
145    pub child: Option<WidgetRef>,
146
147    variant: CardVariant,
148}
149
150impl Card {
151    /// Creates an elevated variant of Card.
152    ///
153    /// Elevated cards have a drop shadow, providing more separation from the
154    /// background than filled cards, but less than outlined cards.
155    ///
156    /// The [`elevation`](Self::elevation) must be null or non-negative.
157    pub fn new() -> Card {
158        Card::of_variant(CardVariant::Elevated)
159    }
160
161    /// Create a filled variant of Card.
162    ///
163    /// Filled cards provide subtle separation from the background. This has less
164    /// emphasis than elevated cards (the default) or outlined cards.
165    ///
166    /// If `ThemeData::use_material3` is false, this constructor is equivalent to
167    /// [`Card::new`].
168    pub fn filled() -> Card {
169        Card::of_variant(CardVariant::Filled)
170    }
171
172    /// Create an outlined variant of Card.
173    ///
174    /// Outlined cards have a visual boundary around the container. This can
175    /// provide greater emphasis than the other types.
176    ///
177    /// The card's outline is defined by the [`shape`](Self::shape) property. By default, the
178    /// card uses a [`RoundedRectangleBorder`] with a 12.0 corner radius, a 1.0
179    /// border width, and the color from `ColorScheme::outline_variant`. If you
180    /// provide a custom [`shape`](Self::shape), it is recommended to use an `OutlinedBorder`
181    /// with a non-null `OutlinedBorder::side` to keep a visible outline.
182    ///
183    /// If `ThemeData::use_material3` is false, this constructor is equivalent to
184    /// [`Card::new`].
185    pub fn outlined() -> Card {
186        Card::of_variant(CardVariant::Outlined)
187    }
188
189    fn of_variant(variant: CardVariant) -> Card {
190        Card {
191            key: None,
192            color: None,
193            shadow_color: None,
194            surface_tint_color: None,
195            elevation: None,
196            shape: None,
197            border_on_foreground: true,
198            clip_behavior: None,
199            margin: None,
200            semantic_container: true,
201            child: None,
202            variant,
203        }
204    }
205
206    /// Dart `Card(key:)`.
207    pub fn key(mut self, key: KeyRef) -> Card {
208        self.key = Some(key);
209        self
210    }
211
212    /// Dart `Card(color:)`.
213    pub fn color(mut self, color: Color) -> Card {
214        self.color = Some(color);
215        self
216    }
217
218    /// Dart `Card(shadowColor:)`.
219    pub fn shadow_color(mut self, shadow_color: Color) -> Card {
220        self.shadow_color = Some(shadow_color);
221        self
222    }
223
224    /// Dart `Card(surfaceTintColor:)`.
225    pub fn surface_tint_color(mut self, surface_tint_color: Color) -> Card {
226        self.surface_tint_color = Some(surface_tint_color);
227        self
228    }
229
230    /// Dart `Card(elevation:)`.
231    pub fn elevation(mut self, elevation: f64) -> Card {
232        debug_assert!(elevation >= 0.0);
233        self.elevation = Some(elevation);
234        self
235    }
236
237    /// Dart `Card(shape:)`.
238    pub fn shape(mut self, shape: impl Into<ShapeBorderRef>) -> Card {
239        self.shape = Some(shape.into());
240        self
241    }
242
243    /// Dart `Card(borderOnForeground:)`.
244    pub fn border_on_foreground(mut self, border_on_foreground: bool) -> Card {
245        self.border_on_foreground = border_on_foreground;
246        self
247    }
248
249    /// Dart `Card(margin:)`.
250    pub fn margin(mut self, margin: impl Into<EdgeInsetsGeometry>) -> Card {
251        let margin = margin.into();
252        self.margin = Some(margin);
253        self
254    }
255
256    /// Dart `Card(clipBehavior:)`.
257    pub fn clip_behavior(mut self, clip_behavior: Clip) -> Card {
258        self.clip_behavior = Some(clip_behavior);
259        self
260    }
261
262    /// Dart `Card(child:)`.
263    #[cfg_attr(debug_assertions, track_caller)]
264    pub fn child<K>(mut self, child: impl IntoWidget<K>) -> Card {
265        self.child = Some(child.into_widget());
266        self
267    }
268
269    /// Dart `Card(semanticContainer:)`.
270    pub fn semantic_container(mut self, semantic_container: bool) -> Card {
271        self.semantic_container = semantic_container;
272        self
273    }
274}
275
276impl Default for Card {
277    fn default() -> Card {
278        Card::new()
279    }
280}
281
282impl StatelessWidget for Card {
283    fn key(&self) -> Option<&KeyRef> {
284        self.key.as_ref()
285    }
286
287    fn build(&self, app: &mut App, context: BuildContext) -> WidgetRef {
288        let card_theme = CardTheme::of(app, context);
289        let defaults: Box<dyn CardThemeDataGetters> = if Theme::of(app, context).use_material3 {
290            match self.variant {
291                CardVariant::Elevated => Box::new(CardDefaultsM3::new(context)),
292                CardVariant::Filled => Box::new(FilledCardDefaultsM3::new(context)),
293                CardVariant::Outlined => Box::new(OutlinedCardDefaultsM3::new(context)),
294            }
295        } else {
296            Box::new(CardDefaultsM2::new(context))
297        };
298
299        let mut material = Material::new()
300            .r#type(MaterialType::Card)
301            .elevation(
302                self.elevation
303                    .or(card_theme.elevation)
304                    .or_else(|| defaults.elevation(app))
305                    .expect("the defaults give an elevation"),
306            )
307            .border_on_foreground(self.border_on_foreground)
308            .clip_behavior(
309                self.clip_behavior
310                    .or(card_theme.clip_behavior)
311                    .or_else(|| defaults.clip_behavior(app))
312                    .expect("the defaults give a clip behavior"),
313            );
314        material.color = self
315            .color
316            .or(card_theme.color)
317            .or_else(|| defaults.color(app));
318        material.shadow_color = self
319            .shadow_color
320            .or(card_theme.shadow_color)
321            .or_else(|| defaults.shadow_color(app));
322        material.surface_tint_color = self
323            .surface_tint_color
324            .or(card_theme.surface_tint_color)
325            .or_else(|| defaults.surface_tint_color(app));
326        material.shape = self
327            .shape
328            .clone()
329            .or(card_theme.shape)
330            .or_else(|| defaults.shape(app));
331        let mut child_semantics = Semantics::new().explicit_child_nodes(!self.semantic_container);
332        child_semantics.child = self.child.clone();
333        material.child = Some(child_semantics.into_widget());
334
335        Semantics::new()
336            .container(self.semantic_container)
337            .child(
338                Padding::new(
339                    self.margin
340                        .or(card_theme.margin)
341                        .or_else(|| defaults.margin(app))
342                        .expect("the defaults give a margin"),
343                )
344                .child(material),
345            )
346            .into_widget()
347    }
348}
349
350/// Hand coded defaults based on Material Design 2.
351///
352/// Dart's `_CardDefaultsM2`.
353struct CardDefaultsM2 {
354    /// Dart's `super(..)` arguments.
355    card_theme_data: CardThemeData,
356    context: BuildContext,
357}
358
359impl CardDefaultsM2 {
360    fn new(context: BuildContext) -> CardDefaultsM2 {
361        CardDefaultsM2 {
362            card_theme_data: CardThemeData::new()
363                .clip_behavior(Clip::None)
364                .elevation(1.0)
365                .margin(EdgeInsetsGeometry::all(4.0))
366                .shape(RoundedRectangleBorder::new(
367                    BorderSide::NONE,
368                    BorderRadiusGeometry::circular(4.0),
369                )),
370            context,
371        }
372    }
373}
374
375impl CardThemeDataGetters for CardDefaultsM2 {
376    fn card_theme_data(&self) -> &CardThemeData {
377        &self.card_theme_data
378    }
379
380    fn color(&self, app: &mut App) -> Option<Color> {
381        Some(Theme::of(app, self.context).card_color)
382    }
383
384    fn shadow_color(&self, app: &mut App) -> Option<Color> {
385        Some(Theme::of(app, self.context).shadow_color)
386    }
387}
388
389#[cfg(test)]
390pub(crate) mod tests {
391    //! Ported from `test/card_test.dart`; its semantics cases (`semanticContainer`) wait for
392    //! the semantics tree, and its goldens are not ported.
393
394    use waft_embedder::Size;
395    use waft_painting::AlignmentGeometry;
396    use waft_widgets::{Builder, Center, Container, SizedBox, Text};
397
398    use waft_widgets::testing::{WidgetTester, find, test_widgets};
399
400    use super::*;
401    use crate::color_scheme::ColorScheme;
402    use crate::colors::Colors;
403    use crate::scaffold::Scaffold;
404    use crate::theme::Theme;
405    use crate::theme_data::ThemeData;
406    use crate::tooltip::tests::{m2, m3, pump_app};
407
408    /// What a `Card`'s `Material` was given: Dart's `tester.widget<Material>(find.descendant(
409    /// of: find.byType(Card), matching: find.byType(Material)))`.
410    pub(crate) struct CardMaterial {
411        pub(crate) clip_behavior: Clip,
412        pub(crate) elevation: f64,
413        pub(crate) color: Option<Color>,
414        pub(crate) shadow_color: Option<Color>,
415        pub(crate) surface_tint_color: Option<Color>,
416        pub(crate) shape: Option<ShapeBorderRef>,
417    }
418
419    pub(crate) fn card_material(tester: &WidgetTester) -> CardMaterial {
420        let materials =
421            find::descendant(find::by_type::<Card>(), find::by_type::<Material>()).evaluate(tester);
422        assert_eq!(materials.len(), 1, "one Material under the Card");
423        tester.widget(materials[0], |material: &Material| CardMaterial {
424            clip_behavior: material.clip_behavior,
425            elevation: material.elevation,
426            color: material.color,
427            shadow_color: material.shadow_color,
428            surface_tint_color: material.surface_tint_color,
429            shape: material.shape.clone(),
430        })
431    }
432
433    /// Dart's `tester.widget<Padding>(find.descendant(of: find.byType(Card), matching:
434    /// find.byType(Padding)))`, whose padding it returns.
435    pub(crate) fn card_padding(tester: &WidgetTester) -> EdgeInsetsGeometry {
436        let paddings =
437            find::descendant(find::by_type::<Card>(), find::by_type::<Padding>()).evaluate(tester);
438        assert_eq!(paddings.len(), 1, "one Padding under the Card");
439        tester.widget(paddings[0], |padding: &Padding| padding.padding)
440    }
441
442    pub(crate) fn rounded(radius: f64) -> Option<ShapeBorderRef> {
443        Some(ShapeBorderRef::new(RoundedRectangleBorder::new(
444            BorderSide::NONE,
445            BorderRadiusGeometry::circular(radius),
446        )))
447    }
448
449    fn scaffold_with(card: Card) -> impl FnOnce(&mut App) -> WidgetRef {
450        move |_app| Scaffold::new().body(card).into_widget()
451    }
452
453    fn colors_of(theme: fn(&App) -> ThemeData, tester: &WidgetTester) -> ColorScheme {
454        theme(&tester.cell.borrow()).color_scheme
455    }
456
457    #[test]
458    fn material3_card_defaults_elevated_card() {
459        test_widgets(|tester| {
460            let colors = colors_of(m3, tester);
461            pump_app(tester, m3, scaffold_with(Card::new()));
462
463            let padding = card_padding(tester);
464            let material = card_material(tester);
465
466            assert_eq!(material.clip_behavior, Clip::None);
467            assert_eq!(material.elevation, 1.0);
468            assert_eq!(padding, EdgeInsetsGeometry::all(4.0));
469            assert_eq!(material.color, Some(colors.surface_container_low()));
470            assert_eq!(material.shadow_color, Some(colors.shadow()));
471            // Don't use surface tint. Toned surface container is used instead.
472            assert_eq!(material.surface_tint_color, Some(Colors::TRANSPARENT));
473            assert_eq!(material.shape, rounded(12.0));
474        });
475    }
476
477    #[test]
478    fn material3_card_filled_defaults() {
479        test_widgets(|tester| {
480            let colors = colors_of(m3, tester);
481            pump_app(tester, m3, scaffold_with(Card::filled()));
482
483            let padding = card_padding(tester);
484            let material = card_material(tester);
485
486            assert_eq!(material.clip_behavior, Clip::None);
487            assert_eq!(material.elevation, 0.0);
488            assert_eq!(padding, EdgeInsetsGeometry::all(4.0));
489            assert_eq!(material.color, Some(colors.surface_container_highest()));
490            assert_eq!(material.shadow_color, Some(colors.shadow()));
491            assert_eq!(material.surface_tint_color, Some(Colors::TRANSPARENT));
492            assert_eq!(material.shape, rounded(12.0));
493        });
494    }
495
496    #[test]
497    fn material3_card_outlined_defaults() {
498        test_widgets(|tester| {
499            let colors = colors_of(m3, tester);
500            pump_app(tester, m3, scaffold_with(Card::outlined()));
501
502            let padding = card_padding(tester);
503            let material = card_material(tester);
504
505            assert_eq!(material.clip_behavior, Clip::None);
506            assert_eq!(material.elevation, 0.0);
507            assert_eq!(padding, EdgeInsetsGeometry::all(4.0));
508            assert_eq!(material.color, Some(colors.surface()));
509            assert_eq!(material.shadow_color, Some(colors.shadow()));
510            assert_eq!(material.surface_tint_color, Some(Colors::TRANSPARENT));
511            assert_eq!(
512                material.shape,
513                Some(ShapeBorderRef::new(RoundedRectangleBorder::new(
514                    BorderSide {
515                        color: colors.outline_variant(),
516                        ..BorderSide::default()
517                    },
518                    BorderRadiusGeometry::circular(12.0),
519                )))
520            );
521        });
522    }
523
524    #[test]
525    fn material2_card_variants_are_the_elevated_card() {
526        test_widgets(|tester| {
527            for card in [Card::new(), Card::filled(), Card::outlined()] {
528                pump_app(tester, m2, scaffold_with(card));
529
530                let material = card_material(tester);
531                assert_eq!(material.elevation, 1.0);
532                assert_eq!(material.shape, rounded(4.0));
533            }
534        });
535    }
536
537    #[test]
538    fn card_margin() {
539        test_widgets(|tester| {
540            let contents_key = waft_widgets::GlobalKey::new();
541            let contents = |key: &waft_widgets::GlobalKey| {
542                Container::new()
543                    .key(key.clone().into())
544                    .color(Color::new(0xFF00FF00))
545                    .width(100.0)
546                    .height(100.0)
547            };
548
549            tester.pump_widget(
550                Container::new()
551                    .alignment(AlignmentGeometry::TOP_LEFT)
552                    .child(Card::new().child(contents(&contents_key)))
553                    .into_widget(),
554            );
555
556            // Default margin is 4
557            let card = find::by_type::<Card>().evaluate(tester)[0];
558            let rect = tester.get_rect(card);
559            assert_eq!(rect.top_left(), waft_embedder::Offset::ZERO);
560            assert_eq!(rect.size(), Size::new(108.0, 108.0));
561
562            let contents_rect = tester.get_rect(&contents_key);
563            assert_eq!(
564                contents_rect.top_left(),
565                waft_embedder::Offset::new(4.0, 4.0)
566            );
567            assert_eq!(contents_rect.size(), Size::new(100.0, 100.0));
568
569            tester.pump_widget(
570                Container::new()
571                    .alignment(AlignmentGeometry::TOP_LEFT)
572                    .child(
573                        Card::new()
574                            .margin(EdgeInsetsGeometry::ZERO)
575                            .child(contents(&contents_key)),
576                    )
577                    .into_widget(),
578            );
579
580            // Specified margin is zero
581            let card = find::by_type::<Card>().evaluate(tester)[0];
582            let rect = tester.get_rect(card);
583            assert_eq!(rect.top_left(), waft_embedder::Offset::ZERO);
584            assert_eq!(rect.size(), Size::new(100.0, 100.0));
585
586            let contents_rect = tester.get_rect(&contents_key);
587            assert_eq!(contents_rect.top_left(), waft_embedder::Offset::ZERO);
588            assert_eq!(contents_rect.size(), Size::new(100.0, 100.0));
589        });
590    }
591
592    #[test]
593    fn card_clip_behavior_property_passes_through_to_the_material() {
594        test_widgets(|tester| {
595            tester.pump_widget(Card::new().into_widget());
596            assert_eq!(card_material(tester).clip_behavior, Clip::None);
597
598            tester.pump_widget(Card::new().clip_behavior(Clip::AntiAlias).into_widget());
599            assert_eq!(card_material(tester).clip_behavior, Clip::AntiAlias);
600        });
601    }
602
603    #[test]
604    fn card_clip_behavior_property_defers_to_theme_when_null() {
605        test_widgets(|tester| {
606            tester.pump_widget(
607                Builder::new(|app, context| {
608                    let theme_data = Theme::of(app, context);
609                    let card_theme = theme_data
610                        .card_theme
611                        .copy_with()
612                        .clip_behavior(Clip::AntiAliasWithSaveLayer);
613                    Theme::new(
614                        theme_data.copy_with().card_theme(card_theme).build(),
615                        Card::new(),
616                    )
617                    .into_widget()
618                })
619                .into_widget(),
620            );
621            assert_eq!(
622                card_material(tester).clip_behavior,
623                Clip::AntiAliasWithSaveLayer
624            );
625        });
626    }
627
628    #[test]
629    fn card_shadow_color() {
630        test_widgets(|tester| {
631            tester.pump_widget(Card::new().into_widget());
632
633            let card = find::by_type::<Card>().evaluate(tester)[0];
634            assert_eq!(tester.widget(card, |card: &Card| card.shadow_color), None);
635            assert_eq!(
636                card_material(tester).shadow_color,
637                Some(Color::new(0xFF000000))
638            );
639
640            tester.pump_widget(
641                Card::new()
642                    .shadow_color(Colors::RED.primary())
643                    .into_widget(),
644            );
645
646            let card = find::by_type::<Card>().evaluate(tester)[0];
647            assert_eq!(
648                card_material(tester).shadow_color,
649                tester.widget(card, |card: &Card| card.shadow_color)
650            );
651            assert_eq!(
652                card_material(tester).shadow_color,
653                Some(Colors::RED.primary())
654            );
655        });
656    }
657
658    #[test]
659    fn card_renders_at_zero_size() {
660        test_widgets(|tester| {
661            pump_app(tester, m3, |_app| {
662                Center::new()
663                    .child(
664                        SizedBox::shrink()
665                            .child(Scaffold::new().body(Card::new().child(Text::new("X")))),
666                    )
667                    .into_widget()
668            });
669            let x_text = find::text("X").evaluate(tester)[0];
670            let rect = tester.get_rect(x_text);
671            assert!(rect.width() <= 0.0 || rect.height() <= 0.0);
672        });
673    }
674}