1use std::any::Any;
17use std::rc::Rc;
18
19use indexmap::IndexMap;
20
21use waft_animation::{AnimationRef, AnyAnimation};
22use waft_embedder::Locale;
23use waft_embedder::{
24 BlendMode, Clip, Color, FillRule, FilterQuality, ImageFilter, Matrix4, Offset, Paint, Path,
25 PathBuilder, RRect, RSuperellipse, Rect, Size, TextBaseline, rrect_radii_elliptical,
26 rsuperellipse_radii_elliptical, valo,
27};
28use waft_foundation::{
29 App, DiagnosticPropertiesBuilder, DiagnosticsProperty, DoubleProperty, EnumProperty,
30 FlagProperty, FlagsSummary, Handle, Listenable, Listener, OptionRetained, describe_identity,
31};
32use waft_gestures::{
33 PointerCancelEventListener, PointerDownEventListener, PointerEnterEventListener, PointerEvent,
34 PointerExitEventListener, PointerHoverEventListener, PointerMoveEventListener,
35 PointerPanZoomEndEventListener, PointerPanZoomStartEventListener,
36 PointerPanZoomUpdateEventListener, PointerSignalEventListener, PointerUpEventListener,
37};
38use waft_painting::{
39 Alignment, AlignmentGeometry, BorderRadius, BorderRadiusGeometry, BoxFit, BoxPainter, BoxShape,
40 ClipContext, ColorProperty, DecorationRef, ImageConfiguration, ShapeBorderRef, TextDirection,
41 TransformProperty, apply_box_fit, draw_rrect, get_as_translation,
42};
43use waft_services::{MouseCursor, MouseCursorRef, MouseTrackerAnnotation};
44
45use crate::box_::{
46 AnyRenderBox, BoxConstraints, BoxHitTestEntry, BoxHitTestResult, RenderBox, RenderBoxBase,
47 RenderBoxData,
48};
49use crate::image_filter_config::{ImageFilterConfig, ImageFilterContext};
50use crate::layer::{
51 AnnotatedRegionLayer, BackdropFilterLayer, BackdropKey, ClipPathLayer, ClipRRectLayer,
52 ClipRectLayer, ContainerLayer, FollowerLayer, ImageFilterLayer, LayerHandle, LayerLink,
53 LeaderLayer, OffsetLayerMixin, OpacityLayer, TransformLayer,
54};
55use crate::layout_helper::{ChildLayoutHelper, ChildLayouter};
56use crate::object::{
57 AnyRenderObject, Constraints, EmptyParentData, RenderHandle, RenderObject, RenderObjectData,
58 RenderObjectWithChildData, RenderObjectWithChildMixin,
59};
60use crate::painting_context::PaintingContext;
61use crate::pipeline_owner::PipelineOwner;
62use crate::semantics::SemanticsProperties;
63use crate::semantics_annotations::{SemanticsAnnotationsData, SemanticsAnnotationsMixin};
64use crate::view::RenderView;
65use waft_foundation::Ref;
66
67pub trait RenderProxyBoxMixin:
73 RenderObjectWithChildMixin<ChildType = AnyRenderBox> + RenderBox
74{
75 fn setup_parent_data(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject) {
77 if child.parent_data(app).is_none() {
78 child.set_parent_data(app, EmptyParentData);
79 }
80 }
81
82 fn apply_paint_transform(
84 self: RenderHandle<Self>,
85 app: &App,
86 child: AnyRenderObject,
87 transform: &mut Matrix4,
88 ) {
89 let _ = (app, child, transform);
90 }
91
92 fn compute_min_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
94 match self.child(app) {
95 Some(child) => child.get_min_intrinsic_width(app, height),
96 None => 0.0,
97 }
98 }
99
100 fn compute_max_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
102 match self.child(app) {
103 Some(child) => child.get_max_intrinsic_width(app, height),
104 None => 0.0,
105 }
106 }
107
108 fn compute_min_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
110 match self.child(app) {
111 Some(child) => child.get_min_intrinsic_height(app, width),
112 None => 0.0,
113 }
114 }
115
116 fn compute_max_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
118 match self.child(app) {
119 Some(child) => child.get_max_intrinsic_height(app, width),
120 None => 0.0,
121 }
122 }
123
124 fn compute_distance_to_actual_baseline(
126 self: RenderHandle<Self>,
127 app: &mut App,
128 baseline: TextBaseline,
129 ) -> Option<f64> {
130 self.child(app)
131 .and_then(|child| child.get_distance_to_actual_baseline(app, baseline))
132 }
133
134 fn compute_dry_baseline(
136 self: RenderHandle<Self>,
137 app: &mut App,
138 constraints: BoxConstraints,
139 baseline: TextBaseline,
140 ) -> Option<f64> {
141 self.child(app)
142 .and_then(|child| child.get_dry_baseline(app, constraints, baseline))
143 }
144
145 fn compute_dry_layout(
148 self: RenderHandle<Self>,
149 app: &mut App,
150 constraints: BoxConstraints,
151 ) -> Size {
152 match self.child(app) {
153 Some(child) => child.get_dry_layout(app, constraints),
154 None => self.compute_size_for_no_child(app, constraints),
155 }
156 }
157
158 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
160 let constraints = self.constraints(app);
161 let size = match self.child(app) {
162 Some(child) => {
163 child.layout(app, constraints, true);
164 child.size(app)
165 }
166 None => self.compute_size_for_no_child(app, constraints),
167 };
168 self.set_size(app, size);
169 }
170
171 fn compute_size_for_no_child(
173 self: RenderHandle<Self>,
174 _app: &App,
175 constraints: BoxConstraints,
176 ) -> Size {
177 constraints.smallest()
178 }
179
180 fn hit_test_children(
182 self: RenderHandle<Self>,
183 app: &mut App,
184 result: &mut BoxHitTestResult<'_>,
185 position: Offset,
186 ) -> bool {
187 match self.child(app) {
188 Some(child) => child.hit_test(app, result, position),
189 None => false,
190 }
191 }
192
193 fn paint(
195 self: RenderHandle<Self>,
196 app: &mut App,
197 context: &mut PaintingContext,
198 offset: Offset,
199 ) {
200 let Some(child) = self.child(app) else {
201 return;
202 };
203 context.paint_child(app, child.as_object(), offset);
204 }
205}
206
207pub trait RenderProxyBoxWithHitTestBehavior: RenderProxyBoxMixin {
212 fn behavior(self: RenderHandle<Self>, app: &App) -> HitTestBehavior;
215
216 fn hit_test(
218 self: RenderHandle<Self>,
219 app: &mut App,
220 result: &mut BoxHitTestResult<'_>,
221 position: Offset,
222 ) -> bool {
223 let mut hit_target = false;
224 if self.size(app).contains(position) {
225 hit_target = RenderBox::hit_test_children(self, app, result, position)
226 || RenderBox::hit_test_self(self, app, position);
227 if hit_target || self.behavior(app) == HitTestBehavior::Translucent {
228 result.add(BoxHitTestEntry::new(self.as_box(), position).into());
229 }
230 }
231 hit_target
232 }
233
234 fn hit_test_self(self: RenderHandle<Self>, app: &App, _position: Offset) -> bool {
236 self.behavior(app) == HitTestBehavior::Opaque
237 }
238
239 fn debug_fill_properties(
242 self: RenderHandle<Self>,
243 app: &App,
244 properties: &mut DiagnosticPropertiesBuilder,
245 ) {
246 properties.add(
247 EnumProperty::<HitTestBehavior>::new("behavior", Some(self.behavior(app)))
248 .default_value(None),
249 );
250 }
251}
252
253#[derive(Debug, Clone, Copy, PartialEq, Eq)]
255pub enum HitTestBehavior {
256 DeferToChild,
259
260 Opaque,
264
265 Translucent,
268}
269
270impl std::fmt::Display for HitTestBehavior {
272 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
273 write!(
274 f,
275 "HitTestBehavior.{}",
276 waft_foundation::describe_enum(self)
277 )
278 }
279}
280
281fn layer_link_description(app: &App, link: Handle<LayerLink>) -> String {
283 let linked = link.leader(app).is_some();
284 format!(
285 "{}({})",
286 describe_identity("LayerLink", link.id().identity_hash()),
287 if linked { "<linked>" } else { "<dangling>" }
288 )
289}
290
291pub struct RenderConstrainedBoxData {
293 additional_constraints: BoxConstraints,
294}
295
296impl RenderConstrainedBoxData {
297 pub fn new(additional_constraints: BoxConstraints) -> RenderConstrainedBoxData {
299 debug_assert!(additional_constraints.debug_assert_is_valid(false));
300 RenderConstrainedBoxData {
301 additional_constraints,
302 }
303 }
304}
305
306pub trait RenderConstrainedBoxBase: RenderProxyBoxMixin {
315 fn constrained_box_data(self: RenderHandle<Self>, app: &App) -> &RenderConstrainedBoxData;
317
318 fn debug_fill_properties(
321 self: RenderHandle<Self>,
322 app: &App,
323 properties: &mut DiagnosticPropertiesBuilder,
324 ) {
325 properties.add(DiagnosticsProperty::new(
326 "additionalConstraints",
327 self.constrained_box_data(app).additional_constraints,
328 ));
329 }
330
331 fn constrained_box_data_mut(
333 self: RenderHandle<Self>,
334 app: &mut App,
335 ) -> &mut RenderConstrainedBoxData;
336
337 fn additional_constraints(self: RenderHandle<Self>, app: &App) -> BoxConstraints {
339 self.constrained_box_data(app).additional_constraints
340 }
341
342 fn set_additional_constraints(self: RenderHandle<Self>, app: &mut App, value: BoxConstraints) {
344 debug_assert!(value.debug_assert_is_valid(false));
345 if self.constrained_box_data(app).additional_constraints == value {
346 return;
347 }
348 self.constrained_box_data_mut(app).additional_constraints = value;
349 self.mark_needs_layout(app);
350 }
351
352 fn compute_min_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
354 let additional = self.additional_constraints(app);
355 if additional.has_bounded_width() && additional.has_tight_width() {
356 return additional.min_width;
357 }
358 let width = RenderProxyBoxMixin::compute_min_intrinsic_width(self, app, height);
359 debug_assert!(width.is_finite());
360 if !additional.has_infinite_width() {
361 return additional.constrain_width(width);
362 }
363 width
364 }
365
366 fn compute_max_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
368 let additional = self.additional_constraints(app);
369 if additional.has_bounded_width() && additional.has_tight_width() {
370 return additional.min_width;
371 }
372 let width = RenderProxyBoxMixin::compute_max_intrinsic_width(self, app, height);
373 debug_assert!(width.is_finite());
374 if !additional.has_infinite_width() {
375 return additional.constrain_width(width);
376 }
377 width
378 }
379
380 fn compute_min_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
382 let additional = self.additional_constraints(app);
383 if additional.has_bounded_height() && additional.has_tight_height() {
384 return additional.min_height;
385 }
386 let height = RenderProxyBoxMixin::compute_min_intrinsic_height(self, app, width);
387 debug_assert!(height.is_finite());
388 if !additional.has_infinite_height() {
389 return additional.constrain_height(height);
390 }
391 height
392 }
393
394 fn compute_max_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
396 let additional = self.additional_constraints(app);
397 if additional.has_bounded_height() && additional.has_tight_height() {
398 return additional.min_height;
399 }
400 let height = RenderProxyBoxMixin::compute_max_intrinsic_height(self, app, width);
401 debug_assert!(height.is_finite());
402 if !additional.has_infinite_height() {
403 return additional.constrain_height(height);
404 }
405 height
406 }
407
408 fn compute_dry_baseline(
410 self: RenderHandle<Self>,
411 app: &mut App,
412 constraints: BoxConstraints,
413 baseline: TextBaseline,
414 ) -> Option<f64> {
415 let additional = self.additional_constraints(app);
416 self.child(app).and_then(|child| {
417 child.get_dry_baseline(app, additional.enforce(constraints), baseline)
418 })
419 }
420
421 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
423 let constraints = self.constraints(app);
424 let additional = self.additional_constraints(app);
425 if let Some(child) = self.child(app) {
426 child.layout(app, additional.enforce(constraints), true);
427 self.set_size(app, child.size(app));
428 } else {
429 self.set_size(app, additional.enforce(constraints).constrain(Size::ZERO));
430 }
431 }
432
433 fn compute_dry_layout(
435 self: RenderHandle<Self>,
436 app: &mut App,
437 constraints: BoxConstraints,
438 ) -> Size {
439 let additional = self.additional_constraints(app);
440 match self.child(app) {
441 Some(child) => child.get_dry_layout(app, additional.enforce(constraints)),
442 None => additional.enforce(constraints).constrain(Size::ZERO),
443 }
444 }
445}
446
447pub struct RenderConstrainedBox {
451 render_object: RenderObjectData,
452 render_box: RenderBoxData,
453 child: RenderObjectWithChildData<AnyRenderBox>,
454 constrained_box: RenderConstrainedBoxData,
455}
456
457impl RenderConstrainedBox {
458 pub fn new(
462 app: &mut App,
463 additional_constraints: BoxConstraints,
464 child: Option<AnyRenderBox>,
465 ) -> RenderHandle<RenderConstrainedBox> {
466 let this = RenderHandle::new_box(
467 app,
468 RenderConstrainedBox {
469 render_object: RenderObjectData::new(),
470 render_box: RenderBoxData::new(),
471 child: RenderObjectWithChildData::new(),
472 constrained_box: RenderConstrainedBoxData::new(additional_constraints),
473 },
474 );
475 this.set_child(app, child);
476 this
477 }
478}
479
480impl RenderConstrainedBoxBase for RenderConstrainedBox {
481 fn constrained_box_data(self: RenderHandle<Self>, app: &App) -> &RenderConstrainedBoxData {
482 &self.get(app).constrained_box
483 }
484
485 fn constrained_box_data_mut(
486 self: RenderHandle<Self>,
487 app: &mut App,
488 ) -> &mut RenderConstrainedBoxData {
489 &mut self.get_mut(app).constrained_box
490 }
491}
492
493impl RenderObjectWithChildMixin for RenderConstrainedBox {
494 type ChildType = AnyRenderBox;
495
496 fn child_data(self: RenderHandle<Self>, app: &App) -> &RenderObjectWithChildData<AnyRenderBox> {
497 &self.get(app).child
498 }
499
500 fn child_data_mut(
501 self: RenderHandle<Self>,
502 app: &mut App,
503 ) -> &mut RenderObjectWithChildData<AnyRenderBox> {
504 &mut self.get_mut(app).child
505 }
506}
507
508impl RenderProxyBoxMixin for RenderConstrainedBox {}
509
510impl RenderObject for RenderConstrainedBox {
511 crate::render_object_accessors!();
512
513 fn debug_fill_properties(
514 self: RenderHandle<Self>,
515 app: &App,
516 properties: &mut DiagnosticPropertiesBuilder,
517 ) {
518 RenderConstrainedBoxBase::debug_fill_properties(self, app, properties);
519 }
520
521 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
522 RenderConstrainedBoxBase::perform_layout(self, app);
523 }
524
525 fn paint(
526 self: RenderHandle<Self>,
527 app: &mut App,
528 context: &mut PaintingContext,
529 offset: Offset,
530 ) {
531 RenderProxyBoxMixin::paint(self, app, context, offset);
532 }
533
534 fn visit_children(
535 self: RenderHandle<Self>,
536 app: &App,
537 visitor: &mut dyn FnMut(AnyRenderObject),
538 ) {
539 if let Some(child) = self.child(app) {
540 visitor(child.as_object());
541 }
542 }
543}
544
545impl RenderBox for RenderConstrainedBox {
546 crate::render_box_accessors!();
547
548 fn setup_parent_data(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject) {
549 RenderProxyBoxMixin::setup_parent_data(self, app, child);
550 }
551
552 fn apply_paint_transform(
553 self: RenderHandle<Self>,
554 app: &App,
555 child: AnyRenderObject,
556 transform: &mut Matrix4,
557 ) {
558 RenderProxyBoxMixin::apply_paint_transform(self, app, child, transform);
559 }
560
561 fn hit_test_children(
562 self: RenderHandle<Self>,
563 app: &mut App,
564 result: &mut BoxHitTestResult<'_>,
565 position: Offset,
566 ) -> bool {
567 RenderProxyBoxMixin::hit_test_children(self, app, result, position)
568 }
569
570 fn compute_min_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
571 RenderConstrainedBoxBase::compute_min_intrinsic_width(self, app, height)
572 }
573
574 fn compute_max_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
575 RenderConstrainedBoxBase::compute_max_intrinsic_width(self, app, height)
576 }
577
578 fn compute_min_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
579 RenderConstrainedBoxBase::compute_min_intrinsic_height(self, app, width)
580 }
581
582 fn compute_max_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
583 RenderConstrainedBoxBase::compute_max_intrinsic_height(self, app, width)
584 }
585
586 fn compute_distance_to_actual_baseline(
587 self: RenderHandle<Self>,
588 app: &mut App,
589 baseline: TextBaseline,
590 ) -> Option<f64> {
591 RenderProxyBoxMixin::compute_distance_to_actual_baseline(self, app, baseline)
592 }
593
594 fn compute_dry_baseline(
595 self: RenderHandle<Self>,
596 app: &mut App,
597 constraints: BoxConstraints,
598 baseline: TextBaseline,
599 ) -> Option<f64> {
600 RenderConstrainedBoxBase::compute_dry_baseline(self, app, constraints, baseline)
601 }
602
603 fn compute_dry_layout(
604 self: RenderHandle<Self>,
605 app: &mut App,
606 constraints: BoxConstraints,
607 ) -> Size {
608 RenderConstrainedBoxBase::compute_dry_layout(self, app, constraints)
609 }
610}
611
612pub struct RenderOpacity {
622 render_object: RenderObjectData,
623 render_box: RenderBoxData,
624 child: RenderObjectWithChildData<AnyRenderBox>,
625 alpha: i32,
626 opacity: f64,
627}
628
629impl RenderOpacity {
630 pub fn new(app: &mut App, opacity: f64, child: Option<AnyRenderBox>) -> RenderHandle<Self> {
634 debug_assert!((0.0..=1.0).contains(&opacity));
635 let this = RenderHandle::new_box(
636 app,
637 RenderOpacity {
638 render_object: RenderObjectData::new(),
639 render_box: RenderBoxData::new(),
640 child: RenderObjectWithChildData::new(),
641 alpha: Color::get_alpha_from_opacity(opacity),
642 opacity,
643 },
644 );
645 this.set_child(app, child);
646 this
647 }
648
649 pub fn opacity(self: RenderHandle<Self>, app: &App) -> f64 {
658 self.get(app).opacity
659 }
660
661 pub fn set_opacity(self: RenderHandle<Self>, app: &mut App, value: f64) {
663 debug_assert!((0.0..=1.0).contains(&value));
664 if self.get(app).opacity == value {
665 return;
666 }
667 let did_need_compositing = self.always_needs_compositing(app);
668 let this = self.get_mut(app);
669 this.opacity = value;
670 this.alpha = Color::get_alpha_from_opacity(value);
671 if did_need_compositing != self.always_needs_compositing(app) {
672 self.mark_needs_compositing_bits_update(app);
673 }
674 self.mark_needs_composited_layer_update(app);
675 }
676}
677
678impl RenderObjectWithChildMixin for RenderOpacity {
679 type ChildType = AnyRenderBox;
680
681 fn child_data(self: RenderHandle<Self>, app: &App) -> &RenderObjectWithChildData<AnyRenderBox> {
682 &self.get(app).child
683 }
684
685 fn child_data_mut(
686 self: RenderHandle<Self>,
687 app: &mut App,
688 ) -> &mut RenderObjectWithChildData<AnyRenderBox> {
689 &mut self.get_mut(app).child
690 }
691}
692
693impl RenderProxyBoxMixin for RenderOpacity {}
694
695impl RenderObject for RenderOpacity {
696 crate::render_object_accessors!();
697
698 fn debug_fill_properties(
699 self: RenderHandle<Self>,
700 app: &App,
701 properties: &mut DiagnosticPropertiesBuilder,
702 ) {
703 properties.add(DoubleProperty::new("opacity", self.opacity(app)));
704 }
705
706 fn always_needs_compositing(self: RenderHandle<Self>, app: &App) -> bool {
707 self.child(app).is_some() && self.get(app).alpha > 0
708 }
709
710 fn is_repaint_boundary(self: RenderHandle<Self>, app: &App) -> bool {
711 self.always_needs_compositing(app)
712 }
713
714 fn update_composited_layer(
715 self: RenderHandle<Self>,
716 app: &mut App,
717 old_layer: Option<crate::AnyOffsetLayer>,
718 ) -> crate::AnyOffsetLayer {
719 let layer = match old_layer {
720 Some(old) => app
721 .handle::<OpacityLayer>(old.id())
722 .expect("RenderOpacity reuses an OpacityLayer"),
723 None => OpacityLayer::new(app),
724 };
725 layer.set_alpha(app, self.get(app).alpha);
726 layer.as_offset_layer()
727 }
728
729 fn paints_child(self: RenderHandle<Self>, app: &App, child: AnyRenderObject) -> bool {
730 debug_assert!(child.parent(app) == Some(self.as_object()));
731 self.get(app).alpha > 0
732 }
733
734 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
735 RenderProxyBoxMixin::perform_layout(self, app);
736 }
737
738 fn paint(
739 self: RenderHandle<Self>,
740 app: &mut App,
741 context: &mut PaintingContext,
742 offset: Offset,
743 ) {
744 if self.child(app).is_none() || self.get(app).alpha == 0 {
745 return;
746 }
747 RenderProxyBoxMixin::paint(self, app, context, offset);
748 }
749
750 fn visit_children(
751 self: RenderHandle<Self>,
752 app: &App,
753 visitor: &mut dyn FnMut(AnyRenderObject),
754 ) {
755 if let Some(child) = self.child(app) {
756 visitor(child.as_object());
757 }
758 }
759}
760
761impl RenderBox for RenderOpacity {
762 crate::render_box_accessors!();
763
764 fn setup_parent_data(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject) {
765 RenderProxyBoxMixin::setup_parent_data(self, app, child);
766 }
767
768 fn apply_paint_transform(
769 self: RenderHandle<Self>,
770 app: &App,
771 child: AnyRenderObject,
772 transform: &mut Matrix4,
773 ) {
774 RenderProxyBoxMixin::apply_paint_transform(self, app, child, transform);
775 }
776
777 fn hit_test_children(
778 self: RenderHandle<Self>,
779 app: &mut App,
780 result: &mut BoxHitTestResult<'_>,
781 position: Offset,
782 ) -> bool {
783 RenderProxyBoxMixin::hit_test_children(self, app, result, position)
784 }
785
786 fn compute_min_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
787 RenderProxyBoxMixin::compute_min_intrinsic_width(self, app, height)
788 }
789
790 fn compute_max_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
791 RenderProxyBoxMixin::compute_max_intrinsic_width(self, app, height)
792 }
793
794 fn compute_min_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
795 RenderProxyBoxMixin::compute_min_intrinsic_height(self, app, width)
796 }
797
798 fn compute_max_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
799 RenderProxyBoxMixin::compute_max_intrinsic_height(self, app, width)
800 }
801
802 fn compute_distance_to_actual_baseline(
803 self: RenderHandle<Self>,
804 app: &mut App,
805 baseline: TextBaseline,
806 ) -> Option<f64> {
807 RenderProxyBoxMixin::compute_distance_to_actual_baseline(self, app, baseline)
808 }
809
810 fn compute_dry_baseline(
811 self: RenderHandle<Self>,
812 app: &mut App,
813 constraints: BoxConstraints,
814 baseline: TextBaseline,
815 ) -> Option<f64> {
816 RenderProxyBoxMixin::compute_dry_baseline(self, app, constraints, baseline)
817 }
818
819 fn compute_dry_layout(
820 self: RenderHandle<Self>,
821 app: &mut App,
822 constraints: BoxConstraints,
823 ) -> Size {
824 RenderProxyBoxMixin::compute_dry_layout(self, app, constraints)
825 }
826}
827
828pub struct RenderLeaderLayer {
833 render_object: RenderObjectData,
834 render_box: RenderBoxData,
835 child: RenderObjectWithChildData<AnyRenderBox>,
836 link: Ref<LayerLink>,
837 previous_layout_size: Option<Size>,
839}
840
841impl RenderLeaderLayer {
842 pub fn new(
843 app: &mut App,
844 link: Ref<LayerLink>,
845 child: Option<AnyRenderBox>,
846 ) -> RenderHandle<Self> {
847 let this = RenderHandle::new_box(
848 app,
849 RenderLeaderLayer {
850 render_object: RenderObjectData::new(),
851 render_box: RenderBoxData::new(),
852 child: RenderObjectWithChildData::new(),
853 link,
854 previous_layout_size: None,
855 },
856 );
857 this.set_child(app, child);
858 this
859 }
860
861 pub fn link(self: RenderHandle<Self>, app: &App) -> Handle<LayerLink> {
864 self.get(app).link.handle()
865 }
866
867 pub fn set_link(self: RenderHandle<Self>, app: &mut App, value: Ref<LayerLink>) {
869 let link = self.link(app);
870 if link == value {
871 return;
872 }
873 let old = app.get_mut(link);
874 old.leader_size = None;
875 let new = value.handle();
876 self.get_mut(app).link = value;
877 if let Some(size) = self.get(app).previous_layout_size {
878 app.get_mut(new).leader_size = Some(size);
879 }
880 self.mark_needs_paint(app);
881 }
882}
883
884impl RenderObjectWithChildMixin for RenderLeaderLayer {
885 type ChildType = AnyRenderBox;
886
887 fn child_data(self: RenderHandle<Self>, app: &App) -> &RenderObjectWithChildData<AnyRenderBox> {
888 &self.get(app).child
889 }
890
891 fn child_data_mut(
892 self: RenderHandle<Self>,
893 app: &mut App,
894 ) -> &mut RenderObjectWithChildData<AnyRenderBox> {
895 &mut self.get_mut(app).child
896 }
897}
898
899impl RenderProxyBoxMixin for RenderLeaderLayer {}
900
901impl RenderObject for RenderLeaderLayer {
902 crate::render_object_accessors!();
903
904 fn debug_fill_properties(
905 self: RenderHandle<Self>,
906 app: &App,
907 properties: &mut DiagnosticPropertiesBuilder,
908 ) {
909 let link = self.get(app).link.handle();
910 properties.add(DiagnosticsProperty::<String>::new(
911 "link",
912 Some(layer_link_description(app, link)),
913 ));
914 }
915
916 fn always_needs_compositing(self: RenderHandle<Self>, _app: &App) -> bool {
917 true
918 }
919
920 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
921 RenderProxyBoxMixin::perform_layout(self, app);
922 let size = self.size(app);
923 self.get_mut(app).previous_layout_size = Some(size);
924 let link = self.link(app);
925 app.get_mut(link).leader_size = Some(size);
926 }
927
928 fn paint(
929 self: RenderHandle<Self>,
930 app: &mut App,
931 context: &mut PaintingContext,
932 offset: Offset,
933 ) {
934 let link = self.get(app).link.clone();
935 let layer = match self.as_object().layer_as::<LeaderLayer>(app) {
936 None => {
937 let layer = LeaderLayer::new(app, link);
938 layer.set_offset(app, offset);
939 self.as_object()
940 .set_layer(app, Some(layer.as_container_layer()));
941 layer
942 }
943 Some(layer) => {
944 layer.set_link(app, link);
945 layer.set_offset(app, offset);
946 layer
947 }
948 };
949 context.push_layer(
950 app,
951 layer.as_container_layer(),
952 |app, context, offset| {
953 RenderProxyBoxMixin::paint(self, app, context, offset);
954 },
955 Offset::ZERO,
956 None,
957 );
958 }
959
960 fn visit_children(
961 self: RenderHandle<Self>,
962 app: &App,
963 visitor: &mut dyn FnMut(AnyRenderObject),
964 ) {
965 if let Some(child) = self.child(app) {
966 visitor(child.as_object());
967 }
968 }
969}
970
971impl RenderBox for RenderLeaderLayer {
972 crate::render_box_accessors!();
973
974 fn setup_parent_data(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject) {
975 RenderProxyBoxMixin::setup_parent_data(self, app, child);
976 }
977
978 fn apply_paint_transform(
979 self: RenderHandle<Self>,
980 app: &App,
981 child: AnyRenderObject,
982 transform: &mut Matrix4,
983 ) {
984 RenderProxyBoxMixin::apply_paint_transform(self, app, child, transform);
985 }
986
987 fn hit_test_children(
988 self: RenderHandle<Self>,
989 app: &mut App,
990 result: &mut BoxHitTestResult<'_>,
991 position: Offset,
992 ) -> bool {
993 RenderProxyBoxMixin::hit_test_children(self, app, result, position)
994 }
995
996 fn compute_min_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
997 RenderProxyBoxMixin::compute_min_intrinsic_width(self, app, height)
998 }
999
1000 fn compute_max_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
1001 RenderProxyBoxMixin::compute_max_intrinsic_width(self, app, height)
1002 }
1003
1004 fn compute_min_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
1005 RenderProxyBoxMixin::compute_min_intrinsic_height(self, app, width)
1006 }
1007
1008 fn compute_max_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
1009 RenderProxyBoxMixin::compute_max_intrinsic_height(self, app, width)
1010 }
1011
1012 fn compute_distance_to_actual_baseline(
1013 self: RenderHandle<Self>,
1014 app: &mut App,
1015 baseline: TextBaseline,
1016 ) -> Option<f64> {
1017 RenderProxyBoxMixin::compute_distance_to_actual_baseline(self, app, baseline)
1018 }
1019
1020 fn compute_dry_baseline(
1021 self: RenderHandle<Self>,
1022 app: &mut App,
1023 constraints: BoxConstraints,
1024 baseline: TextBaseline,
1025 ) -> Option<f64> {
1026 RenderProxyBoxMixin::compute_dry_baseline(self, app, constraints, baseline)
1027 }
1028
1029 fn compute_dry_layout(
1030 self: RenderHandle<Self>,
1031 app: &mut App,
1032 constraints: BoxConstraints,
1033 ) -> Size {
1034 RenderProxyBoxMixin::compute_dry_layout(self, app, constraints)
1035 }
1036}
1037
1038pub struct RenderFollowerLayer {
1043 render_object: RenderObjectData,
1044 render_box: RenderBoxData,
1045 child: RenderObjectWithChildData<AnyRenderBox>,
1046 link: Ref<LayerLink>,
1047 show_when_unlinked: bool,
1048 offset: Offset,
1049 leader_anchor: Alignment,
1050 follower_anchor: Alignment,
1051}
1052
1053impl RenderFollowerLayer {
1054 pub fn new(
1055 app: &mut App,
1056 link: Ref<LayerLink>,
1057 show_when_unlinked: bool,
1058 offset: Offset,
1059 leader_anchor: Alignment,
1060 follower_anchor: Alignment,
1061 child: Option<AnyRenderBox>,
1062 ) -> RenderHandle<Self> {
1063 let this = RenderHandle::new_box(
1064 app,
1065 RenderFollowerLayer {
1066 render_object: RenderObjectData::new(),
1067 render_box: RenderBoxData::new(),
1068 child: RenderObjectWithChildData::new(),
1069 link,
1070 show_when_unlinked,
1071 offset,
1072 leader_anchor,
1073 follower_anchor,
1074 },
1075 );
1076 this.set_child(app, child);
1077 this
1078 }
1079
1080 pub fn link(self: RenderHandle<Self>, app: &App) -> Handle<LayerLink> {
1082 self.get(app).link.handle()
1083 }
1084
1085 pub fn set_link(self: RenderHandle<Self>, app: &mut App, value: Ref<LayerLink>) {
1087 if self.get(app).link == value {
1088 return;
1089 }
1090 self.get_mut(app).link = value;
1091 self.mark_needs_paint(app);
1092 }
1093
1094 pub fn show_when_unlinked(self: RenderHandle<Self>, app: &App) -> bool {
1097 self.get(app).show_when_unlinked
1098 }
1099
1100 pub fn set_show_when_unlinked(self: RenderHandle<Self>, app: &mut App, value: bool) {
1102 if self.get(app).show_when_unlinked == value {
1103 return;
1104 }
1105 self.get_mut(app).show_when_unlinked = value;
1106 self.mark_needs_paint(app);
1107 }
1108
1109 pub fn offset(self: RenderHandle<Self>, app: &App) -> Offset {
1112 self.get(app).offset
1113 }
1114
1115 pub fn set_offset(self: RenderHandle<Self>, app: &mut App, value: Offset) {
1117 if self.get(app).offset == value {
1118 return;
1119 }
1120 self.get_mut(app).offset = value;
1121 self.mark_needs_paint(app);
1122 }
1123
1124 pub fn leader_anchor(self: RenderHandle<Self>, app: &App) -> Alignment {
1129 self.get(app).leader_anchor
1130 }
1131
1132 pub fn set_leader_anchor(self: RenderHandle<Self>, app: &mut App, value: Alignment) {
1134 if self.get(app).leader_anchor == value {
1135 return;
1136 }
1137 self.get_mut(app).leader_anchor = value;
1138 self.mark_needs_paint(app);
1139 }
1140
1141 pub fn follower_anchor(self: RenderHandle<Self>, app: &App) -> Alignment {
1145 self.get(app).follower_anchor
1146 }
1147
1148 pub fn set_follower_anchor(self: RenderHandle<Self>, app: &mut App, value: Alignment) {
1150 if self.get(app).follower_anchor == value {
1151 return;
1152 }
1153 self.get_mut(app).follower_anchor = value;
1154 self.mark_needs_paint(app);
1155 }
1156
1157 pub fn current_transform(self: RenderHandle<Self>, app: &App) -> Matrix4 {
1162 self.as_object()
1163 .layer_as::<FollowerLayer>(app)
1164 .and_then(|layer| layer.get_last_transform(app))
1165 .unwrap_or(Matrix4::IDENTITY)
1166 }
1167}
1168
1169impl RenderObjectWithChildMixin for RenderFollowerLayer {
1170 type ChildType = AnyRenderBox;
1171
1172 fn child_data(self: RenderHandle<Self>, app: &App) -> &RenderObjectWithChildData<AnyRenderBox> {
1173 &self.get(app).child
1174 }
1175
1176 fn child_data_mut(
1177 self: RenderHandle<Self>,
1178 app: &mut App,
1179 ) -> &mut RenderObjectWithChildData<AnyRenderBox> {
1180 &mut self.get_mut(app).child
1181 }
1182}
1183
1184impl RenderProxyBoxMixin for RenderFollowerLayer {}
1185
1186impl RenderObject for RenderFollowerLayer {
1187 crate::render_object_accessors!();
1188
1189 fn debug_fill_properties(
1190 self: RenderHandle<Self>,
1191 app: &App,
1192 properties: &mut DiagnosticPropertiesBuilder,
1193 ) {
1194 let this = self.get(app);
1195 properties.add(DiagnosticsProperty::<String>::new(
1196 "link",
1197 Some(layer_link_description(app, this.link.handle())),
1198 ));
1199 properties.add(DiagnosticsProperty::<bool>::new(
1200 "showWhenUnlinked",
1201 Some(this.show_when_unlinked),
1202 ));
1203 properties.add(DiagnosticsProperty::<Offset>::new(
1204 "offset",
1205 Some(this.offset),
1206 ));
1207 properties.add(TransformProperty::new(
1208 "current transform matrix",
1209 self.current_transform(app),
1210 ));
1211 }
1212
1213 fn always_needs_compositing(self: RenderHandle<Self>, _app: &App) -> bool {
1214 true
1215 }
1216
1217 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
1218 RenderProxyBoxMixin::perform_layout(self, app);
1219 }
1220
1221 fn did_detach(self: RenderHandle<Self>, app: &mut App) {
1223 self.as_object().set_layer(app, None);
1224 if let Some(child) = self.child(app) {
1225 child.as_object().detach(app);
1226 }
1227 }
1228
1229 fn paint(
1230 self: RenderHandle<Self>,
1231 app: &mut App,
1232 context: &mut PaintingContext,
1233 offset: Offset,
1234 ) {
1235 let link = self.get(app).link.clone();
1236 let leader_size = app.get(&link).leader_size;
1237 debug_assert!(
1238 leader_size.is_some()
1239 || link.leader(app).is_none()
1240 || self.get(app).leader_anchor == Alignment::TOP_LEFT,
1241 "a leader size is required when leader_anchor is not Alignment::TOP_LEFT"
1242 );
1243 let this = self.get(app);
1244 let effective_linked_offset = match leader_size {
1245 None => this.offset,
1246 Some(leader_size) => {
1247 this.leader_anchor.along_size(leader_size)
1248 - this.follower_anchor.along_size(self.size(app))
1249 + this.offset
1250 }
1251 };
1252 let show_when_unlinked = this.show_when_unlinked;
1253 let layer = match self.as_object().layer_as::<FollowerLayer>(app) {
1254 None => {
1255 let layer = FollowerLayer::new(app, link);
1256 layer.set_show_when_unlinked(app, show_when_unlinked);
1257 layer.set_linked_offset(app, effective_linked_offset);
1258 layer.set_unlinked_offset(app, offset);
1259 self.as_object()
1260 .set_layer(app, Some(layer.as_container_layer()));
1261 layer
1262 }
1263 Some(layer) => {
1264 layer.set_link(app, link);
1265 layer.set_show_when_unlinked(app, show_when_unlinked);
1266 layer.set_linked_offset(app, effective_linked_offset);
1267 layer.set_unlinked_offset(app, offset);
1268 layer
1269 }
1270 };
1271 context.push_layer(
1272 app,
1273 layer.as_container_layer(),
1274 |app, context, offset| {
1275 RenderProxyBoxMixin::paint(self, app, context, offset);
1276 },
1277 Offset::ZERO,
1278 Some(Rect::from_ltrb(
1279 f64::NEG_INFINITY,
1280 f64::NEG_INFINITY,
1281 f64::INFINITY,
1282 f64::INFINITY,
1283 )),
1284 );
1285 }
1286
1287 fn visit_children(
1288 self: RenderHandle<Self>,
1289 app: &App,
1290 visitor: &mut dyn FnMut(AnyRenderObject),
1291 ) {
1292 if let Some(child) = self.child(app) {
1293 visitor(child.as_object());
1294 }
1295 }
1296}
1297
1298impl RenderBox for RenderFollowerLayer {
1299 crate::render_box_accessors!();
1300
1301 fn setup_parent_data(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject) {
1302 RenderProxyBoxMixin::setup_parent_data(self, app, child);
1303 }
1304
1305 fn apply_paint_transform(
1306 self: RenderHandle<Self>,
1307 app: &App,
1308 _child: AnyRenderObject,
1309 transform: &mut Matrix4,
1310 ) {
1311 *transform = transform.then(&self.current_transform(app));
1312 }
1313
1314 fn hit_test(
1318 self: RenderHandle<Self>,
1319 app: &mut App,
1320 result: &mut BoxHitTestResult<'_>,
1321 position: Offset,
1322 ) -> bool {
1323 let link = self.get(app).link.handle();
1324 if link.leader(app).is_none() && !self.get(app).show_when_unlinked {
1325 return false;
1326 }
1327 RenderBox::hit_test_children(self, app, result, position)
1328 }
1329
1330 fn hit_test_children(
1331 self: RenderHandle<Self>,
1332 app: &mut App,
1333 result: &mut BoxHitTestResult<'_>,
1334 position: Offset,
1335 ) -> bool {
1336 let transform = self.current_transform(app);
1337 result.add_with_paint_transform(Some(transform), position, |result, position| {
1338 RenderProxyBoxMixin::hit_test_children(self, app, result, position)
1339 })
1340 }
1341
1342 fn compute_min_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
1343 RenderProxyBoxMixin::compute_min_intrinsic_width(self, app, height)
1344 }
1345
1346 fn compute_max_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
1347 RenderProxyBoxMixin::compute_max_intrinsic_width(self, app, height)
1348 }
1349
1350 fn compute_min_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
1351 RenderProxyBoxMixin::compute_min_intrinsic_height(self, app, width)
1352 }
1353
1354 fn compute_max_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
1355 RenderProxyBoxMixin::compute_max_intrinsic_height(self, app, width)
1356 }
1357
1358 fn compute_distance_to_actual_baseline(
1359 self: RenderHandle<Self>,
1360 app: &mut App,
1361 baseline: TextBaseline,
1362 ) -> Option<f64> {
1363 RenderProxyBoxMixin::compute_distance_to_actual_baseline(self, app, baseline)
1364 }
1365
1366 fn compute_dry_baseline(
1367 self: RenderHandle<Self>,
1368 app: &mut App,
1369 constraints: BoxConstraints,
1370 baseline: TextBaseline,
1371 ) -> Option<f64> {
1372 RenderProxyBoxMixin::compute_dry_baseline(self, app, constraints, baseline)
1373 }
1374
1375 fn compute_dry_layout(
1376 self: RenderHandle<Self>,
1377 app: &mut App,
1378 constraints: BoxConstraints,
1379 ) -> Size {
1380 RenderProxyBoxMixin::compute_dry_layout(self, app, constraints)
1381 }
1382}
1383
1384pub struct RenderAnimatedOpacityData {
1386 alpha: Option<i32>,
1387 currently_is_repaint_boundary: Option<bool>,
1388 opacity: Option<AnimationRef<f64>>,
1389}
1390
1391impl RenderAnimatedOpacityData {
1392 pub const fn new() -> RenderAnimatedOpacityData {
1394 RenderAnimatedOpacityData {
1395 alpha: None,
1396 currently_is_repaint_boundary: None,
1397 opacity: None,
1398 }
1399 }
1400}
1401
1402impl Default for RenderAnimatedOpacityData {
1403 fn default() -> RenderAnimatedOpacityData {
1404 RenderAnimatedOpacityData::new()
1405 }
1406}
1407
1408pub trait RenderAnimatedOpacityMixin:
1417 RenderObjectWithChildMixin<ChildType = AnyRenderBox> + RenderBox
1418{
1419 fn animated_opacity_data(self: RenderHandle<Self>, app: &App) -> &RenderAnimatedOpacityData;
1421
1422 fn animated_opacity_data_mut(
1424 self: RenderHandle<Self>,
1425 app: &mut App,
1426 ) -> &mut RenderAnimatedOpacityData;
1427
1428 fn is_repaint_boundary(self: RenderHandle<Self>, app: &App) -> bool {
1430 self.child(app).is_some()
1431 && self
1432 .animated_opacity_data(app)
1433 .currently_is_repaint_boundary
1434 .expect("set by the opacity setter")
1435 }
1436
1437 fn update_composited_layer(
1439 self: RenderHandle<Self>,
1440 app: &mut App,
1441 old_layer: Option<crate::AnyOffsetLayer>,
1442 ) -> crate::AnyOffsetLayer {
1443 let alpha = self
1444 .animated_opacity_data(app)
1445 .alpha
1446 .expect("set by the opacity setter");
1447 let layer = match old_layer {
1448 Some(old) => app
1449 .handle::<OpacityLayer>(old.id())
1450 .expect("RenderAnimatedOpacity reuses an OpacityLayer"),
1451 None => OpacityLayer::new(app),
1452 };
1453 layer.set_alpha(app, alpha);
1454 layer.as_offset_layer()
1455 }
1456
1457 fn opacity(self: RenderHandle<Self>, app: &App) -> AnyAnimation<f64> {
1462 self.animated_opacity_data(app)
1463 .opacity
1464 .handle()
1465 .expect("set by the constructor")
1466 }
1467
1468 fn set_opacity(self: RenderHandle<Self>, app: &mut App, value: AnimationRef<f64>) {
1470 if self.animated_opacity_data(app).opacity.as_ref() == Some(&value) {
1471 return;
1472 }
1473 if self.attached(app)
1474 && let Some(opacity) = self.animated_opacity_data(app).opacity.handle()
1475 {
1476 opacity.remove_listener(app, &self.opacity_listener());
1477 }
1478 let new = value.handle();
1479 let _old = self.animated_opacity_data_mut(app).opacity.replace(value);
1481 if self.attached(app) {
1482 new.add_listener(app, self.opacity_listener());
1483 }
1484 self.update_opacity(app);
1485 }
1486
1487 fn did_attach(self: RenderHandle<Self>, app: &mut App) {
1489 self.opacity(app).add_listener(app, self.opacity_listener());
1490 self.update_opacity(app); }
1492
1493 fn did_detach(self: RenderHandle<Self>, app: &mut App) {
1495 self.opacity(app)
1496 .remove_listener(app, &self.opacity_listener());
1497 }
1498
1499 fn opacity_listener(self: RenderHandle<Self>) -> Listener {
1501 Listener::handle_method(self.handle(), update_opacity::<Self>)
1502 }
1503
1504 fn update_opacity(self: RenderHandle<Self>, app: &mut App) {
1506 let old_alpha = self.animated_opacity_data(app).alpha;
1507 let alpha = Color::get_alpha_from_opacity(self.opacity(app).value(app));
1508 self.animated_opacity_data_mut(app).alpha = Some(alpha);
1509 if old_alpha != Some(alpha) {
1510 let was_repaint_boundary = self
1511 .animated_opacity_data(app)
1512 .currently_is_repaint_boundary;
1513 self.animated_opacity_data_mut(app)
1514 .currently_is_repaint_boundary = Some(alpha > 0);
1515 if self.child(app).is_some() && was_repaint_boundary != Some(alpha > 0) {
1517 self.mark_needs_compositing_bits_update(app);
1518 }
1519 self.mark_needs_composited_layer_update(app);
1520 }
1521 }
1522
1523 fn paints_child(self: RenderHandle<Self>, app: &App, child: AnyRenderObject) -> bool {
1525 debug_assert!(child.parent(app) == Some(self.as_object()));
1526 self.opacity(app).value(app) > 0.0
1527 }
1528
1529 fn paint(self: RenderHandle<Self>, app: &mut App, context: &mut PaintingContext, offset: Offset)
1531 where
1532 Self: RenderProxyBoxMixin,
1533 {
1534 if self.animated_opacity_data(app).alpha == Some(0) {
1535 return;
1536 }
1537 RenderProxyBoxMixin::paint(self, app, context, offset);
1538 }
1539}
1540
1541fn update_opacity<T: RenderAnimatedOpacityMixin>(this: Handle<T>, app: &mut App) {
1542 RenderAnimatedOpacityMixin::update_opacity(RenderHandle::from_handle(this), app);
1543}
1544
1545pub struct RenderAnimatedOpacity {
1550 render_object: RenderObjectData,
1551 render_box: RenderBoxData,
1552 child: RenderObjectWithChildData<AnyRenderBox>,
1553 animated_opacity: RenderAnimatedOpacityData,
1554}
1555
1556impl RenderAnimatedOpacity {
1557 pub fn new(
1559 app: &mut App,
1560 opacity: AnimationRef<f64>,
1561 child: Option<AnyRenderBox>,
1562 ) -> RenderHandle<Self> {
1563 let this = RenderHandle::new_box(
1564 app,
1565 RenderAnimatedOpacity {
1566 render_object: RenderObjectData::new(),
1567 render_box: RenderBoxData::new(),
1568 child: RenderObjectWithChildData::new(),
1569 animated_opacity: RenderAnimatedOpacityData::new(),
1570 },
1571 );
1572 this.set_child(app, child);
1573 this.set_opacity(app, opacity);
1574 this
1575 }
1576}
1577
1578impl RenderObjectWithChildMixin for RenderAnimatedOpacity {
1579 type ChildType = AnyRenderBox;
1580
1581 fn child_data(self: RenderHandle<Self>, app: &App) -> &RenderObjectWithChildData<AnyRenderBox> {
1582 &self.get(app).child
1583 }
1584
1585 fn child_data_mut(
1586 self: RenderHandle<Self>,
1587 app: &mut App,
1588 ) -> &mut RenderObjectWithChildData<AnyRenderBox> {
1589 &mut self.get_mut(app).child
1590 }
1591}
1592
1593impl RenderProxyBoxMixin for RenderAnimatedOpacity {}
1594
1595impl RenderAnimatedOpacityMixin for RenderAnimatedOpacity {
1596 fn animated_opacity_data(self: RenderHandle<Self>, app: &App) -> &RenderAnimatedOpacityData {
1597 &self.get(app).animated_opacity
1598 }
1599
1600 fn animated_opacity_data_mut(
1601 self: RenderHandle<Self>,
1602 app: &mut App,
1603 ) -> &mut RenderAnimatedOpacityData {
1604 &mut self.get_mut(app).animated_opacity
1605 }
1606}
1607
1608impl RenderObject for RenderAnimatedOpacity {
1609 crate::render_object_accessors!();
1610
1611 fn is_repaint_boundary(self: RenderHandle<Self>, app: &App) -> bool {
1612 RenderAnimatedOpacityMixin::is_repaint_boundary(self, app)
1613 }
1614
1615 fn update_composited_layer(
1616 self: RenderHandle<Self>,
1617 app: &mut App,
1618 old_layer: Option<crate::AnyOffsetLayer>,
1619 ) -> crate::AnyOffsetLayer {
1620 RenderAnimatedOpacityMixin::update_composited_layer(self, app, old_layer)
1621 }
1622
1623 fn paints_child(self: RenderHandle<Self>, app: &App, child: AnyRenderObject) -> bool {
1624 RenderAnimatedOpacityMixin::paints_child(self, app, child)
1625 }
1626
1627 fn did_attach(self: RenderHandle<Self>, app: &mut App, owner: Handle<crate::PipelineOwner>) {
1628 if let Some(child) = self.child(app) {
1629 child.as_object().attach(app, owner);
1630 }
1631 RenderAnimatedOpacityMixin::did_attach(self, app);
1632 }
1633
1634 fn did_detach(self: RenderHandle<Self>, app: &mut App) {
1635 RenderAnimatedOpacityMixin::did_detach(self, app);
1636 if let Some(child) = self.child(app) {
1637 child.as_object().detach(app);
1638 }
1639 }
1640
1641 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
1642 RenderProxyBoxMixin::perform_layout(self, app);
1643 }
1644
1645 fn paint(
1646 self: RenderHandle<Self>,
1647 app: &mut App,
1648 context: &mut PaintingContext,
1649 offset: Offset,
1650 ) {
1651 RenderAnimatedOpacityMixin::paint(self, app, context, offset);
1652 }
1653
1654 fn visit_children(
1655 self: RenderHandle<Self>,
1656 app: &App,
1657 visitor: &mut dyn FnMut(AnyRenderObject),
1658 ) {
1659 if let Some(child) = self.child(app) {
1660 visitor(child.as_object());
1661 }
1662 }
1663}
1664
1665impl RenderBox for RenderAnimatedOpacity {
1666 crate::render_box_accessors!();
1667
1668 fn setup_parent_data(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject) {
1669 RenderProxyBoxMixin::setup_parent_data(self, app, child);
1670 }
1671
1672 fn apply_paint_transform(
1673 self: RenderHandle<Self>,
1674 app: &App,
1675 child: AnyRenderObject,
1676 transform: &mut Matrix4,
1677 ) {
1678 RenderProxyBoxMixin::apply_paint_transform(self, app, child, transform);
1679 }
1680
1681 fn hit_test_children(
1682 self: RenderHandle<Self>,
1683 app: &mut App,
1684 result: &mut BoxHitTestResult<'_>,
1685 position: Offset,
1686 ) -> bool {
1687 RenderProxyBoxMixin::hit_test_children(self, app, result, position)
1688 }
1689
1690 fn compute_min_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
1691 RenderProxyBoxMixin::compute_min_intrinsic_width(self, app, height)
1692 }
1693
1694 fn compute_max_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
1695 RenderProxyBoxMixin::compute_max_intrinsic_width(self, app, height)
1696 }
1697
1698 fn compute_min_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
1699 RenderProxyBoxMixin::compute_min_intrinsic_height(self, app, width)
1700 }
1701
1702 fn compute_max_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
1703 RenderProxyBoxMixin::compute_max_intrinsic_height(self, app, width)
1704 }
1705
1706 fn compute_distance_to_actual_baseline(
1707 self: RenderHandle<Self>,
1708 app: &mut App,
1709 baseline: TextBaseline,
1710 ) -> Option<f64> {
1711 RenderProxyBoxMixin::compute_distance_to_actual_baseline(self, app, baseline)
1712 }
1713
1714 fn compute_dry_baseline(
1715 self: RenderHandle<Self>,
1716 app: &mut App,
1717 constraints: BoxConstraints,
1718 baseline: TextBaseline,
1719 ) -> Option<f64> {
1720 RenderProxyBoxMixin::compute_dry_baseline(self, app, constraints, baseline)
1721 }
1722
1723 fn compute_dry_layout(
1724 self: RenderHandle<Self>,
1725 app: &mut App,
1726 constraints: BoxConstraints,
1727 ) -> Size {
1728 RenderProxyBoxMixin::compute_dry_layout(self, app, constraints)
1729 }
1730}
1731
1732pub struct RenderPointerListener {
1744 render_object: RenderObjectData,
1745 render_box: RenderBoxData,
1746 child: RenderObjectWithChildData<AnyRenderBox>,
1747 on_pointer_down: Option<PointerDownEventListener>,
1748 on_pointer_move: Option<PointerMoveEventListener>,
1749 on_pointer_up: Option<PointerUpEventListener>,
1750 on_pointer_hover: Option<PointerHoverEventListener>,
1751 on_pointer_cancel: Option<PointerCancelEventListener>,
1752 on_pointer_pan_zoom_start: Option<PointerPanZoomStartEventListener>,
1753 on_pointer_pan_zoom_update: Option<PointerPanZoomUpdateEventListener>,
1754 on_pointer_pan_zoom_end: Option<PointerPanZoomEndEventListener>,
1755 on_pointer_signal: Option<PointerSignalEventListener>,
1756 behavior: HitTestBehavior,
1757}
1758
1759macro_rules! pointer_listener_field {
1760 ($get:ident, $set:ident, $ty:ty, $doc:expr) => {
1761 #[doc = $doc]
1762 pub fn $get(self: RenderHandle<Self>, app: &App) -> Option<$ty> {
1763 self.get(app).$get.clone()
1764 }
1765
1766 #[doc = concat!("Sets [`", stringify!($get), "`](Self::", stringify!($get), ").")]
1767 pub fn $set(self: RenderHandle<Self>, app: &mut App, value: Option<$ty>) {
1768 self.get_mut(app).$get = value;
1769 }
1770 };
1771}
1772
1773impl RenderPointerListener {
1774 pub fn new(
1779 app: &mut App,
1780 behavior: HitTestBehavior,
1781 child: Option<AnyRenderBox>,
1782 ) -> RenderHandle<Self> {
1783 let this = RenderHandle::new_box(
1784 app,
1785 RenderPointerListener {
1786 render_object: RenderObjectData::new(),
1787 render_box: RenderBoxData::new(),
1788 child: RenderObjectWithChildData::new(),
1789 on_pointer_down: None,
1790 on_pointer_move: None,
1791 on_pointer_up: None,
1792 on_pointer_hover: None,
1793 on_pointer_cancel: None,
1794 on_pointer_pan_zoom_start: None,
1795 on_pointer_pan_zoom_update: None,
1796 on_pointer_pan_zoom_end: None,
1797 on_pointer_signal: None,
1798 behavior,
1799 },
1800 );
1801 this.set_child(app, child);
1802 this
1803 }
1804
1805 pointer_listener_field!(
1806 on_pointer_down,
1807 set_on_pointer_down,
1808 PointerDownEventListener,
1809 "Called when a pointer comes into contact with the screen (for touch pointers), or has its button pressed (for mouse pointers) at this widget's location."
1810 );
1811 pointer_listener_field!(
1812 on_pointer_move,
1813 set_on_pointer_move,
1814 PointerMoveEventListener,
1815 "Called when a pointer that triggered an `on_pointer_down` changes position."
1816 );
1817 pointer_listener_field!(
1818 on_pointer_up,
1819 set_on_pointer_up,
1820 PointerUpEventListener,
1821 "Called when a pointer that triggered an `on_pointer_down` is no longer in contact with the screen."
1822 );
1823 pointer_listener_field!(
1824 on_pointer_hover,
1825 set_on_pointer_hover,
1826 PointerHoverEventListener,
1827 "Called when a pointer that has not an `on_pointer_down` changes position."
1828 );
1829 pointer_listener_field!(
1830 on_pointer_cancel,
1831 set_on_pointer_cancel,
1832 PointerCancelEventListener,
1833 "Called when the input from a pointer that triggered an `on_pointer_down` is no longer directed towards this receiver."
1834 );
1835 pointer_listener_field!(
1836 on_pointer_pan_zoom_start,
1837 set_on_pointer_pan_zoom_start,
1838 PointerPanZoomStartEventListener,
1839 "Called when a pan/zoom begins such as from a trackpad gesture."
1840 );
1841 pointer_listener_field!(
1842 on_pointer_pan_zoom_update,
1843 set_on_pointer_pan_zoom_update,
1844 PointerPanZoomUpdateEventListener,
1845 "Called when a pan/zoom is updated."
1846 );
1847 pointer_listener_field!(
1848 on_pointer_pan_zoom_end,
1849 set_on_pointer_pan_zoom_end,
1850 PointerPanZoomEndEventListener,
1851 "Called when a pan/zoom finishes."
1852 );
1853 pointer_listener_field!(
1854 on_pointer_signal,
1855 set_on_pointer_signal,
1856 PointerSignalEventListener,
1857 "Called when a pointer signal occurs over this object."
1858 );
1859
1860 pub fn set_behavior(self: RenderHandle<Self>, app: &mut App, value: HitTestBehavior) {
1862 self.get_mut(app).behavior = value;
1863 }
1864}
1865
1866impl RenderObjectWithChildMixin for RenderPointerListener {
1867 type ChildType = AnyRenderBox;
1868
1869 fn child_data(self: RenderHandle<Self>, app: &App) -> &RenderObjectWithChildData<AnyRenderBox> {
1870 &self.get(app).child
1871 }
1872
1873 fn child_data_mut(
1874 self: RenderHandle<Self>,
1875 app: &mut App,
1876 ) -> &mut RenderObjectWithChildData<AnyRenderBox> {
1877 &mut self.get_mut(app).child
1878 }
1879}
1880
1881impl RenderProxyBoxMixin for RenderPointerListener {
1882 fn compute_size_for_no_child(
1883 self: RenderHandle<Self>,
1884 _app: &App,
1885 constraints: BoxConstraints,
1886 ) -> Size {
1887 constraints.biggest()
1888 }
1889}
1890
1891impl RenderProxyBoxWithHitTestBehavior for RenderPointerListener {
1892 fn behavior(self: RenderHandle<Self>, app: &App) -> HitTestBehavior {
1893 self.get(app).behavior
1894 }
1895}
1896
1897impl RenderObject for RenderPointerListener {
1898 crate::render_object_accessors!();
1899
1900 fn debug_fill_properties(
1901 self: RenderHandle<Self>,
1902 app: &App,
1903 properties: &mut DiagnosticPropertiesBuilder,
1904 ) {
1905 RenderProxyBoxWithHitTestBehavior::debug_fill_properties(self, app, properties);
1906 let this = self.get(app);
1907 let mut listeners = IndexMap::new();
1908 listeners.insert(
1909 "down".to_string(),
1910 this.on_pointer_down.is_some().then_some(()),
1911 );
1912 listeners.insert(
1913 "move".to_string(),
1914 this.on_pointer_move.is_some().then_some(()),
1915 );
1916 listeners.insert("up".to_string(), this.on_pointer_up.is_some().then_some(()));
1917 listeners.insert(
1918 "hover".to_string(),
1919 this.on_pointer_hover.is_some().then_some(()),
1920 );
1921 listeners.insert(
1922 "cancel".to_string(),
1923 this.on_pointer_cancel.is_some().then_some(()),
1924 );
1925 listeners.insert(
1926 "panZoomStart".to_string(),
1927 this.on_pointer_pan_zoom_start.is_some().then_some(()),
1928 );
1929 listeners.insert(
1930 "panZoomUpdate".to_string(),
1931 this.on_pointer_pan_zoom_update.is_some().then_some(()),
1932 );
1933 listeners.insert(
1934 "panZoomEnd".to_string(),
1935 this.on_pointer_pan_zoom_end.is_some().then_some(()),
1936 );
1937 listeners.insert(
1938 "signal".to_string(),
1939 this.on_pointer_signal.is_some().then_some(()),
1940 );
1941 properties.add(FlagsSummary::<()>::new("listeners", listeners).if_empty("<none>"));
1942 }
1943
1944 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
1945 RenderProxyBoxMixin::perform_layout(self, app);
1946 }
1947
1948 fn paint(
1949 self: RenderHandle<Self>,
1950 app: &mut App,
1951 context: &mut PaintingContext,
1952 offset: Offset,
1953 ) {
1954 RenderProxyBoxMixin::paint(self, app, context, offset);
1955 }
1956
1957 fn visit_children(
1958 self: RenderHandle<Self>,
1959 app: &App,
1960 visitor: &mut dyn FnMut(AnyRenderObject),
1961 ) {
1962 if let Some(child) = self.child(app) {
1963 visitor(child.as_object());
1964 }
1965 }
1966}
1967
1968impl RenderBox for RenderPointerListener {
1969 crate::render_box_accessors!();
1970
1971 fn setup_parent_data(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject) {
1972 RenderProxyBoxMixin::setup_parent_data(self, app, child);
1973 }
1974
1975 fn apply_paint_transform(
1976 self: RenderHandle<Self>,
1977 app: &App,
1978 child: AnyRenderObject,
1979 transform: &mut Matrix4,
1980 ) {
1981 RenderProxyBoxMixin::apply_paint_transform(self, app, child, transform);
1982 }
1983
1984 fn handle_event(
1985 self: RenderHandle<Self>,
1986 app: &mut App,
1987 event: &PointerEvent,
1988 _entry: &BoxHitTestEntry,
1989 ) {
1990 match event {
1991 PointerEvent::Down(event) => {
1992 if let Some(callback) = self.get(app).on_pointer_down.clone() {
1993 callback(app, event.clone());
1994 }
1995 }
1996 PointerEvent::Move(event) => {
1997 if let Some(callback) = self.get(app).on_pointer_move.clone() {
1998 callback(app, event.clone());
1999 }
2000 }
2001 PointerEvent::Up(event) => {
2002 if let Some(callback) = self.get(app).on_pointer_up.clone() {
2003 callback(app, event.clone());
2004 }
2005 }
2006 PointerEvent::Hover(event) => {
2007 if let Some(callback) = self.get(app).on_pointer_hover.clone() {
2008 callback(app, event.clone());
2009 }
2010 }
2011 PointerEvent::Cancel(event) => {
2012 if let Some(callback) = self.get(app).on_pointer_cancel.clone() {
2013 callback(app, event.clone());
2014 }
2015 }
2016 PointerEvent::PanZoomStart(event) => {
2017 if let Some(callback) = self.get(app).on_pointer_pan_zoom_start.clone() {
2018 callback(app, event.clone());
2019 }
2020 }
2021 PointerEvent::PanZoomUpdate(event) => {
2022 if let Some(callback) = self.get(app).on_pointer_pan_zoom_update.clone() {
2023 callback(app, event.clone());
2024 }
2025 }
2026 PointerEvent::PanZoomEnd(event) => {
2027 if let Some(callback) = self.get(app).on_pointer_pan_zoom_end.clone() {
2028 callback(app, event.clone());
2029 }
2030 }
2031 PointerEvent::Scroll(_)
2032 | PointerEvent::ScrollInertiaCancel(_)
2033 | PointerEvent::Scale(_) => {
2034 if let Some(callback) = self.get(app).on_pointer_signal.clone() {
2035 callback(app, event.clone());
2036 }
2037 }
2038 PointerEvent::Added(_)
2039 | PointerEvent::Removed(_)
2040 | PointerEvent::Enter(_)
2041 | PointerEvent::Exit(_) => {}
2042 }
2043 }
2044
2045 fn hit_test(
2046 self: RenderHandle<Self>,
2047 app: &mut App,
2048 result: &mut BoxHitTestResult<'_>,
2049 position: Offset,
2050 ) -> bool {
2051 RenderProxyBoxWithHitTestBehavior::hit_test(self, app, result, position)
2052 }
2053
2054 fn hit_test_self(self: RenderHandle<Self>, app: &App, position: Offset) -> bool {
2055 RenderProxyBoxWithHitTestBehavior::hit_test_self(self, app, position)
2056 }
2057
2058 fn hit_test_children(
2059 self: RenderHandle<Self>,
2060 app: &mut App,
2061 result: &mut BoxHitTestResult<'_>,
2062 position: Offset,
2063 ) -> bool {
2064 RenderProxyBoxMixin::hit_test_children(self, app, result, position)
2065 }
2066
2067 fn compute_min_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
2068 RenderProxyBoxMixin::compute_min_intrinsic_width(self, app, height)
2069 }
2070
2071 fn compute_max_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
2072 RenderProxyBoxMixin::compute_max_intrinsic_width(self, app, height)
2073 }
2074
2075 fn compute_min_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
2076 RenderProxyBoxMixin::compute_min_intrinsic_height(self, app, width)
2077 }
2078
2079 fn compute_max_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
2080 RenderProxyBoxMixin::compute_max_intrinsic_height(self, app, width)
2081 }
2082
2083 fn compute_distance_to_actual_baseline(
2084 self: RenderHandle<Self>,
2085 app: &mut App,
2086 baseline: TextBaseline,
2087 ) -> Option<f64> {
2088 RenderProxyBoxMixin::compute_distance_to_actual_baseline(self, app, baseline)
2089 }
2090
2091 fn compute_dry_baseline(
2092 self: RenderHandle<Self>,
2093 app: &mut App,
2094 constraints: BoxConstraints,
2095 baseline: TextBaseline,
2096 ) -> Option<f64> {
2097 RenderProxyBoxMixin::compute_dry_baseline(self, app, constraints, baseline)
2098 }
2099
2100 fn compute_dry_layout(
2101 self: RenderHandle<Self>,
2102 app: &mut App,
2103 constraints: BoxConstraints,
2104 ) -> Size {
2105 RenderProxyBoxMixin::compute_dry_layout(self, app, constraints)
2106 }
2107}
2108
2109#[derive(Debug, Clone, Copy, PartialEq, Eq)]
2111pub enum DecorationPosition {
2112 Background,
2114
2115 Foreground,
2117}
2118
2119pub struct RenderDecoratedBox {
2121 render_object: RenderObjectData,
2122 render_box: RenderBoxData,
2123 child: RenderObjectWithChildData<AnyRenderBox>,
2124 painter: Option<Box<dyn BoxPainter>>,
2125 decoration: DecorationRef,
2126 position: DecorationPosition,
2127 configuration: ImageConfiguration,
2128}
2129
2130impl RenderDecoratedBox {
2131 pub fn new(
2135 app: &mut App,
2136 decoration: DecorationRef,
2137 position: DecorationPosition,
2138 configuration: ImageConfiguration,
2139 child: Option<AnyRenderBox>,
2140 ) -> RenderHandle<Self> {
2141 let this = RenderHandle::new_box(
2142 app,
2143 RenderDecoratedBox {
2144 render_object: RenderObjectData::new(),
2145 render_box: RenderBoxData::new(),
2146 child: RenderObjectWithChildData::new(),
2147 painter: None,
2148 decoration,
2149 position,
2150 configuration,
2151 },
2152 );
2153 this.set_child(app, child);
2154 this
2155 }
2156
2157 pub fn decoration(self: RenderHandle<Self>, app: &App) -> &DecorationRef {
2159 &self.get(app).decoration
2160 }
2161
2162 pub fn set_decoration(self: RenderHandle<Self>, app: &mut App, value: DecorationRef) {
2164 if value == self.get(app).decoration {
2165 return;
2166 }
2167 let this = self.get_mut(app);
2168 if let Some(mut painter) = this.painter.take() {
2169 painter.dispose();
2170 }
2171 this.decoration = value;
2172 self.mark_needs_paint(app);
2173 }
2174
2175 pub fn position(self: RenderHandle<Self>, app: &App) -> DecorationPosition {
2177 self.get(app).position
2178 }
2179
2180 pub fn set_position(self: RenderHandle<Self>, app: &mut App, value: DecorationPosition) {
2182 if self.get(app).position == value {
2183 return;
2184 }
2185 self.get_mut(app).position = value;
2186 self.mark_needs_paint(app);
2187 }
2188
2189 pub fn configuration(self: RenderHandle<Self>, app: &App) -> &ImageConfiguration {
2192 &self.get(app).configuration
2193 }
2194
2195 pub fn set_configuration(self: RenderHandle<Self>, app: &mut App, value: ImageConfiguration) {
2197 if self.get(app).configuration == value {
2198 return;
2199 }
2200 self.get_mut(app).configuration = value;
2201 self.mark_needs_paint(app);
2202 }
2203
2204 fn paint_decoration(
2205 self: RenderHandle<Self>,
2206 app: &mut App,
2207 context: &mut PaintingContext,
2208 offset: Offset,
2209 configuration: &ImageConfiguration,
2210 ) {
2211 let debug_save_count = context.canvas().save_count();
2212 let is_complex = {
2213 let this = self.get_mut(app);
2214 let painter = this.painter.get_or_insert_with(|| {
2215 this.decoration
2216 .create_box_painter(Some(Rc::new(move |app| self.mark_needs_paint(app))))
2217 });
2218 painter.paint(context.canvas(), offset, configuration);
2219 this.decoration.is_complex()
2220 };
2221 debug_assert_eq!(
2222 debug_save_count,
2223 context.canvas().save_count(),
2224 "the decoration's painter had mismatching save and restore calls"
2225 );
2226 if is_complex {
2227 context.set_is_complex_hint();
2228 }
2229 }
2230}
2231
2232impl RenderObjectWithChildMixin for RenderDecoratedBox {
2233 type ChildType = AnyRenderBox;
2234
2235 fn child_data(self: RenderHandle<Self>, app: &App) -> &RenderObjectWithChildData<AnyRenderBox> {
2236 &self.get(app).child
2237 }
2238
2239 fn child_data_mut(
2240 self: RenderHandle<Self>,
2241 app: &mut App,
2242 ) -> &mut RenderObjectWithChildData<AnyRenderBox> {
2243 &mut self.get_mut(app).child
2244 }
2245}
2246
2247impl RenderProxyBoxMixin for RenderDecoratedBox {}
2248
2249impl RenderObject for RenderDecoratedBox {
2250 crate::render_object_accessors!();
2251
2252 fn debug_fill_properties(
2253 self: RenderHandle<Self>,
2254 app: &App,
2255 properties: &mut DiagnosticPropertiesBuilder,
2256 ) {
2257 let this = self.get(app);
2258 properties.add(
2259 this.decoration
2260 .diagnostics_node(Some("decoration".to_string())),
2261 );
2262 properties.add(DiagnosticsProperty::<ImageConfiguration>::new(
2263 "configuration",
2264 Some(this.configuration.clone()),
2265 ));
2266 }
2267
2268 fn did_detach(self: RenderHandle<Self>, app: &mut App) {
2269 if let Some(mut painter) = self.get_mut(app).painter.take() {
2270 painter.dispose();
2271 }
2272 if let Some(child) = self.child(app) {
2273 child.as_object().detach(app);
2274 }
2275 self.mark_needs_paint(app);
2276 }
2277
2278 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
2279 RenderProxyBoxMixin::perform_layout(self, app);
2280 }
2281
2282 fn paint(
2283 self: RenderHandle<Self>,
2284 app: &mut App,
2285 context: &mut PaintingContext,
2286 offset: Offset,
2287 ) {
2288 let size = self.size(app);
2289 let filled_configuration =
2290 self.get(app)
2291 .configuration
2292 .copy_with(None, None, None, None, Some(size), None);
2293 if self.get(app).position == DecorationPosition::Background {
2294 self.paint_decoration(app, context, offset, &filled_configuration);
2295 }
2296 RenderProxyBoxMixin::paint(self, app, context, offset);
2297 if self.get(app).position == DecorationPosition::Foreground {
2298 self.paint_decoration(app, context, offset, &filled_configuration);
2299 }
2300 }
2301
2302 fn visit_children(
2303 self: RenderHandle<Self>,
2304 app: &App,
2305 visitor: &mut dyn FnMut(AnyRenderObject),
2306 ) {
2307 if let Some(child) = self.child(app) {
2308 visitor(child.as_object());
2309 }
2310 }
2311}
2312
2313impl RenderBox for RenderDecoratedBox {
2314 crate::render_box_accessors!();
2315
2316 fn hit_test_self(self: RenderHandle<Self>, app: &App, position: Offset) -> bool {
2317 let this = self.get(app);
2318 this.decoration
2319 .hit_test(self.size(app), position, this.configuration.text_direction)
2320 }
2321
2322 fn setup_parent_data(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject) {
2323 RenderProxyBoxMixin::setup_parent_data(self, app, child);
2324 }
2325
2326 fn apply_paint_transform(
2327 self: RenderHandle<Self>,
2328 app: &App,
2329 child: AnyRenderObject,
2330 transform: &mut Matrix4,
2331 ) {
2332 RenderProxyBoxMixin::apply_paint_transform(self, app, child, transform);
2333 }
2334
2335 fn hit_test_children(
2336 self: RenderHandle<Self>,
2337 app: &mut App,
2338 result: &mut BoxHitTestResult<'_>,
2339 position: Offset,
2340 ) -> bool {
2341 RenderProxyBoxMixin::hit_test_children(self, app, result, position)
2342 }
2343
2344 fn compute_min_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
2345 RenderProxyBoxMixin::compute_min_intrinsic_width(self, app, height)
2346 }
2347
2348 fn compute_max_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
2349 RenderProxyBoxMixin::compute_max_intrinsic_width(self, app, height)
2350 }
2351
2352 fn compute_min_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
2353 RenderProxyBoxMixin::compute_min_intrinsic_height(self, app, width)
2354 }
2355
2356 fn compute_max_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
2357 RenderProxyBoxMixin::compute_max_intrinsic_height(self, app, width)
2358 }
2359
2360 fn compute_distance_to_actual_baseline(
2361 self: RenderHandle<Self>,
2362 app: &mut App,
2363 baseline: TextBaseline,
2364 ) -> Option<f64> {
2365 RenderProxyBoxMixin::compute_distance_to_actual_baseline(self, app, baseline)
2366 }
2367
2368 fn compute_dry_baseline(
2369 self: RenderHandle<Self>,
2370 app: &mut App,
2371 constraints: BoxConstraints,
2372 baseline: TextBaseline,
2373 ) -> Option<f64> {
2374 RenderProxyBoxMixin::compute_dry_baseline(self, app, constraints, baseline)
2375 }
2376
2377 fn compute_dry_layout(
2378 self: RenderHandle<Self>,
2379 app: &mut App,
2380 constraints: BoxConstraints,
2381 ) -> Size {
2382 RenderProxyBoxMixin::compute_dry_layout(self, app, constraints)
2383 }
2384}
2385
2386pub struct RenderRepaintBoundary {
2392 render_object: RenderObjectData,
2393 render_box: RenderBoxData,
2394 child: RenderObjectWithChildData<AnyRenderBox>,
2395}
2396
2397impl RenderRepaintBoundary {
2398 pub fn new(app: &mut App, child: Option<AnyRenderBox>) -> RenderHandle<Self> {
2400 let this = RenderHandle::new_box(
2401 app,
2402 RenderRepaintBoundary {
2403 render_object: RenderObjectData::new(),
2404 render_box: RenderBoxData::new(),
2405 child: RenderObjectWithChildData::new(),
2406 },
2407 );
2408 this.set_child(app, child);
2409 this
2410 }
2411}
2412
2413impl RenderObjectWithChildMixin for RenderRepaintBoundary {
2414 type ChildType = AnyRenderBox;
2415
2416 fn child_data(self: RenderHandle<Self>, app: &App) -> &RenderObjectWithChildData<AnyRenderBox> {
2417 &self.get(app).child
2418 }
2419
2420 fn child_data_mut(
2421 self: RenderHandle<Self>,
2422 app: &mut App,
2423 ) -> &mut RenderObjectWithChildData<AnyRenderBox> {
2424 &mut self.get_mut(app).child
2425 }
2426}
2427
2428impl RenderProxyBoxMixin for RenderRepaintBoundary {}
2429
2430impl RenderObject for RenderRepaintBoundary {
2431 crate::render_object_accessors!();
2432
2433 fn is_repaint_boundary(self: RenderHandle<Self>, _app: &App) -> bool {
2434 true
2435 }
2436
2437 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
2438 RenderProxyBoxMixin::perform_layout(self, app);
2439 }
2440
2441 fn paint(
2442 self: RenderHandle<Self>,
2443 app: &mut App,
2444 context: &mut PaintingContext,
2445 offset: Offset,
2446 ) {
2447 RenderProxyBoxMixin::paint(self, app, context, offset);
2448 }
2449
2450 fn visit_children(
2451 self: RenderHandle<Self>,
2452 app: &App,
2453 visitor: &mut dyn FnMut(AnyRenderObject),
2454 ) {
2455 if let Some(child) = self.child(app) {
2456 visitor(child.as_object());
2457 }
2458 }
2459}
2460
2461impl RenderBox for RenderRepaintBoundary {
2462 crate::render_box_accessors!();
2463
2464 fn setup_parent_data(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject) {
2465 RenderProxyBoxMixin::setup_parent_data(self, app, child);
2466 }
2467
2468 fn apply_paint_transform(
2469 self: RenderHandle<Self>,
2470 app: &App,
2471 child: AnyRenderObject,
2472 transform: &mut Matrix4,
2473 ) {
2474 RenderProxyBoxMixin::apply_paint_transform(self, app, child, transform);
2475 }
2476
2477 fn hit_test_children(
2478 self: RenderHandle<Self>,
2479 app: &mut App,
2480 result: &mut BoxHitTestResult<'_>,
2481 position: Offset,
2482 ) -> bool {
2483 RenderProxyBoxMixin::hit_test_children(self, app, result, position)
2484 }
2485
2486 fn compute_min_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
2487 RenderProxyBoxMixin::compute_min_intrinsic_width(self, app, height)
2488 }
2489
2490 fn compute_max_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
2491 RenderProxyBoxMixin::compute_max_intrinsic_width(self, app, height)
2492 }
2493
2494 fn compute_min_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
2495 RenderProxyBoxMixin::compute_min_intrinsic_height(self, app, width)
2496 }
2497
2498 fn compute_max_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
2499 RenderProxyBoxMixin::compute_max_intrinsic_height(self, app, width)
2500 }
2501
2502 fn compute_distance_to_actual_baseline(
2503 self: RenderHandle<Self>,
2504 app: &mut App,
2505 baseline: TextBaseline,
2506 ) -> Option<f64> {
2507 RenderProxyBoxMixin::compute_distance_to_actual_baseline(self, app, baseline)
2508 }
2509
2510 fn compute_dry_baseline(
2511 self: RenderHandle<Self>,
2512 app: &mut App,
2513 constraints: BoxConstraints,
2514 baseline: TextBaseline,
2515 ) -> Option<f64> {
2516 RenderProxyBoxMixin::compute_dry_baseline(self, app, constraints, baseline)
2517 }
2518
2519 fn compute_dry_layout(
2520 self: RenderHandle<Self>,
2521 app: &mut App,
2522 constraints: BoxConstraints,
2523 ) -> Size {
2524 RenderProxyBoxMixin::compute_dry_layout(self, app, constraints)
2525 }
2526}
2527
2528pub struct RenderMouseRegionData {
2530 on_enter: Option<PointerEnterEventListener>,
2531 on_hover: Option<PointerHoverEventListener>,
2532 on_exit: Option<PointerExitEventListener>,
2533 cursor: MouseCursorRef,
2534 valid_for_mouse_tracker: bool,
2535 opaque: bool,
2536 behavior: HitTestBehavior,
2537}
2538
2539impl RenderMouseRegionData {
2540 pub fn new(valid_for_mouse_tracker: bool) -> RenderMouseRegionData {
2544 RenderMouseRegionData {
2545 on_enter: None,
2546 on_hover: None,
2547 on_exit: None,
2548 cursor: <dyn MouseCursor>::defer(),
2549 valid_for_mouse_tracker,
2550 opaque: true,
2551 behavior: HitTestBehavior::Opaque,
2552 }
2553 }
2554
2555 pub fn behavior(&self) -> HitTestBehavior {
2558 self.behavior
2559 }
2560}
2561
2562pub trait RenderMouseRegionBase:
2571 RenderProxyBoxWithHitTestBehavior + RenderObjectWithChildMixin<ChildType = AnyRenderBox>
2572{
2573 fn mouse_region_data(self: RenderHandle<Self>, app: &App) -> &RenderMouseRegionData;
2575
2576 fn debug_fill_properties(
2579 self: RenderHandle<Self>,
2580 app: &App,
2581 properties: &mut DiagnosticPropertiesBuilder,
2582 ) {
2583 RenderProxyBoxWithHitTestBehavior::debug_fill_properties(self, app, properties);
2584 let data = self.mouse_region_data(app);
2585 let mut listeners = IndexMap::new();
2586 listeners.insert("enter".to_string(), data.on_enter.is_some().then_some(()));
2587 listeners.insert("hover".to_string(), data.on_hover.is_some().then_some(()));
2588 listeners.insert("exit".to_string(), data.on_exit.is_some().then_some(()));
2589 properties.add(FlagsSummary::<()>::new("listeners", listeners).if_empty("<none>"));
2590 properties.add(
2591 DiagnosticsProperty::<String>::new("cursor", Some(data.cursor.debug_description()))
2592 .default_value(Some("defer".to_string())),
2593 );
2594 properties.add(
2595 DiagnosticsProperty::<bool>::new("opaque", Some(data.opaque)).default_value(Some(true)),
2596 );
2597 properties.add(
2598 FlagProperty::new("validForMouseTracker", Some(data.valid_for_mouse_tracker))
2599 .default_value(Some(true))
2600 .if_false("invalid for MouseTracker"),
2601 );
2602 }
2603
2604 fn mouse_region_data_mut(self: RenderHandle<Self>, app: &mut App)
2606 -> &mut RenderMouseRegionData;
2607
2608 fn opaque(self: RenderHandle<Self>, app: &App) -> bool {
2623 self.mouse_region_data(app).opaque
2624 }
2625
2626 fn set_opaque(self: RenderHandle<Self>, app: &mut App, value: bool) {
2628 if self.mouse_region_data(app).opaque != value {
2629 self.mouse_region_data_mut(app).opaque = value;
2630 self.mark_needs_paint(app);
2632 }
2633 }
2634
2635 fn hit_test_behavior(self: RenderHandle<Self>, app: &App) -> Option<HitTestBehavior> {
2639 Some(self.mouse_region_data(app).behavior)
2640 }
2641
2642 fn set_hit_test_behavior(
2644 self: RenderHandle<Self>,
2645 app: &mut App,
2646 value: Option<HitTestBehavior>,
2647 ) {
2648 let new_value = value.unwrap_or(HitTestBehavior::Opaque);
2649 if self.mouse_region_data(app).behavior != new_value {
2650 self.mouse_region_data_mut(app).behavior = new_value;
2651 self.mark_needs_paint(app);
2653 }
2654 }
2655
2656 fn on_enter(self: RenderHandle<Self>, app: &App) -> Option<PointerEnterEventListener> {
2658 self.mouse_region_data(app).on_enter.clone()
2659 }
2660
2661 fn set_on_enter(
2663 self: RenderHandle<Self>,
2664 app: &mut App,
2665 value: Option<PointerEnterEventListener>,
2666 ) {
2667 self.mouse_region_data_mut(app).on_enter = value;
2668 }
2669
2670 fn on_hover(self: RenderHandle<Self>, app: &App) -> Option<PointerHoverEventListener> {
2672 self.mouse_region_data(app).on_hover.clone()
2673 }
2674
2675 fn set_on_hover(
2677 self: RenderHandle<Self>,
2678 app: &mut App,
2679 value: Option<PointerHoverEventListener>,
2680 ) {
2681 self.mouse_region_data_mut(app).on_hover = value;
2682 }
2683
2684 fn on_exit(self: RenderHandle<Self>, app: &App) -> Option<PointerExitEventListener> {
2686 self.mouse_region_data(app).on_exit.clone()
2687 }
2688
2689 fn set_on_exit(
2691 self: RenderHandle<Self>,
2692 app: &mut App,
2693 value: Option<PointerExitEventListener>,
2694 ) {
2695 self.mouse_region_data_mut(app).on_exit = value;
2696 }
2697
2698 fn cursor(self: RenderHandle<Self>, app: &App) -> MouseCursorRef {
2707 Rc::clone(&self.mouse_region_data(app).cursor)
2708 }
2709
2710 fn set_cursor(self: RenderHandle<Self>, app: &mut App, value: MouseCursorRef) {
2712 if *self.mouse_region_data(app).cursor != *value {
2713 self.mouse_region_data_mut(app).cursor = value;
2714 self.mark_needs_paint(app);
2717 }
2718 }
2719
2720 fn valid_for_mouse_tracker(self: RenderHandle<Self>, app: &App) -> bool {
2723 self.mouse_region_data(app).valid_for_mouse_tracker
2724 }
2725
2726 fn did_attach(self: RenderHandle<Self>, app: &mut App, owner: Handle<PipelineOwner>) {
2728 for child in [self.child(app)].into_iter().flatten() {
2729 child.as_object().attach(app, owner);
2730 }
2731 self.mouse_region_data_mut(app).valid_for_mouse_tracker = true;
2732 }
2733
2734 fn did_detach(self: RenderHandle<Self>, app: &mut App) {
2736 self.mouse_region_data_mut(app).valid_for_mouse_tracker = false;
2738 for child in [self.child(app)].into_iter().flatten() {
2739 child.as_object().detach(app);
2740 }
2741 }
2742
2743 fn mouse_tracker_annotation(
2746 self: RenderHandle<Self>,
2747 app: &App,
2748 ) -> Option<MouseTrackerAnnotation> {
2749 let data = self.mouse_region_data(app);
2750 Some(MouseTrackerAnnotation {
2751 on_enter: data.on_enter.clone(),
2752 on_exit: data.on_exit.clone(),
2753 cursor: Rc::clone(&data.cursor),
2754 valid_for_mouse_tracker: data.valid_for_mouse_tracker,
2755 })
2756 }
2757
2758 fn hit_test(
2760 self: RenderHandle<Self>,
2761 app: &mut App,
2762 result: &mut BoxHitTestResult<'_>,
2763 position: Offset,
2764 ) -> bool {
2765 RenderProxyBoxWithHitTestBehavior::hit_test(self, app, result, position)
2766 && self.mouse_region_data(app).opaque
2767 }
2768
2769 fn handle_event(self: RenderHandle<Self>, app: &mut App, event: &PointerEvent) {
2771 if let PointerEvent::Hover(event) = event
2772 && let Some(on_hover) = self.mouse_region_data(app).on_hover.clone()
2773 {
2774 on_hover(app, event.clone());
2775 }
2776 }
2777}
2778
2779pub struct RenderMouseRegion {
2802 render_object: RenderObjectData,
2803 render_box: RenderBoxData,
2804 child: RenderObjectWithChildData<AnyRenderBox>,
2805 mouse_region: RenderMouseRegionData,
2806}
2807
2808impl RenderMouseRegion {
2809 pub fn new(
2815 app: &mut App,
2816 valid_for_mouse_tracker: bool,
2817 child: Option<AnyRenderBox>,
2818 ) -> RenderHandle<Self> {
2819 let this = RenderHandle::new_box(
2820 app,
2821 RenderMouseRegion {
2822 render_object: RenderObjectData::new(),
2823 render_box: RenderBoxData::new(),
2824 child: RenderObjectWithChildData::new(),
2825 mouse_region: RenderMouseRegionData::new(valid_for_mouse_tracker),
2826 },
2827 );
2828 this.set_child(app, child);
2829 this
2830 }
2831}
2832
2833impl RenderMouseRegionBase for RenderMouseRegion {
2834 fn mouse_region_data(self: RenderHandle<Self>, app: &App) -> &RenderMouseRegionData {
2835 &self.get(app).mouse_region
2836 }
2837
2838 fn mouse_region_data_mut(
2839 self: RenderHandle<Self>,
2840 app: &mut App,
2841 ) -> &mut RenderMouseRegionData {
2842 &mut self.get_mut(app).mouse_region
2843 }
2844}
2845
2846impl RenderObjectWithChildMixin for RenderMouseRegion {
2847 type ChildType = AnyRenderBox;
2848
2849 fn child_data(self: RenderHandle<Self>, app: &App) -> &RenderObjectWithChildData<AnyRenderBox> {
2850 &self.get(app).child
2851 }
2852
2853 fn child_data_mut(
2854 self: RenderHandle<Self>,
2855 app: &mut App,
2856 ) -> &mut RenderObjectWithChildData<AnyRenderBox> {
2857 &mut self.get_mut(app).child
2858 }
2859}
2860
2861impl RenderProxyBoxMixin for RenderMouseRegion {
2862 fn compute_size_for_no_child(
2863 self: RenderHandle<Self>,
2864 _app: &App,
2865 constraints: BoxConstraints,
2866 ) -> Size {
2867 constraints.biggest()
2868 }
2869}
2870
2871impl RenderProxyBoxWithHitTestBehavior for RenderMouseRegion {
2872 fn behavior(self: RenderHandle<Self>, app: &App) -> HitTestBehavior {
2873 self.mouse_region_data(app).behavior
2874 }
2875}
2876
2877impl RenderObject for RenderMouseRegion {
2878 crate::render_object_accessors!();
2879
2880 fn debug_fill_properties(
2881 self: RenderHandle<Self>,
2882 app: &App,
2883 properties: &mut DiagnosticPropertiesBuilder,
2884 ) {
2885 RenderMouseRegionBase::debug_fill_properties(self, app, properties);
2886 }
2887
2888 fn did_attach(self: RenderHandle<Self>, app: &mut App, owner: Handle<PipelineOwner>) {
2889 RenderMouseRegionBase::did_attach(self, app, owner);
2890 }
2891
2892 fn did_detach(self: RenderHandle<Self>, app: &mut App) {
2893 RenderMouseRegionBase::did_detach(self, app);
2894 }
2895
2896 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
2897 RenderProxyBoxMixin::perform_layout(self, app);
2898 }
2899
2900 fn mouse_tracker_annotation(
2901 self: RenderHandle<Self>,
2902 app: &App,
2903 ) -> Option<MouseTrackerAnnotation> {
2904 RenderMouseRegionBase::mouse_tracker_annotation(self, app)
2905 }
2906
2907 fn paint(
2908 self: RenderHandle<Self>,
2909 app: &mut App,
2910 context: &mut PaintingContext,
2911 offset: Offset,
2912 ) {
2913 RenderProxyBoxMixin::paint(self, app, context, offset);
2914 }
2915
2916 fn visit_children(
2917 self: RenderHandle<Self>,
2918 app: &App,
2919 visitor: &mut dyn FnMut(AnyRenderObject),
2920 ) {
2921 if let Some(child) = self.child(app) {
2922 visitor(child.as_object());
2923 }
2924 }
2925}
2926
2927impl RenderBox for RenderMouseRegion {
2928 crate::render_box_accessors!();
2929
2930 fn setup_parent_data(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject) {
2931 RenderProxyBoxMixin::setup_parent_data(self, app, child);
2932 }
2933
2934 fn apply_paint_transform(
2935 self: RenderHandle<Self>,
2936 app: &App,
2937 child: AnyRenderObject,
2938 transform: &mut Matrix4,
2939 ) {
2940 RenderProxyBoxMixin::apply_paint_transform(self, app, child, transform);
2941 }
2942
2943 fn hit_test(
2944 self: RenderHandle<Self>,
2945 app: &mut App,
2946 result: &mut BoxHitTestResult<'_>,
2947 position: Offset,
2948 ) -> bool {
2949 RenderMouseRegionBase::hit_test(self, app, result, position)
2950 }
2951
2952 fn hit_test_self(self: RenderHandle<Self>, app: &App, position: Offset) -> bool {
2953 RenderProxyBoxWithHitTestBehavior::hit_test_self(self, app, position)
2954 }
2955
2956 fn hit_test_children(
2957 self: RenderHandle<Self>,
2958 app: &mut App,
2959 result: &mut BoxHitTestResult<'_>,
2960 position: Offset,
2961 ) -> bool {
2962 RenderProxyBoxMixin::hit_test_children(self, app, result, position)
2963 }
2964
2965 fn handle_event(
2966 self: RenderHandle<Self>,
2967 app: &mut App,
2968 event: &PointerEvent,
2969 _entry: &BoxHitTestEntry,
2970 ) {
2971 RenderMouseRegionBase::handle_event(self, app, event);
2972 }
2973
2974 fn compute_min_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
2975 RenderProxyBoxMixin::compute_min_intrinsic_width(self, app, height)
2976 }
2977
2978 fn compute_max_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
2979 RenderProxyBoxMixin::compute_max_intrinsic_width(self, app, height)
2980 }
2981
2982 fn compute_min_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
2983 RenderProxyBoxMixin::compute_min_intrinsic_height(self, app, width)
2984 }
2985
2986 fn compute_max_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
2987 RenderProxyBoxMixin::compute_max_intrinsic_height(self, app, width)
2988 }
2989
2990 fn compute_distance_to_actual_baseline(
2991 self: RenderHandle<Self>,
2992 app: &mut App,
2993 baseline: TextBaseline,
2994 ) -> Option<f64> {
2995 RenderProxyBoxMixin::compute_distance_to_actual_baseline(self, app, baseline)
2996 }
2997
2998 fn compute_dry_baseline(
2999 self: RenderHandle<Self>,
3000 app: &mut App,
3001 constraints: BoxConstraints,
3002 baseline: TextBaseline,
3003 ) -> Option<f64> {
3004 RenderProxyBoxMixin::compute_dry_baseline(self, app, constraints, baseline)
3005 }
3006
3007 fn compute_dry_layout(
3008 self: RenderHandle<Self>,
3009 app: &mut App,
3010 constraints: BoxConstraints,
3011 ) -> Size {
3012 RenderProxyBoxMixin::compute_dry_layout(self, app, constraints)
3013 }
3014}
3015
3016pub(crate) fn same_instance<T: ?Sized>(a: Option<&Rc<T>>, b: Option<&Rc<T>>) -> bool {
3018 match (a, b) {
3019 (None, None) => true,
3020 (Some(a), Some(b)) => Rc::ptr_eq(a, b),
3021 _ => false,
3022 }
3023}
3024
3025pub struct RenderLimitedBox {
3038 render_object: RenderObjectData,
3039 render_box: RenderBoxData,
3040 child: RenderObjectWithChildData<AnyRenderBox>,
3041 max_width: f64,
3042 max_height: f64,
3043}
3044
3045impl RenderLimitedBox {
3046 pub fn new(
3051 app: &mut App,
3052 max_width: f64,
3053 max_height: f64,
3054 child: Option<AnyRenderBox>,
3055 ) -> RenderHandle<RenderLimitedBox> {
3056 debug_assert!(max_width >= 0.0);
3057 debug_assert!(max_height >= 0.0);
3058 let this = RenderHandle::new_box(
3059 app,
3060 RenderLimitedBox {
3061 render_object: RenderObjectData::new(),
3062 render_box: RenderBoxData::new(),
3063 child: RenderObjectWithChildData::new(),
3064 max_width,
3065 max_height,
3066 },
3067 );
3068 this.set_child(app, child);
3069 this
3070 }
3071
3072 pub fn max_width(self: RenderHandle<Self>, app: &App) -> f64 {
3074 self.get(app).max_width
3075 }
3076
3077 pub fn set_max_width(self: RenderHandle<Self>, app: &mut App, value: f64) {
3079 debug_assert!(value >= 0.0);
3080 if self.get(app).max_width == value {
3081 return;
3082 }
3083 self.get_mut(app).max_width = value;
3084 RenderBox::mark_needs_layout(self, app);
3085 }
3086
3087 pub fn max_height(self: RenderHandle<Self>, app: &App) -> f64 {
3089 self.get(app).max_height
3090 }
3091
3092 pub fn set_max_height(self: RenderHandle<Self>, app: &mut App, value: f64) {
3094 debug_assert!(value >= 0.0);
3095 if self.get(app).max_height == value {
3096 return;
3097 }
3098 self.get_mut(app).max_height = value;
3099 RenderBox::mark_needs_layout(self, app);
3100 }
3101
3102 fn compute_size(
3104 self: RenderHandle<Self>,
3105 app: &mut App,
3106 constraints: BoxConstraints,
3107 layout_child: ChildLayouter,
3108 ) -> Size {
3109 let limited = self.limit_constraints(app, constraints);
3110 match self.child(app) {
3111 Some(child) => constraints.constrain(layout_child(app, child, limited)),
3112 None => limited.constrain(Size::ZERO),
3113 }
3114 }
3115
3116 fn limit_constraints(
3117 self: RenderHandle<Self>,
3118 app: &App,
3119 constraints: BoxConstraints,
3120 ) -> BoxConstraints {
3121 let this = self.get(app);
3122 BoxConstraints::new()
3123 .min_width(constraints.min_width)
3124 .max_width(if constraints.has_bounded_width() {
3125 constraints.max_width
3126 } else {
3127 constraints.constrain_width(this.max_width)
3128 })
3129 .min_height(constraints.min_height)
3130 .max_height(if constraints.has_bounded_height() {
3131 constraints.max_height
3132 } else {
3133 constraints.constrain_height(this.max_height)
3134 })
3135 }
3136}
3137
3138impl RenderObjectWithChildMixin for RenderLimitedBox {
3139 type ChildType = AnyRenderBox;
3140
3141 fn child_data(self: RenderHandle<Self>, app: &App) -> &RenderObjectWithChildData<AnyRenderBox> {
3142 &self.get(app).child
3143 }
3144
3145 fn child_data_mut(
3146 self: RenderHandle<Self>,
3147 app: &mut App,
3148 ) -> &mut RenderObjectWithChildData<AnyRenderBox> {
3149 &mut self.get_mut(app).child
3150 }
3151}
3152
3153impl RenderProxyBoxMixin for RenderLimitedBox {}
3154
3155impl RenderObject for RenderLimitedBox {
3156 crate::render_object_accessors!();
3157
3158 fn debug_fill_properties(
3159 self: RenderHandle<Self>,
3160 app: &App,
3161 properties: &mut DiagnosticPropertiesBuilder,
3162 ) {
3163 let this = self.get(app);
3164 properties.add(
3165 DoubleProperty::new("maxWidth", this.max_width).default_value(Some(f64::INFINITY)),
3166 );
3167 properties.add(
3168 DoubleProperty::new("maxHeight", this.max_height).default_value(Some(f64::INFINITY)),
3169 );
3170 }
3171
3172 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
3173 let constraints = self.constraints(app);
3174 let size = self.compute_size(app, constraints, ChildLayoutHelper::layout_child);
3175 self.set_size(app, size);
3176 }
3177
3178 fn paint(
3179 self: RenderHandle<Self>,
3180 app: &mut App,
3181 context: &mut PaintingContext,
3182 offset: Offset,
3183 ) {
3184 RenderProxyBoxMixin::paint(self, app, context, offset);
3185 }
3186
3187 fn visit_children(
3188 self: RenderHandle<Self>,
3189 app: &App,
3190 visitor: &mut dyn FnMut(AnyRenderObject),
3191 ) {
3192 if let Some(child) = self.child(app) {
3193 visitor(child.as_object());
3194 }
3195 }
3196}
3197
3198impl RenderBox for RenderLimitedBox {
3199 crate::render_box_accessors!();
3200
3201 fn setup_parent_data(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject) {
3202 RenderProxyBoxMixin::setup_parent_data(self, app, child);
3203 }
3204
3205 fn apply_paint_transform(
3206 self: RenderHandle<Self>,
3207 app: &App,
3208 child: AnyRenderObject,
3209 transform: &mut Matrix4,
3210 ) {
3211 RenderProxyBoxMixin::apply_paint_transform(self, app, child, transform);
3212 }
3213
3214 fn hit_test_children(
3215 self: RenderHandle<Self>,
3216 app: &mut App,
3217 result: &mut BoxHitTestResult<'_>,
3218 position: Offset,
3219 ) -> bool {
3220 RenderProxyBoxMixin::hit_test_children(self, app, result, position)
3221 }
3222
3223 fn compute_min_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
3224 RenderProxyBoxMixin::compute_min_intrinsic_width(self, app, height)
3225 }
3226
3227 fn compute_max_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
3228 RenderProxyBoxMixin::compute_max_intrinsic_width(self, app, height)
3229 }
3230
3231 fn compute_min_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
3232 RenderProxyBoxMixin::compute_min_intrinsic_height(self, app, width)
3233 }
3234
3235 fn compute_max_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
3236 RenderProxyBoxMixin::compute_max_intrinsic_height(self, app, width)
3237 }
3238
3239 fn compute_distance_to_actual_baseline(
3240 self: RenderHandle<Self>,
3241 app: &mut App,
3242 baseline: TextBaseline,
3243 ) -> Option<f64> {
3244 RenderProxyBoxMixin::compute_distance_to_actual_baseline(self, app, baseline)
3245 }
3246
3247 fn compute_dry_baseline(
3248 self: RenderHandle<Self>,
3249 app: &mut App,
3250 constraints: BoxConstraints,
3251 baseline: TextBaseline,
3252 ) -> Option<f64> {
3253 RenderProxyBoxMixin::compute_dry_baseline(self, app, constraints, baseline)
3254 }
3255
3256 fn compute_dry_layout(
3257 self: RenderHandle<Self>,
3258 app: &mut App,
3259 constraints: BoxConstraints,
3260 ) -> Size {
3261 self.compute_size(app, constraints, ChildLayoutHelper::dry_layout_child)
3262 }
3263}
3264
3265pub struct RenderAspectRatio {
3279 render_object: RenderObjectData,
3280 render_box: RenderBoxData,
3281 child: RenderObjectWithChildData<AnyRenderBox>,
3282 aspect_ratio: f64,
3283}
3284
3285impl RenderAspectRatio {
3286 pub fn new(
3290 app: &mut App,
3291 aspect_ratio: f64,
3292 child: Option<AnyRenderBox>,
3293 ) -> RenderHandle<RenderAspectRatio> {
3294 debug_assert!(aspect_ratio > 0.0);
3295 debug_assert!(aspect_ratio.is_finite());
3296 let this = RenderHandle::new_box(
3297 app,
3298 RenderAspectRatio {
3299 render_object: RenderObjectData::new(),
3300 render_box: RenderBoxData::new(),
3301 child: RenderObjectWithChildData::new(),
3302 aspect_ratio,
3303 },
3304 );
3305 this.set_child(app, child);
3306 this
3307 }
3308
3309 pub fn aspect_ratio(self: RenderHandle<Self>, app: &App) -> f64 {
3314 self.get(app).aspect_ratio
3315 }
3316
3317 pub fn set_aspect_ratio(self: RenderHandle<Self>, app: &mut App, value: f64) {
3319 debug_assert!(value > 0.0);
3320 debug_assert!(value.is_finite());
3321 if self.get(app).aspect_ratio == value {
3322 return;
3323 }
3324 self.get_mut(app).aspect_ratio = value;
3325 RenderBox::mark_needs_layout(self, app);
3326 }
3327
3328 fn apply_aspect_ratio(
3329 self: RenderHandle<Self>,
3330 app: &App,
3331 constraints: BoxConstraints,
3332 ) -> Size {
3333 debug_assert!(constraints.debug_assert_is_valid(false));
3334 let aspect_ratio = self.get(app).aspect_ratio;
3335 debug_assert!(
3336 constraints.has_bounded_width() || constraints.has_bounded_height(),
3337 "{} has unbounded constraints.\n\
3338 This render object was given an aspect ratio of {aspect_ratio} but was given both \
3339 unbounded width and unbounded height constraints. Because both constraints were \
3340 unbounded, this render object doesn't know how much size to consume.",
3341 std::any::type_name::<Self>()
3342 );
3343
3344 if constraints.is_tight() {
3345 return constraints.smallest();
3346 }
3347
3348 let mut width = constraints.max_width;
3349 let mut height;
3350
3351 if width.is_finite() {
3354 height = width / aspect_ratio;
3355 } else {
3356 height = constraints.max_height;
3357 width = height * aspect_ratio;
3358 }
3359
3360 if width > constraints.max_width {
3365 width = constraints.max_width;
3366 height = width / aspect_ratio;
3367 }
3368
3369 if height > constraints.max_height {
3370 height = constraints.max_height;
3371 width = height * aspect_ratio;
3372 }
3373
3374 if width < constraints.min_width {
3375 width = constraints.min_width;
3376 height = width / aspect_ratio;
3377 }
3378
3379 if height < constraints.min_height {
3380 height = constraints.min_height;
3381 width = height * aspect_ratio;
3382 }
3383
3384 constraints.constrain(Size::new(width, height))
3385 }
3386}
3387
3388impl RenderObjectWithChildMixin for RenderAspectRatio {
3389 type ChildType = AnyRenderBox;
3390
3391 fn child_data(self: RenderHandle<Self>, app: &App) -> &RenderObjectWithChildData<AnyRenderBox> {
3392 &self.get(app).child
3393 }
3394
3395 fn child_data_mut(
3396 self: RenderHandle<Self>,
3397 app: &mut App,
3398 ) -> &mut RenderObjectWithChildData<AnyRenderBox> {
3399 &mut self.get_mut(app).child
3400 }
3401}
3402
3403impl RenderProxyBoxMixin for RenderAspectRatio {}
3404
3405impl RenderObject for RenderAspectRatio {
3406 crate::render_object_accessors!();
3407
3408 fn debug_fill_properties(
3409 self: RenderHandle<Self>,
3410 app: &App,
3411 properties: &mut DiagnosticPropertiesBuilder,
3412 ) {
3413 properties.add(DoubleProperty::new(
3414 "aspectRatio",
3415 self.get(app).aspect_ratio,
3416 ));
3417 }
3418
3419 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
3420 let constraints = self.constraints(app);
3421 let size = self.get_dry_layout(app, constraints);
3422 self.set_size(app, size);
3423 if let Some(child) = self.child(app) {
3424 child.layout(app, BoxConstraints::tight(size), false);
3425 }
3426 }
3427
3428 fn paint(
3429 self: RenderHandle<Self>,
3430 app: &mut App,
3431 context: &mut PaintingContext,
3432 offset: Offset,
3433 ) {
3434 RenderProxyBoxMixin::paint(self, app, context, offset);
3435 }
3436
3437 fn visit_children(
3438 self: RenderHandle<Self>,
3439 app: &App,
3440 visitor: &mut dyn FnMut(AnyRenderObject),
3441 ) {
3442 if let Some(child) = self.child(app) {
3443 visitor(child.as_object());
3444 }
3445 }
3446}
3447
3448impl RenderBox for RenderAspectRatio {
3449 crate::render_box_accessors!();
3450
3451 fn setup_parent_data(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject) {
3452 RenderProxyBoxMixin::setup_parent_data(self, app, child);
3453 }
3454
3455 fn apply_paint_transform(
3456 self: RenderHandle<Self>,
3457 app: &App,
3458 child: AnyRenderObject,
3459 transform: &mut Matrix4,
3460 ) {
3461 RenderProxyBoxMixin::apply_paint_transform(self, app, child, transform);
3462 }
3463
3464 fn hit_test_children(
3465 self: RenderHandle<Self>,
3466 app: &mut App,
3467 result: &mut BoxHitTestResult<'_>,
3468 position: Offset,
3469 ) -> bool {
3470 RenderProxyBoxMixin::hit_test_children(self, app, result, position)
3471 }
3472
3473 fn compute_min_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
3474 if height.is_finite() {
3475 return height * self.get(app).aspect_ratio;
3476 }
3477 match self.child(app) {
3478 Some(child) => child.get_min_intrinsic_width(app, height),
3479 None => 0.0,
3480 }
3481 }
3482
3483 fn compute_max_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
3484 if height.is_finite() {
3485 return height * self.get(app).aspect_ratio;
3486 }
3487 match self.child(app) {
3488 Some(child) => child.get_max_intrinsic_width(app, height),
3489 None => 0.0,
3490 }
3491 }
3492
3493 fn compute_min_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
3494 if width.is_finite() {
3495 return width / self.get(app).aspect_ratio;
3496 }
3497 match self.child(app) {
3498 Some(child) => child.get_min_intrinsic_height(app, width),
3499 None => 0.0,
3500 }
3501 }
3502
3503 fn compute_max_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
3504 if width.is_finite() {
3505 return width / self.get(app).aspect_ratio;
3506 }
3507 match self.child(app) {
3508 Some(child) => child.get_max_intrinsic_height(app, width),
3509 None => 0.0,
3510 }
3511 }
3512
3513 fn compute_distance_to_actual_baseline(
3514 self: RenderHandle<Self>,
3515 app: &mut App,
3516 baseline: TextBaseline,
3517 ) -> Option<f64> {
3518 RenderProxyBoxMixin::compute_distance_to_actual_baseline(self, app, baseline)
3519 }
3520
3521 fn compute_dry_layout(
3522 self: RenderHandle<Self>,
3523 app: &mut App,
3524 constraints: BoxConstraints,
3525 ) -> Size {
3526 self.apply_aspect_ratio(app, constraints)
3527 }
3528
3529 fn compute_dry_baseline(
3530 self: RenderHandle<Self>,
3531 app: &mut App,
3532 constraints: BoxConstraints,
3533 baseline: TextBaseline,
3534 ) -> Option<f64> {
3535 let size = self.get_dry_layout(app, constraints);
3536 RenderProxyBoxMixin::compute_dry_baseline(self, app, BoxConstraints::tight(size), baseline)
3537 }
3538}
3539
3540pub struct RenderIntrinsicWidth {
3560 render_object: RenderObjectData,
3561 render_box: RenderBoxData,
3562 child: RenderObjectWithChildData<AnyRenderBox>,
3563 step_width: Option<f64>,
3564 step_height: Option<f64>,
3565}
3566
3567fn apply_step(input: f64, step: Option<f64>) -> f64 {
3569 debug_assert!(input.is_finite());
3570 match step {
3571 Some(step) => (input / step).ceil() * step,
3572 None => input,
3573 }
3574}
3575
3576impl RenderIntrinsicWidth {
3577 pub fn new(
3582 app: &mut App,
3583 step_width: Option<f64>,
3584 step_height: Option<f64>,
3585 child: Option<AnyRenderBox>,
3586 ) -> RenderHandle<RenderIntrinsicWidth> {
3587 debug_assert!(step_width.is_none_or(|step| step > 0.0));
3588 debug_assert!(step_height.is_none_or(|step| step > 0.0));
3589 let this = RenderHandle::new_box(
3590 app,
3591 RenderIntrinsicWidth {
3592 render_object: RenderObjectData::new(),
3593 render_box: RenderBoxData::new(),
3594 child: RenderObjectWithChildData::new(),
3595 step_width,
3596 step_height,
3597 },
3598 );
3599 this.set_child(app, child);
3600 this
3601 }
3602
3603 pub fn step_width(self: RenderHandle<Self>, app: &App) -> Option<f64> {
3605 self.get(app).step_width
3606 }
3607
3608 pub fn set_step_width(self: RenderHandle<Self>, app: &mut App, value: Option<f64>) {
3610 debug_assert!(value.is_none_or(|step| step > 0.0));
3611 if self.get(app).step_width == value {
3612 return;
3613 }
3614 self.get_mut(app).step_width = value;
3615 RenderBox::mark_needs_layout(self, app);
3616 }
3617
3618 pub fn step_height(self: RenderHandle<Self>, app: &App) -> Option<f64> {
3620 self.get(app).step_height
3621 }
3622
3623 pub fn set_step_height(self: RenderHandle<Self>, app: &mut App, value: Option<f64>) {
3625 debug_assert!(value.is_none_or(|step| step > 0.0));
3626 if self.get(app).step_height == value {
3627 return;
3628 }
3629 self.get_mut(app).step_height = value;
3630 RenderBox::mark_needs_layout(self, app);
3631 }
3632
3633 fn child_constraints(
3634 self: RenderHandle<Self>,
3635 app: &mut App,
3636 child: AnyRenderBox,
3637 constraints: BoxConstraints,
3638 ) -> BoxConstraints {
3639 let (step_width, step_height) = {
3640 let this = self.get(app);
3641 (this.step_width, this.step_height)
3642 };
3643 let width = if constraints.has_tight_width() {
3644 None
3645 } else {
3646 Some(apply_step(
3647 child.get_max_intrinsic_width(app, constraints.max_height),
3648 step_width,
3649 ))
3650 };
3651 let height = step_height.map(|_| {
3652 apply_step(
3653 child.get_max_intrinsic_height(app, constraints.max_width),
3654 step_height,
3655 )
3656 });
3657 constraints.tighten(width, height)
3658 }
3659
3660 fn compute_size(
3662 self: RenderHandle<Self>,
3663 app: &mut App,
3664 constraints: BoxConstraints,
3665 layout_child: ChildLayouter,
3666 ) -> Size {
3667 match self.child(app) {
3668 Some(child) => {
3669 let child_constraints = self.child_constraints(app, child, constraints);
3670 layout_child(app, child, child_constraints)
3671 }
3672 None => constraints.smallest(),
3673 }
3674 }
3675}
3676
3677impl RenderObjectWithChildMixin for RenderIntrinsicWidth {
3678 type ChildType = AnyRenderBox;
3679
3680 fn child_data(self: RenderHandle<Self>, app: &App) -> &RenderObjectWithChildData<AnyRenderBox> {
3681 &self.get(app).child
3682 }
3683
3684 fn child_data_mut(
3685 self: RenderHandle<Self>,
3686 app: &mut App,
3687 ) -> &mut RenderObjectWithChildData<AnyRenderBox> {
3688 &mut self.get_mut(app).child
3689 }
3690}
3691
3692impl RenderProxyBoxMixin for RenderIntrinsicWidth {}
3693
3694impl RenderObject for RenderIntrinsicWidth {
3695 crate::render_object_accessors!();
3696
3697 fn debug_fill_properties(
3698 self: RenderHandle<Self>,
3699 app: &App,
3700 properties: &mut DiagnosticPropertiesBuilder,
3701 ) {
3702 let this = self.get(app);
3703 properties.add(DoubleProperty::new("stepWidth", this.step_width));
3704 properties.add(DoubleProperty::new("stepHeight", this.step_height));
3705 }
3706
3707 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
3708 let constraints = self.constraints(app);
3709 let size = self.compute_size(app, constraints, ChildLayoutHelper::layout_child);
3710 self.set_size(app, size);
3711 }
3712
3713 fn paint(
3714 self: RenderHandle<Self>,
3715 app: &mut App,
3716 context: &mut PaintingContext,
3717 offset: Offset,
3718 ) {
3719 RenderProxyBoxMixin::paint(self, app, context, offset);
3720 }
3721
3722 fn visit_children(
3723 self: RenderHandle<Self>,
3724 app: &App,
3725 visitor: &mut dyn FnMut(AnyRenderObject),
3726 ) {
3727 if let Some(child) = self.child(app) {
3728 visitor(child.as_object());
3729 }
3730 }
3731}
3732
3733impl RenderBox for RenderIntrinsicWidth {
3734 crate::render_box_accessors!();
3735
3736 fn setup_parent_data(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject) {
3737 RenderProxyBoxMixin::setup_parent_data(self, app, child);
3738 }
3739
3740 fn apply_paint_transform(
3741 self: RenderHandle<Self>,
3742 app: &App,
3743 child: AnyRenderObject,
3744 transform: &mut Matrix4,
3745 ) {
3746 RenderProxyBoxMixin::apply_paint_transform(self, app, child, transform);
3747 }
3748
3749 fn hit_test_children(
3750 self: RenderHandle<Self>,
3751 app: &mut App,
3752 result: &mut BoxHitTestResult<'_>,
3753 position: Offset,
3754 ) -> bool {
3755 RenderProxyBoxMixin::hit_test_children(self, app, result, position)
3756 }
3757
3758 fn compute_min_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
3759 self.as_box().get_max_intrinsic_width(app, height)
3760 }
3761
3762 fn compute_max_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
3763 let Some(child) = self.child(app) else {
3764 return 0.0;
3765 };
3766 let width = child.get_max_intrinsic_width(app, height);
3767 apply_step(width, self.get(app).step_width)
3768 }
3769
3770 fn compute_min_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
3771 let Some(child) = self.child(app) else {
3772 return 0.0;
3773 };
3774 let width = if width.is_finite() {
3775 width
3776 } else {
3777 self.as_box().get_max_intrinsic_width(app, f64::INFINITY)
3778 };
3779 debug_assert!(width.is_finite());
3780 let height = child.get_min_intrinsic_height(app, width);
3781 apply_step(height, self.get(app).step_height)
3782 }
3783
3784 fn compute_max_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
3785 let Some(child) = self.child(app) else {
3786 return 0.0;
3787 };
3788 let width = if width.is_finite() {
3789 width
3790 } else {
3791 self.as_box().get_max_intrinsic_width(app, f64::INFINITY)
3792 };
3793 debug_assert!(width.is_finite());
3794 let height = child.get_max_intrinsic_height(app, width);
3795 apply_step(height, self.get(app).step_height)
3796 }
3797
3798 fn compute_distance_to_actual_baseline(
3799 self: RenderHandle<Self>,
3800 app: &mut App,
3801 baseline: TextBaseline,
3802 ) -> Option<f64> {
3803 RenderProxyBoxMixin::compute_distance_to_actual_baseline(self, app, baseline)
3804 }
3805
3806 fn compute_dry_layout(
3807 self: RenderHandle<Self>,
3808 app: &mut App,
3809 constraints: BoxConstraints,
3810 ) -> Size {
3811 self.compute_size(app, constraints, ChildLayoutHelper::dry_layout_child)
3812 }
3813
3814 fn compute_dry_baseline(
3815 self: RenderHandle<Self>,
3816 app: &mut App,
3817 constraints: BoxConstraints,
3818 baseline: TextBaseline,
3819 ) -> Option<f64> {
3820 let child = self.child(app)?;
3821 let child_constraints = self.child_constraints(app, child, constraints);
3822 child.get_dry_baseline(app, child_constraints, baseline)
3823 }
3824}
3825
3826pub struct RenderIntrinsicHeight {
3842 render_object: RenderObjectData,
3843 render_box: RenderBoxData,
3844 child: RenderObjectWithChildData<AnyRenderBox>,
3845}
3846
3847impl RenderIntrinsicHeight {
3848 pub fn new(app: &mut App, child: Option<AnyRenderBox>) -> RenderHandle<RenderIntrinsicHeight> {
3850 let this = RenderHandle::new_box(
3851 app,
3852 RenderIntrinsicHeight {
3853 render_object: RenderObjectData::new(),
3854 render_box: RenderBoxData::new(),
3855 child: RenderObjectWithChildData::new(),
3856 },
3857 );
3858 this.set_child(app, child);
3859 this
3860 }
3861
3862 fn child_constraints(
3863 self: RenderHandle<Self>,
3864 app: &mut App,
3865 child: AnyRenderBox,
3866 constraints: BoxConstraints,
3867 ) -> BoxConstraints {
3868 if constraints.has_tight_height() {
3869 return constraints;
3870 }
3871 let height = child.get_max_intrinsic_height(app, constraints.max_width);
3872 constraints.tighten(None, Some(height))
3873 }
3874
3875 fn compute_size(
3877 self: RenderHandle<Self>,
3878 app: &mut App,
3879 constraints: BoxConstraints,
3880 layout_child: ChildLayouter,
3881 ) -> Size {
3882 match self.child(app) {
3883 Some(child) => {
3884 let child_constraints = self.child_constraints(app, child, constraints);
3885 layout_child(app, child, child_constraints)
3886 }
3887 None => constraints.smallest(),
3888 }
3889 }
3890}
3891
3892impl RenderObjectWithChildMixin for RenderIntrinsicHeight {
3893 type ChildType = AnyRenderBox;
3894
3895 fn child_data(self: RenderHandle<Self>, app: &App) -> &RenderObjectWithChildData<AnyRenderBox> {
3896 &self.get(app).child
3897 }
3898
3899 fn child_data_mut(
3900 self: RenderHandle<Self>,
3901 app: &mut App,
3902 ) -> &mut RenderObjectWithChildData<AnyRenderBox> {
3903 &mut self.get_mut(app).child
3904 }
3905}
3906
3907impl RenderProxyBoxMixin for RenderIntrinsicHeight {}
3908
3909impl RenderObject for RenderIntrinsicHeight {
3910 crate::render_object_accessors!();
3911
3912 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
3913 let constraints = self.constraints(app);
3914 let size = self.compute_size(app, constraints, ChildLayoutHelper::layout_child);
3915 self.set_size(app, size);
3916 }
3917
3918 fn paint(
3919 self: RenderHandle<Self>,
3920 app: &mut App,
3921 context: &mut PaintingContext,
3922 offset: Offset,
3923 ) {
3924 RenderProxyBoxMixin::paint(self, app, context, offset);
3925 }
3926
3927 fn visit_children(
3928 self: RenderHandle<Self>,
3929 app: &App,
3930 visitor: &mut dyn FnMut(AnyRenderObject),
3931 ) {
3932 if let Some(child) = self.child(app) {
3933 visitor(child.as_object());
3934 }
3935 }
3936}
3937
3938impl RenderBox for RenderIntrinsicHeight {
3939 crate::render_box_accessors!();
3940
3941 fn setup_parent_data(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject) {
3942 RenderProxyBoxMixin::setup_parent_data(self, app, child);
3943 }
3944
3945 fn apply_paint_transform(
3946 self: RenderHandle<Self>,
3947 app: &App,
3948 child: AnyRenderObject,
3949 transform: &mut Matrix4,
3950 ) {
3951 RenderProxyBoxMixin::apply_paint_transform(self, app, child, transform);
3952 }
3953
3954 fn hit_test_children(
3955 self: RenderHandle<Self>,
3956 app: &mut App,
3957 result: &mut BoxHitTestResult<'_>,
3958 position: Offset,
3959 ) -> bool {
3960 RenderProxyBoxMixin::hit_test_children(self, app, result, position)
3961 }
3962
3963 fn compute_min_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
3964 let Some(child) = self.child(app) else {
3965 return 0.0;
3966 };
3967 let height = if height.is_finite() {
3968 height
3969 } else {
3970 child.get_max_intrinsic_height(app, f64::INFINITY)
3971 };
3972 debug_assert!(height.is_finite());
3973 child.get_min_intrinsic_width(app, height)
3974 }
3975
3976 fn compute_max_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
3977 let Some(child) = self.child(app) else {
3978 return 0.0;
3979 };
3980 let height = if height.is_finite() {
3981 height
3982 } else {
3983 child.get_max_intrinsic_height(app, f64::INFINITY)
3984 };
3985 debug_assert!(height.is_finite());
3986 child.get_max_intrinsic_width(app, height)
3987 }
3988
3989 fn compute_min_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
3990 self.as_box().get_max_intrinsic_height(app, width)
3991 }
3992
3993 fn compute_max_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
3994 RenderProxyBoxMixin::compute_max_intrinsic_height(self, app, width)
3995 }
3996
3997 fn compute_distance_to_actual_baseline(
3998 self: RenderHandle<Self>,
3999 app: &mut App,
4000 baseline: TextBaseline,
4001 ) -> Option<f64> {
4002 RenderProxyBoxMixin::compute_distance_to_actual_baseline(self, app, baseline)
4003 }
4004
4005 fn compute_dry_layout(
4006 self: RenderHandle<Self>,
4007 app: &mut App,
4008 constraints: BoxConstraints,
4009 ) -> Size {
4010 self.compute_size(app, constraints, ChildLayoutHelper::dry_layout_child)
4011 }
4012
4013 fn compute_dry_baseline(
4014 self: RenderHandle<Self>,
4015 app: &mut App,
4016 constraints: BoxConstraints,
4017 baseline: TextBaseline,
4018 ) -> Option<f64> {
4019 let child = self.child(app)?;
4020 let child_constraints = self.child_constraints(app, child, constraints);
4021 child.get_dry_baseline(app, child_constraints, baseline)
4022 }
4023}
4024
4025pub trait CustomClipper<T>: 'static {
4039 fn reclip(&self) -> Option<&Rc<dyn Listenable>> {
4045 None
4046 }
4047
4048 fn get_clip(&self, app: &App, size: Size) -> T;
4053
4054 fn get_approximate_clip_rect(&self, _app: &App, size: Size) -> Rect {
4065 Offset::ZERO & size
4066 }
4067
4068 fn should_reclip(&self, app: &App, old_clipper: &dyn CustomClipper<T>) -> bool;
4086
4087 fn as_any(&self) -> &dyn Any;
4089}
4090
4091impl<T: 'static> Listenable for dyn CustomClipper<T> {
4092 fn add_listener(&self, app: &mut App, listener: Listener) {
4096 if let Some(reclip) = self.reclip() {
4097 reclip.add_listener(app, listener);
4098 }
4099 }
4100
4101 fn remove_listener(&self, app: &mut App, listener: &Listener) {
4104 if let Some(reclip) = self.reclip() {
4105 reclip.remove_listener(app, listener);
4106 }
4107 }
4108}
4109
4110pub struct RenderCustomClipData<T> {
4112 clipper: Option<Rc<dyn CustomClipper<T>>>,
4113 clip: Option<T>,
4114 clip_behavior: Clip,
4115}
4116
4117impl<T> RenderCustomClipData<T> {
4118 pub fn new(
4120 clipper: Option<Rc<dyn CustomClipper<T>>>,
4121 clip_behavior: Clip,
4122 ) -> RenderCustomClipData<T> {
4123 RenderCustomClipData {
4124 clipper,
4125 clip: None,
4126 clip_behavior,
4127 }
4128 }
4129}
4130
4131pub struct ShapeBorderClipper {
4133 pub shape: ShapeBorderRef,
4135 pub text_direction: Option<TextDirection>,
4140}
4141
4142impl ShapeBorderClipper {
4143 pub fn new(shape: ShapeBorderRef, text_direction: Option<TextDirection>) -> Self {
4150 ShapeBorderClipper {
4151 shape,
4152 text_direction,
4153 }
4154 }
4155}
4156
4157impl CustomClipper<Path> for ShapeBorderClipper {
4158 fn get_clip(&self, _app: &App, size: Size) -> Path {
4159 self.shape
4160 .get_outer_path(Offset::ZERO & size, self.text_direction)
4161 }
4162
4163 fn should_reclip(&self, _app: &App, old_clipper: &dyn CustomClipper<Path>) -> bool {
4164 let Some(old_clipper) = old_clipper.as_any().downcast_ref::<ShapeBorderClipper>() else {
4165 return true;
4166 };
4167 old_clipper.shape != self.shape || old_clipper.text_direction != self.text_direction
4168 }
4169
4170 fn as_any(&self) -> &dyn Any {
4171 self
4172 }
4173}
4174
4175pub trait RenderCustomClip<T: Clone + 'static>: RenderProxyBoxMixin {
4181 fn custom_clip_data(self: RenderHandle<Self>, app: &App) -> &RenderCustomClipData<T>;
4183
4184 fn custom_clip_data_mut(
4186 self: RenderHandle<Self>,
4187 app: &mut App,
4188 ) -> &mut RenderCustomClipData<T>;
4189
4190 fn default_clip(self: RenderHandle<Self>, app: &App) -> T;
4192
4193 fn clipper(self: RenderHandle<Self>, app: &App) -> Option<Rc<dyn CustomClipper<T>>> {
4195 self.custom_clip_data(app).clipper.clone()
4196 }
4197
4198 fn set_clipper(
4200 self: RenderHandle<Self>,
4201 app: &mut App,
4202 new_clipper: Option<Rc<dyn CustomClipper<T>>>,
4203 ) {
4204 let old_clipper = self.clipper(app);
4205 if same_instance(old_clipper.as_ref(), new_clipper.as_ref()) {
4206 return;
4207 }
4208 self.custom_clip_data_mut(app).clipper = new_clipper.clone();
4209 debug_assert!(new_clipper.is_some() || old_clipper.is_some());
4210 let reclip = match (&new_clipper, &old_clipper) {
4211 (Some(new_clipper), Some(old_clipper)) => {
4212 new_clipper.as_any().type_id() != old_clipper.as_any().type_id()
4213 || new_clipper.should_reclip(app, &**old_clipper)
4214 }
4215 _ => true,
4216 };
4217 if reclip {
4218 self.mark_needs_clip(app);
4219 }
4220 if self.attached(app) {
4221 if let Some(old_clipper) = &old_clipper {
4222 old_clipper.remove_listener(app, &self.clip_listener());
4223 }
4224 if let Some(new_clipper) = &new_clipper {
4225 new_clipper.add_listener(app, self.clip_listener());
4226 }
4227 }
4228 }
4229
4230 fn did_attach(self: RenderHandle<Self>, app: &mut App) {
4232 if let Some(clipper) = self.clipper(app) {
4233 clipper.add_listener(app, self.clip_listener());
4234 }
4235 }
4236
4237 fn did_detach(self: RenderHandle<Self>, app: &mut App) {
4239 if let Some(clipper) = self.clipper(app) {
4240 clipper.remove_listener(app, &self.clip_listener());
4241 }
4242 }
4243
4244 fn mark_needs_clip(self: RenderHandle<Self>, app: &mut App) {
4246 self.custom_clip_data_mut(app).clip = None;
4247 self.mark_needs_paint(app);
4248 }
4249
4250 fn clip_listener(self: RenderHandle<Self>) -> Listener {
4252 Listener::handle_method(self.handle(), mark_needs_clip::<Self, T>)
4253 }
4254
4255 fn clip_behavior(self: RenderHandle<Self>, app: &App) -> Clip {
4257 self.custom_clip_data(app).clip_behavior
4258 }
4259
4260 fn set_clip_behavior(self: RenderHandle<Self>, app: &mut App, value: Clip) {
4262 if value != self.clip_behavior(app) {
4263 self.custom_clip_data_mut(app).clip_behavior = value;
4264 self.mark_needs_paint(app);
4265 }
4266 }
4267
4268 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
4270 let old_size = self.has_size(app).then(|| self.size(app));
4271 RenderProxyBoxMixin::perform_layout(self, app);
4272 if old_size != Some(self.size(app)) {
4273 self.custom_clip_data_mut(app).clip = None;
4274 }
4275 }
4276
4277 fn update_clip(self: RenderHandle<Self>, app: &mut App) {
4279 if self.custom_clip_data(app).clip.is_some() {
4280 return;
4281 }
4282 let clip = match self.clipper(app) {
4283 Some(clipper) => clipper.get_clip(app, self.size(app)),
4284 None => self.default_clip(app),
4285 };
4286 self.custom_clip_data_mut(app).clip = Some(clip);
4287 }
4288
4289 fn clip(self: RenderHandle<Self>, app: &App) -> T {
4291 self.custom_clip_data(app)
4292 .clip
4293 .clone()
4294 .expect("update_clip computes the clip")
4295 }
4296
4297 fn describe_approximate_paint_clip(
4300 self: RenderHandle<Self>,
4301 app: &App,
4302 _child: AnyRenderObject,
4303 ) -> Option<Rect> {
4304 match self.clip_behavior(app) {
4305 Clip::None => None,
4306 Clip::HardEdge | Clip::AntiAlias | Clip::AntiAliasWithSaveLayer => {
4307 Some(match self.clipper(app) {
4308 Some(clipper) => clipper.get_approximate_clip_rect(app, self.size(app)),
4309 None => Offset::ZERO & self.size(app),
4310 })
4311 }
4312 }
4313 }
4314}
4315
4316fn mark_needs_clip<C: RenderCustomClip<T>, T: Clone + 'static>(this: Handle<C>, app: &mut App) {
4317 RenderCustomClip::mark_needs_clip(RenderHandle::from_handle(this), app);
4318}
4319
4320pub struct RenderClipRect {
4326 render_object: RenderObjectData,
4327 render_box: RenderBoxData,
4328 child: RenderObjectWithChildData<AnyRenderBox>,
4329 custom_clip: RenderCustomClipData<Rect>,
4330}
4331
4332impl RenderClipRect {
4333 pub fn new(
4340 app: &mut App,
4341 clipper: Option<Rc<dyn CustomClipper<Rect>>>,
4342 clip_behavior: Clip,
4343 child: Option<AnyRenderBox>,
4344 ) -> RenderHandle<RenderClipRect> {
4345 let this = RenderHandle::new_box(
4346 app,
4347 RenderClipRect {
4348 render_object: RenderObjectData::new(),
4349 render_box: RenderBoxData::new(),
4350 child: RenderObjectWithChildData::new(),
4351 custom_clip: RenderCustomClipData::new(clipper, clip_behavior),
4352 },
4353 );
4354 this.set_child(app, child);
4355 this
4356 }
4357}
4358
4359impl RenderObjectWithChildMixin for RenderClipRect {
4360 type ChildType = AnyRenderBox;
4361
4362 fn child_data(self: RenderHandle<Self>, app: &App) -> &RenderObjectWithChildData<AnyRenderBox> {
4363 &self.get(app).child
4364 }
4365
4366 fn child_data_mut(
4367 self: RenderHandle<Self>,
4368 app: &mut App,
4369 ) -> &mut RenderObjectWithChildData<AnyRenderBox> {
4370 &mut self.get_mut(app).child
4371 }
4372}
4373
4374impl RenderProxyBoxMixin for RenderClipRect {}
4375
4376impl RenderCustomClip<Rect> for RenderClipRect {
4377 fn custom_clip_data(self: RenderHandle<Self>, app: &App) -> &RenderCustomClipData<Rect> {
4378 &self.get(app).custom_clip
4379 }
4380
4381 fn custom_clip_data_mut(
4382 self: RenderHandle<Self>,
4383 app: &mut App,
4384 ) -> &mut RenderCustomClipData<Rect> {
4385 &mut self.get_mut(app).custom_clip
4386 }
4387
4388 fn default_clip(self: RenderHandle<Self>, app: &App) -> Rect {
4389 Offset::ZERO & self.size(app)
4390 }
4391}
4392
4393impl RenderObject for RenderClipRect {
4394 crate::render_object_accessors!();
4395
4396 fn did_attach(self: RenderHandle<Self>, app: &mut App, owner: Handle<PipelineOwner>) {
4397 if let Some(child) = self.child(app) {
4398 child.as_object().attach(app, owner);
4399 }
4400 RenderCustomClip::did_attach(self, app);
4401 }
4402
4403 fn did_detach(self: RenderHandle<Self>, app: &mut App) {
4404 RenderCustomClip::did_detach(self, app);
4405 if let Some(child) = self.child(app) {
4406 child.as_object().detach(app);
4407 }
4408 }
4409
4410 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
4411 RenderCustomClip::perform_layout(self, app);
4412 }
4413
4414 fn describe_approximate_paint_clip(
4415 self: RenderHandle<Self>,
4416 app: &App,
4417 child: AnyRenderObject,
4418 ) -> Option<Rect> {
4419 RenderCustomClip::describe_approximate_paint_clip(self, app, child)
4420 }
4421
4422 fn paint(
4423 self: RenderHandle<Self>,
4424 app: &mut App,
4425 context: &mut PaintingContext,
4426 offset: Offset,
4427 ) {
4428 if let Some(child) = self.child(app) {
4429 let clip_behavior = self.clip_behavior(app);
4430 if clip_behavior != Clip::None {
4431 self.update_clip(app);
4432 let clip = self.clip(app);
4433 let old = self.as_object().layer_as::<ClipRectLayer>(app);
4434 let layer = context.push_clip_rect(
4435 app,
4436 self.as_object().needs_compositing(app),
4437 offset,
4438 clip,
4439 |app, context, offset| RenderProxyBoxMixin::paint(self, app, context, offset),
4440 clip_behavior,
4441 old,
4442 );
4443 self.as_object()
4444 .set_layer(app, layer.map(|layer| layer.as_container_layer()));
4445 } else {
4446 context.paint_child(app, child.as_object(), offset);
4447 self.as_object().set_layer(app, None);
4448 }
4449 } else {
4450 self.as_object().set_layer(app, None);
4451 }
4452 }
4453
4454 fn visit_children(
4455 self: RenderHandle<Self>,
4456 app: &App,
4457 visitor: &mut dyn FnMut(AnyRenderObject),
4458 ) {
4459 if let Some(child) = self.child(app) {
4460 visitor(child.as_object());
4461 }
4462 }
4463}
4464
4465impl RenderBox for RenderClipRect {
4466 crate::render_box_accessors!();
4467
4468 fn setup_parent_data(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject) {
4469 RenderProxyBoxMixin::setup_parent_data(self, app, child);
4470 }
4471
4472 fn apply_paint_transform(
4473 self: RenderHandle<Self>,
4474 app: &App,
4475 child: AnyRenderObject,
4476 transform: &mut Matrix4,
4477 ) {
4478 RenderProxyBoxMixin::apply_paint_transform(self, app, child, transform);
4479 }
4480
4481 fn hit_test(
4482 self: RenderHandle<Self>,
4483 app: &mut App,
4484 result: &mut BoxHitTestResult<'_>,
4485 position: Offset,
4486 ) -> bool {
4487 if self.clipper(app).is_some() {
4488 self.update_clip(app);
4489 if !self.clip(app).contains(position) {
4490 return false;
4491 }
4492 }
4493 RenderBoxBase::hit_test(self, app, result, position)
4494 }
4495
4496 fn hit_test_children(
4497 self: RenderHandle<Self>,
4498 app: &mut App,
4499 result: &mut BoxHitTestResult<'_>,
4500 position: Offset,
4501 ) -> bool {
4502 RenderProxyBoxMixin::hit_test_children(self, app, result, position)
4503 }
4504
4505 fn compute_min_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
4506 RenderProxyBoxMixin::compute_min_intrinsic_width(self, app, height)
4507 }
4508
4509 fn compute_max_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
4510 RenderProxyBoxMixin::compute_max_intrinsic_width(self, app, height)
4511 }
4512
4513 fn compute_min_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
4514 RenderProxyBoxMixin::compute_min_intrinsic_height(self, app, width)
4515 }
4516
4517 fn compute_max_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
4518 RenderProxyBoxMixin::compute_max_intrinsic_height(self, app, width)
4519 }
4520
4521 fn compute_distance_to_actual_baseline(
4522 self: RenderHandle<Self>,
4523 app: &mut App,
4524 baseline: TextBaseline,
4525 ) -> Option<f64> {
4526 RenderProxyBoxMixin::compute_distance_to_actual_baseline(self, app, baseline)
4527 }
4528
4529 fn compute_dry_baseline(
4530 self: RenderHandle<Self>,
4531 app: &mut App,
4532 constraints: BoxConstraints,
4533 baseline: TextBaseline,
4534 ) -> Option<f64> {
4535 RenderProxyBoxMixin::compute_dry_baseline(self, app, constraints, baseline)
4536 }
4537
4538 fn compute_dry_layout(
4539 self: RenderHandle<Self>,
4540 app: &mut App,
4541 constraints: BoxConstraints,
4542 ) -> Size {
4543 RenderProxyBoxMixin::compute_dry_layout(self, app, constraints)
4544 }
4545}
4546
4547pub struct RenderClipRRect {
4553 render_object: RenderObjectData,
4554 render_box: RenderBoxData,
4555 child: RenderObjectWithChildData<AnyRenderBox>,
4556 custom_clip: RenderCustomClipData<RRect>,
4557 border_radius: BorderRadiusGeometry,
4558 text_direction: Option<TextDirection>,
4559}
4560
4561impl RenderClipRRect {
4562 pub fn new(
4571 app: &mut App,
4572 border_radius: BorderRadiusGeometry,
4573 clipper: Option<Rc<dyn CustomClipper<RRect>>>,
4574 clip_behavior: Clip,
4575 text_direction: Option<TextDirection>,
4576 child: Option<AnyRenderBox>,
4577 ) -> RenderHandle<RenderClipRRect> {
4578 let this = RenderHandle::new_box(
4579 app,
4580 RenderClipRRect {
4581 render_object: RenderObjectData::new(),
4582 render_box: RenderBoxData::new(),
4583 child: RenderObjectWithChildData::new(),
4584 custom_clip: RenderCustomClipData::new(clipper, clip_behavior),
4585 border_radius,
4586 text_direction,
4587 },
4588 );
4589 this.set_child(app, child);
4590 this
4591 }
4592
4593 pub fn border_radius(self: RenderHandle<Self>, app: &App) -> BorderRadiusGeometry {
4600 self.get(app).border_radius
4601 }
4602
4603 pub fn set_border_radius(self: RenderHandle<Self>, app: &mut App, value: BorderRadiusGeometry) {
4605 if self.get(app).border_radius == value {
4606 return;
4607 }
4608 self.get_mut(app).border_radius = value;
4609 self.mark_needs_clip(app);
4610 }
4611
4612 pub fn text_direction(self: RenderHandle<Self>, app: &App) -> Option<TextDirection> {
4614 self.get(app).text_direction
4615 }
4616
4617 pub fn set_text_direction(
4619 self: RenderHandle<Self>,
4620 app: &mut App,
4621 value: Option<TextDirection>,
4622 ) {
4623 if self.get(app).text_direction == value {
4624 return;
4625 }
4626 self.get_mut(app).text_direction = value;
4627 self.mark_needs_clip(app);
4628 }
4629}
4630
4631impl RenderObjectWithChildMixin for RenderClipRRect {
4632 type ChildType = AnyRenderBox;
4633
4634 fn child_data(self: RenderHandle<Self>, app: &App) -> &RenderObjectWithChildData<AnyRenderBox> {
4635 &self.get(app).child
4636 }
4637
4638 fn child_data_mut(
4639 self: RenderHandle<Self>,
4640 app: &mut App,
4641 ) -> &mut RenderObjectWithChildData<AnyRenderBox> {
4642 &mut self.get_mut(app).child
4643 }
4644}
4645
4646impl RenderProxyBoxMixin for RenderClipRRect {}
4647
4648impl RenderCustomClip<RRect> for RenderClipRRect {
4649 fn custom_clip_data(self: RenderHandle<Self>, app: &App) -> &RenderCustomClipData<RRect> {
4650 &self.get(app).custom_clip
4651 }
4652
4653 fn custom_clip_data_mut(
4654 self: RenderHandle<Self>,
4655 app: &mut App,
4656 ) -> &mut RenderCustomClipData<RRect> {
4657 &mut self.get_mut(app).custom_clip
4658 }
4659
4660 fn default_clip(self: RenderHandle<Self>, app: &App) -> RRect {
4661 let this = self.get(app);
4662 this.border_radius
4663 .resolve(this.text_direction)
4664 .to_rrect(Offset::ZERO & self.size(app))
4665 }
4666}
4667
4668impl RenderObject for RenderClipRRect {
4669 crate::render_object_accessors!();
4670
4671 fn did_attach(self: RenderHandle<Self>, app: &mut App, owner: Handle<PipelineOwner>) {
4672 if let Some(child) = self.child(app) {
4673 child.as_object().attach(app, owner);
4674 }
4675 RenderCustomClip::did_attach(self, app);
4676 }
4677
4678 fn did_detach(self: RenderHandle<Self>, app: &mut App) {
4679 RenderCustomClip::did_detach(self, app);
4680 if let Some(child) = self.child(app) {
4681 child.as_object().detach(app);
4682 }
4683 }
4684
4685 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
4686 RenderCustomClip::perform_layout(self, app);
4687 }
4688
4689 fn describe_approximate_paint_clip(
4690 self: RenderHandle<Self>,
4691 app: &App,
4692 child: AnyRenderObject,
4693 ) -> Option<Rect> {
4694 RenderCustomClip::describe_approximate_paint_clip(self, app, child)
4695 }
4696
4697 fn paint(
4698 self: RenderHandle<Self>,
4699 app: &mut App,
4700 context: &mut PaintingContext,
4701 offset: Offset,
4702 ) {
4703 if let Some(child) = self.child(app) {
4704 let clip_behavior = self.clip_behavior(app);
4705 if clip_behavior != Clip::None {
4706 self.update_clip(app);
4707 let clip = self.clip(app);
4708 let old = self.as_object().layer_as::<ClipRRectLayer>(app);
4709 let layer = context.push_clip_rrect(
4710 app,
4711 self.as_object().needs_compositing(app),
4712 offset,
4713 clip.outer_rect(),
4714 clip,
4715 |app, context, offset| RenderProxyBoxMixin::paint(self, app, context, offset),
4716 clip_behavior,
4717 old,
4718 );
4719 self.as_object()
4720 .set_layer(app, layer.map(|layer| layer.as_container_layer()));
4721 } else {
4722 context.paint_child(app, child.as_object(), offset);
4723 self.as_object().set_layer(app, None);
4724 }
4725 } else {
4726 self.as_object().set_layer(app, None);
4727 }
4728 }
4729
4730 fn visit_children(
4731 self: RenderHandle<Self>,
4732 app: &App,
4733 visitor: &mut dyn FnMut(AnyRenderObject),
4734 ) {
4735 if let Some(child) = self.child(app) {
4736 visitor(child.as_object());
4737 }
4738 }
4739}
4740
4741impl RenderBox for RenderClipRRect {
4742 crate::render_box_accessors!();
4743
4744 fn setup_parent_data(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject) {
4745 RenderProxyBoxMixin::setup_parent_data(self, app, child);
4746 }
4747
4748 fn apply_paint_transform(
4749 self: RenderHandle<Self>,
4750 app: &App,
4751 child: AnyRenderObject,
4752 transform: &mut Matrix4,
4753 ) {
4754 RenderProxyBoxMixin::apply_paint_transform(self, app, child, transform);
4755 }
4756
4757 fn hit_test(
4758 self: RenderHandle<Self>,
4759 app: &mut App,
4760 result: &mut BoxHitTestResult<'_>,
4761 position: Offset,
4762 ) -> bool {
4763 if self.clipper(app).is_some() {
4764 self.update_clip(app);
4765 if !self.clip(app).contains(position) {
4766 return false;
4767 }
4768 }
4769 RenderBoxBase::hit_test(self, app, result, position)
4770 }
4771
4772 fn hit_test_children(
4773 self: RenderHandle<Self>,
4774 app: &mut App,
4775 result: &mut BoxHitTestResult<'_>,
4776 position: Offset,
4777 ) -> bool {
4778 RenderProxyBoxMixin::hit_test_children(self, app, result, position)
4779 }
4780
4781 fn compute_min_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
4782 RenderProxyBoxMixin::compute_min_intrinsic_width(self, app, height)
4783 }
4784
4785 fn compute_max_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
4786 RenderProxyBoxMixin::compute_max_intrinsic_width(self, app, height)
4787 }
4788
4789 fn compute_min_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
4790 RenderProxyBoxMixin::compute_min_intrinsic_height(self, app, width)
4791 }
4792
4793 fn compute_max_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
4794 RenderProxyBoxMixin::compute_max_intrinsic_height(self, app, width)
4795 }
4796
4797 fn compute_distance_to_actual_baseline(
4798 self: RenderHandle<Self>,
4799 app: &mut App,
4800 baseline: TextBaseline,
4801 ) -> Option<f64> {
4802 RenderProxyBoxMixin::compute_distance_to_actual_baseline(self, app, baseline)
4803 }
4804
4805 fn compute_dry_baseline(
4806 self: RenderHandle<Self>,
4807 app: &mut App,
4808 constraints: BoxConstraints,
4809 baseline: TextBaseline,
4810 ) -> Option<f64> {
4811 RenderProxyBoxMixin::compute_dry_baseline(self, app, constraints, baseline)
4812 }
4813
4814 fn compute_dry_layout(
4815 self: RenderHandle<Self>,
4816 app: &mut App,
4817 constraints: BoxConstraints,
4818 ) -> Size {
4819 RenderProxyBoxMixin::compute_dry_layout(self, app, constraints)
4820 }
4821}
4822
4823pub struct RenderClipOval {
4828 render_object: RenderObjectData,
4829 render_box: RenderBoxData,
4830 child: RenderObjectWithChildData<AnyRenderBox>,
4831 custom_clip: RenderCustomClipData<Rect>,
4832 cached_rect: Option<Rect>,
4833 cached_path: Option<Path>,
4834}
4835
4836impl RenderClipOval {
4837 pub fn new(
4844 app: &mut App,
4845 clipper: Option<Rc<dyn CustomClipper<Rect>>>,
4846 clip_behavior: Clip,
4847 child: Option<AnyRenderBox>,
4848 ) -> RenderHandle<RenderClipOval> {
4849 let this = RenderHandle::new_box(
4850 app,
4851 RenderClipOval {
4852 render_object: RenderObjectData::new(),
4853 render_box: RenderBoxData::new(),
4854 child: RenderObjectWithChildData::new(),
4855 custom_clip: RenderCustomClipData::new(clipper, clip_behavior),
4856 cached_rect: None,
4857 cached_path: None,
4858 },
4859 );
4860 this.set_child(app, child);
4861 this
4862 }
4863
4864 fn get_clip_path(self: RenderHandle<Self>, app: &mut App, rect: Rect) -> Path {
4865 if self.get(app).cached_rect != Some(rect) {
4866 let radius = [(rect.width() / 2.0) as f32, (rect.height() / 2.0) as f32];
4867 let mut path = PathBuilder::new();
4868 path.rrect_radii_elliptical(rect, [radius; 4]);
4869 let this = self.get_mut(app);
4870 this.cached_rect = Some(rect);
4871 this.cached_path = Some(path.build().into());
4872 }
4873 self.get(app).cached_path.clone().expect("cached above")
4874 }
4875}
4876
4877impl RenderObjectWithChildMixin for RenderClipOval {
4878 type ChildType = AnyRenderBox;
4879
4880 fn child_data(self: RenderHandle<Self>, app: &App) -> &RenderObjectWithChildData<AnyRenderBox> {
4881 &self.get(app).child
4882 }
4883
4884 fn child_data_mut(
4885 self: RenderHandle<Self>,
4886 app: &mut App,
4887 ) -> &mut RenderObjectWithChildData<AnyRenderBox> {
4888 &mut self.get_mut(app).child
4889 }
4890}
4891
4892impl RenderProxyBoxMixin for RenderClipOval {}
4893
4894impl RenderCustomClip<Rect> for RenderClipOval {
4895 fn custom_clip_data(self: RenderHandle<Self>, app: &App) -> &RenderCustomClipData<Rect> {
4896 &self.get(app).custom_clip
4897 }
4898
4899 fn custom_clip_data_mut(
4900 self: RenderHandle<Self>,
4901 app: &mut App,
4902 ) -> &mut RenderCustomClipData<Rect> {
4903 &mut self.get_mut(app).custom_clip
4904 }
4905
4906 fn default_clip(self: RenderHandle<Self>, app: &App) -> Rect {
4907 Offset::ZERO & self.size(app)
4908 }
4909}
4910
4911impl RenderObject for RenderClipOval {
4912 crate::render_object_accessors!();
4913
4914 fn did_attach(self: RenderHandle<Self>, app: &mut App, owner: Handle<PipelineOwner>) {
4915 if let Some(child) = self.child(app) {
4916 child.as_object().attach(app, owner);
4917 }
4918 RenderCustomClip::did_attach(self, app);
4919 }
4920
4921 fn did_detach(self: RenderHandle<Self>, app: &mut App) {
4922 RenderCustomClip::did_detach(self, app);
4923 if let Some(child) = self.child(app) {
4924 child.as_object().detach(app);
4925 }
4926 }
4927
4928 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
4929 RenderCustomClip::perform_layout(self, app);
4930 }
4931
4932 fn describe_approximate_paint_clip(
4933 self: RenderHandle<Self>,
4934 app: &App,
4935 child: AnyRenderObject,
4936 ) -> Option<Rect> {
4937 RenderCustomClip::describe_approximate_paint_clip(self, app, child)
4938 }
4939
4940 fn paint(
4941 self: RenderHandle<Self>,
4942 app: &mut App,
4943 context: &mut PaintingContext,
4944 offset: Offset,
4945 ) {
4946 if let Some(child) = self.child(app) {
4947 let clip_behavior = self.clip_behavior(app);
4948 if clip_behavior != Clip::None {
4949 self.update_clip(app);
4950 let clip = self.clip(app);
4951 let clip_path = self.get_clip_path(app, clip);
4952 let old = self.as_object().layer_as::<ClipPathLayer>(app);
4953 let layer = context.push_clip_path(
4954 app,
4955 self.as_object().needs_compositing(app),
4956 offset,
4957 clip,
4958 clip_path,
4959 |app, context, offset| RenderProxyBoxMixin::paint(self, app, context, offset),
4960 clip_behavior,
4961 old,
4962 );
4963 self.as_object()
4964 .set_layer(app, layer.map(|layer| layer.as_container_layer()));
4965 } else {
4966 context.paint_child(app, child.as_object(), offset);
4967 self.as_object().set_layer(app, None);
4968 }
4969 } else {
4970 self.as_object().set_layer(app, None);
4971 }
4972 }
4973
4974 fn visit_children(
4975 self: RenderHandle<Self>,
4976 app: &App,
4977 visitor: &mut dyn FnMut(AnyRenderObject),
4978 ) {
4979 if let Some(child) = self.child(app) {
4980 visitor(child.as_object());
4981 }
4982 }
4983}
4984
4985impl RenderBox for RenderClipOval {
4986 crate::render_box_accessors!();
4987
4988 fn setup_parent_data(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject) {
4989 RenderProxyBoxMixin::setup_parent_data(self, app, child);
4990 }
4991
4992 fn apply_paint_transform(
4993 self: RenderHandle<Self>,
4994 app: &App,
4995 child: AnyRenderObject,
4996 transform: &mut Matrix4,
4997 ) {
4998 RenderProxyBoxMixin::apply_paint_transform(self, app, child, transform);
4999 }
5000
5001 fn hit_test(
5002 self: RenderHandle<Self>,
5003 app: &mut App,
5004 result: &mut BoxHitTestResult<'_>,
5005 position: Offset,
5006 ) -> bool {
5007 self.update_clip(app);
5008 let clip = self.clip(app);
5009 let center = clip.center();
5010 let offset = Offset::new(
5012 (position.dx() - center.dx()) / clip.width(),
5013 (position.dy() - center.dy()) / clip.height(),
5014 );
5015 if offset.distance_squared() > 0.25 {
5017 return false;
5019 }
5020 RenderBoxBase::hit_test(self, app, result, position)
5021 }
5022
5023 fn hit_test_children(
5024 self: RenderHandle<Self>,
5025 app: &mut App,
5026 result: &mut BoxHitTestResult<'_>,
5027 position: Offset,
5028 ) -> bool {
5029 RenderProxyBoxMixin::hit_test_children(self, app, result, position)
5030 }
5031
5032 fn compute_min_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
5033 RenderProxyBoxMixin::compute_min_intrinsic_width(self, app, height)
5034 }
5035
5036 fn compute_max_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
5037 RenderProxyBoxMixin::compute_max_intrinsic_width(self, app, height)
5038 }
5039
5040 fn compute_min_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
5041 RenderProxyBoxMixin::compute_min_intrinsic_height(self, app, width)
5042 }
5043
5044 fn compute_max_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
5045 RenderProxyBoxMixin::compute_max_intrinsic_height(self, app, width)
5046 }
5047
5048 fn compute_distance_to_actual_baseline(
5049 self: RenderHandle<Self>,
5050 app: &mut App,
5051 baseline: TextBaseline,
5052 ) -> Option<f64> {
5053 RenderProxyBoxMixin::compute_distance_to_actual_baseline(self, app, baseline)
5054 }
5055
5056 fn compute_dry_baseline(
5057 self: RenderHandle<Self>,
5058 app: &mut App,
5059 constraints: BoxConstraints,
5060 baseline: TextBaseline,
5061 ) -> Option<f64> {
5062 RenderProxyBoxMixin::compute_dry_baseline(self, app, constraints, baseline)
5063 }
5064
5065 fn compute_dry_layout(
5066 self: RenderHandle<Self>,
5067 app: &mut App,
5068 constraints: BoxConstraints,
5069 ) -> Size {
5070 RenderProxyBoxMixin::compute_dry_layout(self, app, constraints)
5071 }
5072}
5073
5074pub struct RenderClipPath {
5086 render_object: RenderObjectData,
5087 render_box: RenderBoxData,
5088 child: RenderObjectWithChildData<AnyRenderBox>,
5089 custom_clip: RenderCustomClipData<Path>,
5090}
5091
5092impl RenderClipPath {
5093 pub fn new(
5102 app: &mut App,
5103 clipper: Option<Rc<dyn CustomClipper<Path>>>,
5104 clip_behavior: Clip,
5105 child: Option<AnyRenderBox>,
5106 ) -> RenderHandle<RenderClipPath> {
5107 let this = RenderHandle::new_box(
5108 app,
5109 RenderClipPath {
5110 render_object: RenderObjectData::new(),
5111 render_box: RenderBoxData::new(),
5112 child: RenderObjectWithChildData::new(),
5113 custom_clip: RenderCustomClipData::new(clipper, clip_behavior),
5114 },
5115 );
5116 this.set_child(app, child);
5117 this
5118 }
5119}
5120
5121impl RenderObjectWithChildMixin for RenderClipPath {
5122 type ChildType = AnyRenderBox;
5123
5124 fn child_data(self: RenderHandle<Self>, app: &App) -> &RenderObjectWithChildData<AnyRenderBox> {
5125 &self.get(app).child
5126 }
5127
5128 fn child_data_mut(
5129 self: RenderHandle<Self>,
5130 app: &mut App,
5131 ) -> &mut RenderObjectWithChildData<AnyRenderBox> {
5132 &mut self.get_mut(app).child
5133 }
5134}
5135
5136impl RenderProxyBoxMixin for RenderClipPath {}
5137
5138impl RenderCustomClip<Path> for RenderClipPath {
5139 fn custom_clip_data(self: RenderHandle<Self>, app: &App) -> &RenderCustomClipData<Path> {
5140 &self.get(app).custom_clip
5141 }
5142
5143 fn custom_clip_data_mut(
5144 self: RenderHandle<Self>,
5145 app: &mut App,
5146 ) -> &mut RenderCustomClipData<Path> {
5147 &mut self.get_mut(app).custom_clip
5148 }
5149
5150 fn default_clip(self: RenderHandle<Self>, app: &App) -> Path {
5151 let mut path = PathBuilder::new();
5152 path.rect((Offset::ZERO & self.size(app)).into());
5153 path.build().into()
5154 }
5155}
5156
5157impl RenderObject for RenderClipPath {
5158 crate::render_object_accessors!();
5159
5160 fn did_attach(self: RenderHandle<Self>, app: &mut App, owner: Handle<PipelineOwner>) {
5161 if let Some(child) = self.child(app) {
5162 child.as_object().attach(app, owner);
5163 }
5164 RenderCustomClip::did_attach(self, app);
5165 }
5166
5167 fn did_detach(self: RenderHandle<Self>, app: &mut App) {
5168 RenderCustomClip::did_detach(self, app);
5169 if let Some(child) = self.child(app) {
5170 child.as_object().detach(app);
5171 }
5172 }
5173
5174 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
5175 RenderCustomClip::perform_layout(self, app);
5176 }
5177
5178 fn describe_approximate_paint_clip(
5179 self: RenderHandle<Self>,
5180 app: &App,
5181 child: AnyRenderObject,
5182 ) -> Option<Rect> {
5183 RenderCustomClip::describe_approximate_paint_clip(self, app, child)
5184 }
5185
5186 fn paint(
5187 self: RenderHandle<Self>,
5188 app: &mut App,
5189 context: &mut PaintingContext,
5190 offset: Offset,
5191 ) {
5192 if let Some(child) = self.child(app) {
5193 let clip_behavior = self.clip_behavior(app);
5194 if clip_behavior != Clip::None {
5195 self.update_clip(app);
5196 let clip = self.clip(app);
5197 let bounds = Offset::ZERO & self.size(app);
5198 let old = self.as_object().layer_as::<ClipPathLayer>(app);
5199 let layer = context.push_clip_path(
5200 app,
5201 self.as_object().needs_compositing(app),
5202 offset,
5203 bounds,
5204 clip,
5205 |app, context, offset| RenderProxyBoxMixin::paint(self, app, context, offset),
5206 clip_behavior,
5207 old,
5208 );
5209 self.as_object()
5210 .set_layer(app, layer.map(|layer| layer.as_container_layer()));
5211 } else {
5212 context.paint_child(app, child.as_object(), offset);
5213 self.as_object().set_layer(app, None);
5214 }
5215 } else {
5216 self.as_object().set_layer(app, None);
5217 }
5218 }
5219
5220 fn visit_children(
5221 self: RenderHandle<Self>,
5222 app: &App,
5223 visitor: &mut dyn FnMut(AnyRenderObject),
5224 ) {
5225 if let Some(child) = self.child(app) {
5226 visitor(child.as_object());
5227 }
5228 }
5229}
5230
5231impl RenderBox for RenderClipPath {
5232 crate::render_box_accessors!();
5233
5234 fn setup_parent_data(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject) {
5235 RenderProxyBoxMixin::setup_parent_data(self, app, child);
5236 }
5237
5238 fn apply_paint_transform(
5239 self: RenderHandle<Self>,
5240 app: &App,
5241 child: AnyRenderObject,
5242 transform: &mut Matrix4,
5243 ) {
5244 RenderProxyBoxMixin::apply_paint_transform(self, app, child, transform);
5245 }
5246
5247 fn hit_test(
5248 self: RenderHandle<Self>,
5249 app: &mut App,
5250 result: &mut BoxHitTestResult<'_>,
5251 position: Offset,
5252 ) -> bool {
5253 if self.clipper(app).is_some() {
5254 self.update_clip(app);
5255 if !self.clip(app).contains(position) {
5256 return false;
5257 }
5258 }
5259 RenderBoxBase::hit_test(self, app, result, position)
5260 }
5261
5262 fn hit_test_children(
5263 self: RenderHandle<Self>,
5264 app: &mut App,
5265 result: &mut BoxHitTestResult<'_>,
5266 position: Offset,
5267 ) -> bool {
5268 RenderProxyBoxMixin::hit_test_children(self, app, result, position)
5269 }
5270
5271 fn compute_min_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
5272 RenderProxyBoxMixin::compute_min_intrinsic_width(self, app, height)
5273 }
5274
5275 fn compute_max_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
5276 RenderProxyBoxMixin::compute_max_intrinsic_width(self, app, height)
5277 }
5278
5279 fn compute_min_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
5280 RenderProxyBoxMixin::compute_min_intrinsic_height(self, app, width)
5281 }
5282
5283 fn compute_max_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
5284 RenderProxyBoxMixin::compute_max_intrinsic_height(self, app, width)
5285 }
5286
5287 fn compute_distance_to_actual_baseline(
5288 self: RenderHandle<Self>,
5289 app: &mut App,
5290 baseline: TextBaseline,
5291 ) -> Option<f64> {
5292 RenderProxyBoxMixin::compute_distance_to_actual_baseline(self, app, baseline)
5293 }
5294
5295 fn compute_dry_baseline(
5296 self: RenderHandle<Self>,
5297 app: &mut App,
5298 constraints: BoxConstraints,
5299 baseline: TextBaseline,
5300 ) -> Option<f64> {
5301 RenderProxyBoxMixin::compute_dry_baseline(self, app, constraints, baseline)
5302 }
5303
5304 fn compute_dry_layout(
5305 self: RenderHandle<Self>,
5306 app: &mut App,
5307 constraints: BoxConstraints,
5308 ) -> Size {
5309 RenderProxyBoxMixin::compute_dry_layout(self, app, constraints)
5310 }
5311}
5312
5313pub struct RenderClipRSuperellipse {
5319 render_object: RenderObjectData,
5320 render_box: RenderBoxData,
5321 child: RenderObjectWithChildData<AnyRenderBox>,
5322 custom_clip: RenderCustomClipData<RSuperellipse>,
5323 border_radius: BorderRadiusGeometry,
5324 text_direction: Option<TextDirection>,
5325}
5326
5327impl RenderClipRSuperellipse {
5328 pub fn new(
5337 app: &mut App,
5338 border_radius: BorderRadiusGeometry,
5339 clipper: Option<Rc<dyn CustomClipper<RSuperellipse>>>,
5340 clip_behavior: Clip,
5341 text_direction: Option<TextDirection>,
5342 child: Option<AnyRenderBox>,
5343 ) -> RenderHandle<RenderClipRSuperellipse> {
5344 let this = RenderHandle::new_box(
5345 app,
5346 RenderClipRSuperellipse {
5347 render_object: RenderObjectData::new(),
5348 render_box: RenderBoxData::new(),
5349 child: RenderObjectWithChildData::new(),
5350 custom_clip: RenderCustomClipData::new(clipper, clip_behavior),
5351 border_radius,
5352 text_direction,
5353 },
5354 );
5355 this.set_child(app, child);
5356 this
5357 }
5358
5359 pub fn border_radius(self: RenderHandle<Self>, app: &App) -> BorderRadiusGeometry {
5366 self.get(app).border_radius
5367 }
5368
5369 pub fn set_border_radius(self: RenderHandle<Self>, app: &mut App, value: BorderRadiusGeometry) {
5371 if self.get(app).border_radius == value {
5372 return;
5373 }
5374 self.get_mut(app).border_radius = value;
5375 self.mark_needs_clip(app);
5376 }
5377
5378 pub fn text_direction(self: RenderHandle<Self>, app: &App) -> Option<TextDirection> {
5380 self.get(app).text_direction
5381 }
5382
5383 pub fn set_text_direction(
5385 self: RenderHandle<Self>,
5386 app: &mut App,
5387 value: Option<TextDirection>,
5388 ) {
5389 if self.get(app).text_direction == value {
5390 return;
5391 }
5392 self.get_mut(app).text_direction = value;
5393 self.mark_needs_clip(app);
5394 }
5395}
5396
5397impl RenderObjectWithChildMixin for RenderClipRSuperellipse {
5398 type ChildType = AnyRenderBox;
5399
5400 fn child_data(self: RenderHandle<Self>, app: &App) -> &RenderObjectWithChildData<AnyRenderBox> {
5401 &self.get(app).child
5402 }
5403
5404 fn child_data_mut(
5405 self: RenderHandle<Self>,
5406 app: &mut App,
5407 ) -> &mut RenderObjectWithChildData<AnyRenderBox> {
5408 &mut self.get_mut(app).child
5409 }
5410}
5411
5412impl RenderProxyBoxMixin for RenderClipRSuperellipse {}
5413
5414impl RenderCustomClip<RSuperellipse> for RenderClipRSuperellipse {
5415 fn custom_clip_data(
5416 self: RenderHandle<Self>,
5417 app: &App,
5418 ) -> &RenderCustomClipData<RSuperellipse> {
5419 &self.get(app).custom_clip
5420 }
5421
5422 fn custom_clip_data_mut(
5423 self: RenderHandle<Self>,
5424 app: &mut App,
5425 ) -> &mut RenderCustomClipData<RSuperellipse> {
5426 &mut self.get_mut(app).custom_clip
5427 }
5428
5429 fn default_clip(self: RenderHandle<Self>, app: &App) -> RSuperellipse {
5430 let this = self.get(app);
5431 this.border_radius
5432 .resolve(this.text_direction)
5433 .to_r_superellipse(Offset::ZERO & self.size(app))
5434 }
5435}
5436
5437impl RenderObject for RenderClipRSuperellipse {
5438 crate::render_object_accessors!();
5439
5440 fn did_attach(self: RenderHandle<Self>, app: &mut App, owner: Handle<PipelineOwner>) {
5441 if let Some(child) = self.child(app) {
5442 child.as_object().attach(app, owner);
5443 }
5444 RenderCustomClip::did_attach(self, app);
5445 }
5446
5447 fn did_detach(self: RenderHandle<Self>, app: &mut App) {
5448 RenderCustomClip::did_detach(self, app);
5449 if let Some(child) = self.child(app) {
5450 child.as_object().detach(app);
5451 }
5452 }
5453
5454 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
5455 RenderCustomClip::perform_layout(self, app);
5456 }
5457
5458 fn describe_approximate_paint_clip(
5459 self: RenderHandle<Self>,
5460 app: &App,
5461 child: AnyRenderObject,
5462 ) -> Option<Rect> {
5463 RenderCustomClip::describe_approximate_paint_clip(self, app, child)
5464 }
5465
5466 fn paint(
5467 self: RenderHandle<Self>,
5468 app: &mut App,
5469 context: &mut PaintingContext,
5470 offset: Offset,
5471 ) {
5472 if let Some(child) = self.child(app) {
5473 let clip_behavior = self.clip_behavior(app);
5474 if clip_behavior != Clip::None {
5475 self.update_clip(app);
5476 let clip = self.clip(app);
5477 let mut clip_path = PathBuilder::new();
5478 clip_path.rsuperellipse_radii(
5479 clip.outer_rect().into(),
5480 rsuperellipse_radii_elliptical(clip),
5481 );
5482 let old = self.as_object().layer_as::<ClipPathLayer>(app);
5483 let layer = context.push_clip_path(
5484 app,
5485 self.as_object().needs_compositing(app),
5486 offset,
5487 clip.outer_rect(),
5488 clip_path.build().into(),
5489 |app, context, offset| RenderProxyBoxMixin::paint(self, app, context, offset),
5490 clip_behavior,
5491 old,
5492 );
5493 self.as_object()
5494 .set_layer(app, layer.map(|layer| layer.as_container_layer()));
5495 } else {
5496 context.paint_child(app, child.as_object(), offset);
5497 self.as_object().set_layer(app, None);
5498 }
5499 } else {
5500 self.as_object().set_layer(app, None);
5501 }
5502 }
5503
5504 fn visit_children(
5505 self: RenderHandle<Self>,
5506 app: &App,
5507 visitor: &mut dyn FnMut(AnyRenderObject),
5508 ) {
5509 if let Some(child) = self.child(app) {
5510 visitor(child.as_object());
5511 }
5512 }
5513}
5514
5515impl RenderBox for RenderClipRSuperellipse {
5516 crate::render_box_accessors!();
5517
5518 fn setup_parent_data(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject) {
5519 RenderProxyBoxMixin::setup_parent_data(self, app, child);
5520 }
5521
5522 fn apply_paint_transform(
5523 self: RenderHandle<Self>,
5524 app: &App,
5525 child: AnyRenderObject,
5526 transform: &mut Matrix4,
5527 ) {
5528 RenderProxyBoxMixin::apply_paint_transform(self, app, child, transform);
5529 }
5530
5531 fn hit_test(
5532 self: RenderHandle<Self>,
5533 app: &mut App,
5534 result: &mut BoxHitTestResult<'_>,
5535 position: Offset,
5536 ) -> bool {
5537 if self.clipper(app).is_some() {
5538 self.update_clip(app);
5539 if !self.clip(app).outer_rect().contains(position) {
5540 return false;
5541 }
5542 }
5543 RenderBoxBase::hit_test(self, app, result, position)
5544 }
5545
5546 fn hit_test_children(
5547 self: RenderHandle<Self>,
5548 app: &mut App,
5549 result: &mut BoxHitTestResult<'_>,
5550 position: Offset,
5551 ) -> bool {
5552 RenderProxyBoxMixin::hit_test_children(self, app, result, position)
5553 }
5554
5555 fn compute_min_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
5556 RenderProxyBoxMixin::compute_min_intrinsic_width(self, app, height)
5557 }
5558
5559 fn compute_max_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
5560 RenderProxyBoxMixin::compute_max_intrinsic_width(self, app, height)
5561 }
5562
5563 fn compute_min_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
5564 RenderProxyBoxMixin::compute_min_intrinsic_height(self, app, width)
5565 }
5566
5567 fn compute_max_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
5568 RenderProxyBoxMixin::compute_max_intrinsic_height(self, app, width)
5569 }
5570
5571 fn compute_distance_to_actual_baseline(
5572 self: RenderHandle<Self>,
5573 app: &mut App,
5574 baseline: TextBaseline,
5575 ) -> Option<f64> {
5576 RenderProxyBoxMixin::compute_distance_to_actual_baseline(self, app, baseline)
5577 }
5578
5579 fn compute_dry_baseline(
5580 self: RenderHandle<Self>,
5581 app: &mut App,
5582 constraints: BoxConstraints,
5583 baseline: TextBaseline,
5584 ) -> Option<f64> {
5585 RenderProxyBoxMixin::compute_dry_baseline(self, app, constraints, baseline)
5586 }
5587
5588 fn compute_dry_layout(
5589 self: RenderHandle<Self>,
5590 app: &mut App,
5591 constraints: BoxConstraints,
5592 ) -> Size {
5593 RenderProxyBoxMixin::compute_dry_layout(self, app, constraints)
5594 }
5595}
5596
5597pub struct RenderPhysicalModelBaseData {
5599 elevation: f64,
5600 color: Color,
5601 shadow_color: Color,
5602}
5603
5604impl RenderPhysicalModelBaseData {
5605 pub fn new(elevation: f64, color: Color, shadow_color: Color) -> RenderPhysicalModelBaseData {
5607 debug_assert!(elevation >= 0.0);
5608 RenderPhysicalModelBaseData {
5609 elevation,
5610 color,
5611 shadow_color,
5612 }
5613 }
5614}
5615
5616pub trait RenderPhysicalModelBase<T: Clone + 'static>: RenderCustomClip<T> {
5619 fn physical_model_data(self: RenderHandle<Self>, app: &App) -> &RenderPhysicalModelBaseData;
5621
5622 fn physical_model_data_mut(
5624 self: RenderHandle<Self>,
5625 app: &mut App,
5626 ) -> &mut RenderPhysicalModelBaseData;
5627
5628 fn elevation(self: RenderHandle<Self>, app: &App) -> f64 {
5632 self.physical_model_data(app).elevation
5633 }
5634
5635 fn set_elevation(self: RenderHandle<Self>, app: &mut App, value: f64) {
5637 debug_assert!(value >= 0.0);
5638 if self.elevation(app) == value {
5639 return;
5640 }
5641 let did_need_compositing = self.as_object().always_needs_compositing(app);
5642 self.physical_model_data_mut(app).elevation = value;
5643 if did_need_compositing != self.as_object().always_needs_compositing(app) {
5644 self.as_object().mark_needs_compositing_bits_update(app);
5645 }
5646 self.mark_needs_paint(app);
5647 }
5648
5649 fn shadow_color(self: RenderHandle<Self>, app: &App) -> Color {
5651 self.physical_model_data(app).shadow_color
5652 }
5653
5654 fn set_shadow_color(self: RenderHandle<Self>, app: &mut App, value: Color) {
5656 if self.shadow_color(app) == value {
5657 return;
5658 }
5659 self.physical_model_data_mut(app).shadow_color = value;
5660 self.mark_needs_paint(app);
5661 }
5662
5663 fn color(self: RenderHandle<Self>, app: &App) -> Color {
5665 self.physical_model_data(app).color
5666 }
5667
5668 fn set_color(self: RenderHandle<Self>, app: &mut App, value: Color) {
5670 if self.color(app) == value {
5671 return;
5672 }
5673 self.physical_model_data_mut(app).color = value;
5674 self.mark_needs_paint(app);
5675 }
5676
5677 fn debug_fill_properties(
5680 self: RenderHandle<Self>,
5681 app: &App,
5682 properties: &mut DiagnosticPropertiesBuilder,
5683 ) {
5684 let data = self.physical_model_data(app);
5685 properties.add(DoubleProperty::new("elevation", data.elevation));
5686 properties.add(ColorProperty::new("color", data.color));
5687 properties.add(ColorProperty::new("shadowColor", data.color));
5689 }
5690}
5691
5692fn device_pixel_ratio_of_view(app: &App, render_object: AnyRenderObject) -> f64 {
5696 render_object
5697 .owner(app)
5698 .and_then(|owner| owner.root_node(app))
5699 .and_then(|root| root.downcast::<RenderView>(app))
5700 .map_or(1.0, |view| view.configuration(app).device_pixel_ratio)
5701}
5702
5703pub struct RenderPhysicalModel {
5708 render_object: RenderObjectData,
5709 render_box: RenderBoxData,
5710 child: RenderObjectWithChildData<AnyRenderBox>,
5711 custom_clip: RenderCustomClipData<RRect>,
5712 physical_model: RenderPhysicalModelBaseData,
5713 shape: BoxShape,
5714 border_radius: Option<BorderRadius>,
5715}
5716
5717impl RenderPhysicalModel {
5718 #[expect(
5726 clippy::too_many_arguments,
5727 reason = "Dart's named arguments, in Dart's order"
5728 )]
5729 pub fn new(
5730 app: &mut App,
5731 child: Option<AnyRenderBox>,
5732 shape: BoxShape,
5733 clip_behavior: Clip,
5734 border_radius: Option<BorderRadius>,
5735 elevation: f64,
5736 color: Color,
5737 shadow_color: Color,
5738 ) -> RenderHandle<RenderPhysicalModel> {
5739 debug_assert!(elevation >= 0.0);
5740 let this = RenderHandle::new_box(
5741 app,
5742 RenderPhysicalModel {
5743 render_object: RenderObjectData::new(),
5744 render_box: RenderBoxData::new(),
5745 child: RenderObjectWithChildData::new(),
5746 custom_clip: RenderCustomClipData::new(None, clip_behavior),
5747 physical_model: RenderPhysicalModelBaseData::new(elevation, color, shadow_color),
5748 shape,
5749 border_radius,
5750 },
5751 );
5752 this.set_child(app, child);
5753 this
5754 }
5755
5756 pub fn shape(self: RenderHandle<Self>, app: &App) -> BoxShape {
5761 self.get(app).shape
5762 }
5763
5764 pub fn set_shape(self: RenderHandle<Self>, app: &mut App, value: BoxShape) {
5766 if self.shape(app) == value {
5767 return;
5768 }
5769 self.get_mut(app).shape = value;
5770 self.mark_needs_clip(app);
5771 }
5772
5773 pub fn border_radius(self: RenderHandle<Self>, app: &App) -> Option<BorderRadius> {
5782 self.get(app).border_radius
5783 }
5784
5785 pub fn set_border_radius(self: RenderHandle<Self>, app: &mut App, value: Option<BorderRadius>) {
5787 if self.border_radius(app) == value {
5788 return;
5789 }
5790 self.get_mut(app).border_radius = value;
5791 self.mark_needs_clip(app);
5792 }
5793}
5794
5795impl RenderObjectWithChildMixin for RenderPhysicalModel {
5796 type ChildType = AnyRenderBox;
5797
5798 fn child_data(self: RenderHandle<Self>, app: &App) -> &RenderObjectWithChildData<AnyRenderBox> {
5799 &self.get(app).child
5800 }
5801
5802 fn child_data_mut(
5803 self: RenderHandle<Self>,
5804 app: &mut App,
5805 ) -> &mut RenderObjectWithChildData<AnyRenderBox> {
5806 &mut self.get_mut(app).child
5807 }
5808}
5809
5810impl RenderProxyBoxMixin for RenderPhysicalModel {}
5811
5812impl RenderCustomClip<RRect> for RenderPhysicalModel {
5813 fn custom_clip_data(self: RenderHandle<Self>, app: &App) -> &RenderCustomClipData<RRect> {
5814 &self.get(app).custom_clip
5815 }
5816
5817 fn custom_clip_data_mut(
5818 self: RenderHandle<Self>,
5819 app: &mut App,
5820 ) -> &mut RenderCustomClipData<RRect> {
5821 &mut self.get_mut(app).custom_clip
5822 }
5823
5824 fn default_clip(self: RenderHandle<Self>, app: &App) -> RRect {
5825 debug_assert!(self.has_size(app));
5826 let rect = Offset::ZERO & self.size(app);
5827 match self.get(app).shape {
5828 BoxShape::Rectangle => self
5829 .get(app)
5830 .border_radius
5831 .unwrap_or(BorderRadius::ZERO)
5832 .to_rrect(rect),
5833 BoxShape::Circle => RRect::from_rect_xy(rect, rect.width() / 2.0, rect.height() / 2.0),
5834 }
5835 }
5836}
5837
5838impl RenderPhysicalModelBase<RRect> for RenderPhysicalModel {
5839 fn physical_model_data(self: RenderHandle<Self>, app: &App) -> &RenderPhysicalModelBaseData {
5840 &self.get(app).physical_model
5841 }
5842
5843 fn physical_model_data_mut(
5844 self: RenderHandle<Self>,
5845 app: &mut App,
5846 ) -> &mut RenderPhysicalModelBaseData {
5847 &mut self.get_mut(app).physical_model
5848 }
5849}
5850
5851impl RenderObject for RenderPhysicalModel {
5852 crate::render_object_accessors!();
5853
5854 fn debug_fill_properties(
5855 self: RenderHandle<Self>,
5856 app: &App,
5857 properties: &mut DiagnosticPropertiesBuilder,
5858 ) {
5859 RenderPhysicalModelBase::debug_fill_properties(self, app, properties);
5860 let this = self.get(app);
5861 properties.add(DiagnosticsProperty::<BoxShape>::new(
5862 "shape",
5863 Some(this.shape),
5864 ));
5865 properties.add(DiagnosticsProperty::<BorderRadius>::new(
5866 "borderRadius",
5867 this.border_radius,
5868 ));
5869 }
5870
5871 fn did_attach(self: RenderHandle<Self>, app: &mut App, owner: Handle<PipelineOwner>) {
5872 if let Some(child) = self.child(app) {
5873 child.as_object().attach(app, owner);
5874 }
5875 RenderCustomClip::did_attach(self, app);
5876 }
5877
5878 fn did_detach(self: RenderHandle<Self>, app: &mut App) {
5879 RenderCustomClip::did_detach(self, app);
5880 if let Some(child) = self.child(app) {
5881 child.as_object().detach(app);
5882 }
5883 }
5884
5885 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
5886 RenderCustomClip::perform_layout(self, app);
5887 }
5888
5889 fn describe_approximate_paint_clip(
5890 self: RenderHandle<Self>,
5891 app: &App,
5892 child: AnyRenderObject,
5893 ) -> Option<Rect> {
5894 RenderCustomClip::describe_approximate_paint_clip(self, app, child)
5895 }
5896
5897 fn paint(
5898 self: RenderHandle<Self>,
5899 app: &mut App,
5900 context: &mut PaintingContext,
5901 offset: Offset,
5902 ) {
5903 if self.child(app).is_none() {
5904 self.as_object().set_layer(app, None);
5905 return;
5906 }
5907
5908 self.update_clip(app);
5909 let offset_rrect = self.clip(app).shift(offset);
5910 let elevation = self.elevation(app);
5911 let shadow_color = self.shadow_color(app);
5912 let color = self.color(app);
5913
5914 let device_pixel_ratio = device_pixel_ratio_of_view(app, self.as_object());
5915 let canvas = context.canvas();
5916 if elevation != 0.0 {
5917 let mut offset_rrect_as_path = PathBuilder::new();
5918 offset_rrect_as_path.rrect_radii_elliptical(
5919 valo::Rect::from(offset_rrect.outer_rect()),
5920 rrect_radii_elliptical(offset_rrect),
5921 );
5922 #[expect(deprecated, reason = "Dart's paint reads the deprecated `Color.alpha`")]
5923 let transparent_occluder = color.alpha() != 0xFF;
5924 canvas.draw_shadow(
5925 &offset_rrect_as_path.build(),
5926 FillRule::NonZero,
5927 shadow_color.into(),
5928 elevation as f32,
5929 transparent_occluder,
5930 device_pixel_ratio as f32,
5931 );
5932 }
5933 let clip_behavior = self.clip_behavior(app);
5934 let uses_save_layer = clip_behavior == Clip::AntiAliasWithSaveLayer;
5935 if !uses_save_layer {
5936 draw_rrect(
5937 canvas,
5938 offset_rrect,
5939 &Paint {
5940 color: color.into(),
5941 ..Paint::default()
5942 },
5943 );
5944 }
5945 let clip = self.clip(app);
5946 let old = self.as_object().layer_as::<ClipRRectLayer>(app);
5947 let layer = context.push_clip_rrect(
5948 app,
5949 self.as_object().needs_compositing(app),
5950 offset,
5951 Offset::ZERO & self.size(app),
5952 clip,
5953 |app, context, offset| {
5954 if uses_save_layer {
5955 context.canvas().draw_paint(&Paint {
5960 color: color.into(),
5961 ..Paint::default()
5962 });
5963 }
5964 RenderProxyBoxMixin::paint(self, app, context, offset)
5965 },
5966 clip_behavior,
5967 old,
5968 );
5969 self.as_object()
5970 .set_layer(app, layer.map(|layer| layer.as_container_layer()));
5971 }
5972
5973 fn visit_children(
5974 self: RenderHandle<Self>,
5975 app: &App,
5976 visitor: &mut dyn FnMut(AnyRenderObject),
5977 ) {
5978 if let Some(child) = self.child(app) {
5979 visitor(child.as_object());
5980 }
5981 }
5982}
5983
5984impl RenderBox for RenderPhysicalModel {
5985 crate::render_box_accessors!();
5986
5987 fn setup_parent_data(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject) {
5988 RenderProxyBoxMixin::setup_parent_data(self, app, child);
5989 }
5990
5991 fn apply_paint_transform(
5992 self: RenderHandle<Self>,
5993 app: &App,
5994 child: AnyRenderObject,
5995 transform: &mut Matrix4,
5996 ) {
5997 RenderProxyBoxMixin::apply_paint_transform(self, app, child, transform);
5998 }
5999
6000 fn hit_test(
6001 self: RenderHandle<Self>,
6002 app: &mut App,
6003 result: &mut BoxHitTestResult<'_>,
6004 position: Offset,
6005 ) -> bool {
6006 if self.clipper(app).is_some() {
6007 self.update_clip(app);
6008 if !self.clip(app).contains(position) {
6009 return false;
6010 }
6011 }
6012 RenderBoxBase::hit_test(self, app, result, position)
6013 }
6014
6015 fn hit_test_children(
6016 self: RenderHandle<Self>,
6017 app: &mut App,
6018 result: &mut BoxHitTestResult<'_>,
6019 position: Offset,
6020 ) -> bool {
6021 RenderProxyBoxMixin::hit_test_children(self, app, result, position)
6022 }
6023
6024 fn compute_min_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
6025 RenderProxyBoxMixin::compute_min_intrinsic_width(self, app, height)
6026 }
6027
6028 fn compute_max_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
6029 RenderProxyBoxMixin::compute_max_intrinsic_width(self, app, height)
6030 }
6031
6032 fn compute_min_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
6033 RenderProxyBoxMixin::compute_min_intrinsic_height(self, app, width)
6034 }
6035
6036 fn compute_max_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
6037 RenderProxyBoxMixin::compute_max_intrinsic_height(self, app, width)
6038 }
6039
6040 fn compute_distance_to_actual_baseline(
6041 self: RenderHandle<Self>,
6042 app: &mut App,
6043 baseline: TextBaseline,
6044 ) -> Option<f64> {
6045 RenderProxyBoxMixin::compute_distance_to_actual_baseline(self, app, baseline)
6046 }
6047
6048 fn compute_dry_baseline(
6049 self: RenderHandle<Self>,
6050 app: &mut App,
6051 constraints: BoxConstraints,
6052 baseline: TextBaseline,
6053 ) -> Option<f64> {
6054 RenderProxyBoxMixin::compute_dry_baseline(self, app, constraints, baseline)
6055 }
6056
6057 fn compute_dry_layout(
6058 self: RenderHandle<Self>,
6059 app: &mut App,
6060 constraints: BoxConstraints,
6061 ) -> Size {
6062 RenderProxyBoxMixin::compute_dry_layout(self, app, constraints)
6063 }
6064}
6065
6066pub struct RenderPhysicalShape {
6075 render_object: RenderObjectData,
6076 render_box: RenderBoxData,
6077 child: RenderObjectWithChildData<AnyRenderBox>,
6078 custom_clip: RenderCustomClipData<Path>,
6079 physical_model: RenderPhysicalModelBaseData,
6080}
6081
6082impl RenderPhysicalShape {
6083 pub fn new(
6090 app: &mut App,
6091 child: Option<AnyRenderBox>,
6092 clipper: Rc<dyn CustomClipper<Path>>,
6093 clip_behavior: Clip,
6094 elevation: f64,
6095 color: Color,
6096 shadow_color: Color,
6097 ) -> RenderHandle<RenderPhysicalShape> {
6098 debug_assert!(elevation >= 0.0);
6099 let this = RenderHandle::new_box(
6100 app,
6101 RenderPhysicalShape {
6102 render_object: RenderObjectData::new(),
6103 render_box: RenderBoxData::new(),
6104 child: RenderObjectWithChildData::new(),
6105 custom_clip: RenderCustomClipData::new(Some(clipper), clip_behavior),
6106 physical_model: RenderPhysicalModelBaseData::new(elevation, color, shadow_color),
6107 },
6108 );
6109 this.set_child(app, child);
6110 this
6111 }
6112}
6113
6114impl RenderObjectWithChildMixin for RenderPhysicalShape {
6115 type ChildType = AnyRenderBox;
6116
6117 fn child_data(self: RenderHandle<Self>, app: &App) -> &RenderObjectWithChildData<AnyRenderBox> {
6118 &self.get(app).child
6119 }
6120
6121 fn child_data_mut(
6122 self: RenderHandle<Self>,
6123 app: &mut App,
6124 ) -> &mut RenderObjectWithChildData<AnyRenderBox> {
6125 &mut self.get_mut(app).child
6126 }
6127}
6128
6129impl RenderProxyBoxMixin for RenderPhysicalShape {}
6130
6131impl RenderCustomClip<Path> for RenderPhysicalShape {
6132 fn custom_clip_data(self: RenderHandle<Self>, app: &App) -> &RenderCustomClipData<Path> {
6133 &self.get(app).custom_clip
6134 }
6135
6136 fn custom_clip_data_mut(
6137 self: RenderHandle<Self>,
6138 app: &mut App,
6139 ) -> &mut RenderCustomClipData<Path> {
6140 &mut self.get_mut(app).custom_clip
6141 }
6142
6143 fn default_clip(self: RenderHandle<Self>, app: &App) -> Path {
6144 let mut path = PathBuilder::new();
6145 path.rect((Offset::ZERO & self.size(app)).into());
6146 path.build().into()
6147 }
6148}
6149
6150impl RenderPhysicalModelBase<Path> for RenderPhysicalShape {
6151 fn physical_model_data(self: RenderHandle<Self>, app: &App) -> &RenderPhysicalModelBaseData {
6152 &self.get(app).physical_model
6153 }
6154
6155 fn physical_model_data_mut(
6156 self: RenderHandle<Self>,
6157 app: &mut App,
6158 ) -> &mut RenderPhysicalModelBaseData {
6159 &mut self.get_mut(app).physical_model
6160 }
6161}
6162
6163impl RenderObject for RenderPhysicalShape {
6164 crate::render_object_accessors!();
6165
6166 fn debug_fill_properties(
6167 self: RenderHandle<Self>,
6168 app: &App,
6169 properties: &mut DiagnosticPropertiesBuilder,
6170 ) {
6171 RenderPhysicalModelBase::debug_fill_properties(self, app, properties);
6172 let clipper = self.clipper(app);
6173 properties.add(DiagnosticsProperty::<String>::new(
6174 "clipper",
6175 clipper.map(|_| "Instance of 'CustomClipper<Path>'".to_string()),
6176 ));
6177 }
6178
6179 fn did_attach(self: RenderHandle<Self>, app: &mut App, owner: Handle<PipelineOwner>) {
6180 if let Some(child) = self.child(app) {
6181 child.as_object().attach(app, owner);
6182 }
6183 RenderCustomClip::did_attach(self, app);
6184 }
6185
6186 fn did_detach(self: RenderHandle<Self>, app: &mut App) {
6187 RenderCustomClip::did_detach(self, app);
6188 if let Some(child) = self.child(app) {
6189 child.as_object().detach(app);
6190 }
6191 }
6192
6193 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
6194 RenderCustomClip::perform_layout(self, app);
6195 }
6196
6197 fn describe_approximate_paint_clip(
6198 self: RenderHandle<Self>,
6199 app: &App,
6200 child: AnyRenderObject,
6201 ) -> Option<Rect> {
6202 RenderCustomClip::describe_approximate_paint_clip(self, app, child)
6203 }
6204
6205 fn paint(
6206 self: RenderHandle<Self>,
6207 app: &mut App,
6208 context: &mut PaintingContext,
6209 offset: Offset,
6210 ) {
6211 if self.child(app).is_none() {
6212 self.as_object().set_layer(app, None);
6213 return;
6214 }
6215
6216 self.update_clip(app);
6217 let clip = self.clip(app);
6218 let offset_path = clip.shift(offset);
6219 let elevation = self.elevation(app);
6220 let shadow_color = self.shadow_color(app);
6221 let color = self.color(app);
6222
6223 let device_pixel_ratio = device_pixel_ratio_of_view(app, self.as_object());
6224 let canvas = context.canvas();
6225 if elevation != 0.0 {
6226 #[expect(deprecated, reason = "Dart's paint reads the deprecated `Color.alpha`")]
6227 let transparent_occluder = color.alpha() != 0xFF;
6228 canvas.draw_shadow(
6229 offset_path.as_valo(),
6230 offset_path.fill_type,
6231 shadow_color.into(),
6232 elevation as f32,
6233 transparent_occluder,
6234 device_pixel_ratio as f32,
6235 );
6236 }
6237 let clip_behavior = self.clip_behavior(app);
6238 let uses_save_layer = clip_behavior == Clip::AntiAliasWithSaveLayer;
6239 if !uses_save_layer {
6240 canvas.draw_path(
6241 offset_path.as_valo(),
6242 offset_path.fill_type,
6243 &Paint {
6244 color: color.into(),
6245 ..Paint::default()
6246 },
6247 );
6248 }
6249 let old = self.as_object().layer_as::<ClipPathLayer>(app);
6250 let layer = context.push_clip_path(
6251 app,
6252 self.as_object().needs_compositing(app),
6253 offset,
6254 Offset::ZERO & self.size(app),
6255 clip,
6256 |app, context, offset| {
6257 if uses_save_layer {
6258 context.canvas().draw_paint(&Paint {
6263 color: color.into(),
6264 ..Paint::default()
6265 });
6266 }
6267 RenderProxyBoxMixin::paint(self, app, context, offset)
6268 },
6269 clip_behavior,
6270 old,
6271 );
6272 self.as_object()
6273 .set_layer(app, layer.map(|layer| layer.as_container_layer()));
6274 }
6275
6276 fn visit_children(
6277 self: RenderHandle<Self>,
6278 app: &App,
6279 visitor: &mut dyn FnMut(AnyRenderObject),
6280 ) {
6281 if let Some(child) = self.child(app) {
6282 visitor(child.as_object());
6283 }
6284 }
6285}
6286
6287impl RenderBox for RenderPhysicalShape {
6288 crate::render_box_accessors!();
6289
6290 fn setup_parent_data(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject) {
6291 RenderProxyBoxMixin::setup_parent_data(self, app, child);
6292 }
6293
6294 fn apply_paint_transform(
6295 self: RenderHandle<Self>,
6296 app: &App,
6297 child: AnyRenderObject,
6298 transform: &mut Matrix4,
6299 ) {
6300 RenderProxyBoxMixin::apply_paint_transform(self, app, child, transform);
6301 }
6302
6303 fn hit_test(
6304 self: RenderHandle<Self>,
6305 app: &mut App,
6306 result: &mut BoxHitTestResult<'_>,
6307 position: Offset,
6308 ) -> bool {
6309 if self.clipper(app).is_some() {
6310 self.update_clip(app);
6311 if !self.clip(app).contains(position) {
6312 return false;
6313 }
6314 }
6315 RenderBoxBase::hit_test(self, app, result, position)
6316 }
6317
6318 fn hit_test_children(
6319 self: RenderHandle<Self>,
6320 app: &mut App,
6321 result: &mut BoxHitTestResult<'_>,
6322 position: Offset,
6323 ) -> bool {
6324 RenderProxyBoxMixin::hit_test_children(self, app, result, position)
6325 }
6326
6327 fn compute_min_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
6328 RenderProxyBoxMixin::compute_min_intrinsic_width(self, app, height)
6329 }
6330
6331 fn compute_max_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
6332 RenderProxyBoxMixin::compute_max_intrinsic_width(self, app, height)
6333 }
6334
6335 fn compute_min_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
6336 RenderProxyBoxMixin::compute_min_intrinsic_height(self, app, width)
6337 }
6338
6339 fn compute_max_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
6340 RenderProxyBoxMixin::compute_max_intrinsic_height(self, app, width)
6341 }
6342
6343 fn compute_distance_to_actual_baseline(
6344 self: RenderHandle<Self>,
6345 app: &mut App,
6346 baseline: TextBaseline,
6347 ) -> Option<f64> {
6348 RenderProxyBoxMixin::compute_distance_to_actual_baseline(self, app, baseline)
6349 }
6350
6351 fn compute_dry_baseline(
6352 self: RenderHandle<Self>,
6353 app: &mut App,
6354 constraints: BoxConstraints,
6355 baseline: TextBaseline,
6356 ) -> Option<f64> {
6357 RenderProxyBoxMixin::compute_dry_baseline(self, app, constraints, baseline)
6358 }
6359
6360 fn compute_dry_layout(
6361 self: RenderHandle<Self>,
6362 app: &mut App,
6363 constraints: BoxConstraints,
6364 ) -> Size {
6365 RenderProxyBoxMixin::compute_dry_layout(self, app, constraints)
6366 }
6367}
6368
6369pub struct RenderTransform {
6371 render_object: RenderObjectData,
6372 render_box: RenderBoxData,
6373 child: RenderObjectWithChildData<AnyRenderBox>,
6374 origin: Option<Offset>,
6375 alignment: Option<AlignmentGeometry>,
6376 text_direction: Option<TextDirection>,
6377 transform_hit_tests: bool,
6378 transform: Matrix4,
6379 filter_quality: Option<FilterQuality>,
6380}
6381
6382impl RenderTransform {
6383 #[allow(clippy::too_many_arguments)]
6385 pub fn new(
6386 app: &mut App,
6387 transform: Matrix4,
6388 origin: Option<Offset>,
6389 alignment: Option<AlignmentGeometry>,
6390 text_direction: Option<TextDirection>,
6391 transform_hit_tests: bool,
6392 filter_quality: Option<FilterQuality>,
6393 child: Option<AnyRenderBox>,
6394 ) -> RenderHandle<RenderTransform> {
6395 let this = RenderHandle::new_box(
6396 app,
6397 RenderTransform {
6398 render_object: RenderObjectData::new(),
6399 render_box: RenderBoxData::new(),
6400 child: RenderObjectWithChildData::new(),
6401 origin,
6402 alignment,
6403 text_direction,
6404 transform_hit_tests,
6405 transform,
6406 filter_quality,
6407 },
6408 );
6409 this.set_child(app, child);
6410 this
6411 }
6412
6413 pub fn origin(self: RenderHandle<Self>, app: &App) -> Option<Offset> {
6419 self.get(app).origin
6420 }
6421
6422 pub fn set_origin(self: RenderHandle<Self>, app: &mut App, value: Option<Offset>) {
6424 if self.get(app).origin == value {
6425 return;
6426 }
6427 self.get_mut(app).origin = value;
6428 self.mark_needs_paint(app);
6429 }
6430
6431 pub fn alignment(self: RenderHandle<Self>, app: &App) -> Option<AlignmentGeometry> {
6445 self.get(app).alignment
6446 }
6447
6448 pub fn set_alignment(
6450 self: RenderHandle<Self>,
6451 app: &mut App,
6452 value: Option<AlignmentGeometry>,
6453 ) {
6454 if self.get(app).alignment == value {
6455 return;
6456 }
6457 self.get_mut(app).alignment = value;
6458 self.mark_needs_paint(app);
6459 }
6460
6461 pub fn text_direction(self: RenderHandle<Self>, app: &App) -> Option<TextDirection> {
6466 self.get(app).text_direction
6467 }
6468
6469 pub fn set_text_direction(
6471 self: RenderHandle<Self>,
6472 app: &mut App,
6473 value: Option<TextDirection>,
6474 ) {
6475 if self.get(app).text_direction == value {
6476 return;
6477 }
6478 self.get_mut(app).text_direction = value;
6479 self.mark_needs_paint(app);
6480 }
6481
6482 pub fn transform_hit_tests(self: RenderHandle<Self>, app: &App) -> bool {
6490 self.get(app).transform_hit_tests
6491 }
6492
6493 pub fn set_transform_hit_tests(self: RenderHandle<Self>, app: &mut App, value: bool) {
6495 self.get_mut(app).transform_hit_tests = value;
6496 }
6497
6498 pub fn set_transform(self: RenderHandle<Self>, app: &mut App, value: Matrix4) {
6504 if self.get(app).transform == value {
6505 return;
6506 }
6507 self.get_mut(app).transform = value;
6508 self.mark_needs_paint(app);
6509 }
6510
6511 pub fn filter_quality(self: RenderHandle<Self>, app: &App) -> Option<FilterQuality> {
6517 self.get(app).filter_quality
6518 }
6519
6520 pub fn set_filter_quality(
6522 self: RenderHandle<Self>,
6523 app: &mut App,
6524 value: Option<FilterQuality>,
6525 ) {
6526 if self.get(app).filter_quality == value {
6527 return;
6528 }
6529 let did_need_compositing = self.always_needs_compositing(app);
6530 self.get_mut(app).filter_quality = value;
6531 if did_need_compositing != self.always_needs_compositing(app) {
6532 self.mark_needs_compositing_bits_update(app);
6533 }
6534 self.mark_needs_paint(app);
6535 }
6536
6537 pub fn set_identity(self: RenderHandle<Self>, app: &mut App) {
6539 self.get_mut(app).transform = Matrix4::IDENTITY;
6540 self.mark_needs_paint(app);
6541 }
6542
6543 pub fn rotate_x(self: RenderHandle<Self>, app: &mut App, radians: f64) {
6545 let (sin, cos) = (radians.sin() as f32, radians.cos() as f32);
6546 #[rustfmt::skip]
6547 let rotation = Matrix4::from_flutter_array(&[
6548 1.0, 0.0, 0.0, 0.0,
6549 0.0, cos, sin, 0.0,
6550 0.0, -sin, cos, 0.0,
6551 0.0, 0.0, 0.0, 1.0,
6552 ]);
6553 self.concat(app, &rotation);
6554 }
6555
6556 pub fn rotate_y(self: RenderHandle<Self>, app: &mut App, radians: f64) {
6558 let (sin, cos) = (radians.sin() as f32, radians.cos() as f32);
6559 #[rustfmt::skip]
6560 let rotation = Matrix4::from_flutter_array(&[
6561 cos, 0.0, -sin, 0.0,
6562 0.0, 1.0, 0.0, 0.0,
6563 sin, 0.0, cos, 0.0,
6564 0.0, 0.0, 0.0, 1.0,
6565 ]);
6566 self.concat(app, &rotation);
6567 }
6568
6569 pub fn rotate_z(self: RenderHandle<Self>, app: &mut App, radians: f64) {
6571 let (sin, cos) = (radians.sin() as f32, radians.cos() as f32);
6572 #[rustfmt::skip]
6573 let rotation = Matrix4::from_flutter_array(&[
6574 cos, sin, 0.0, 0.0,
6575 -sin, cos, 0.0, 0.0,
6576 0.0, 0.0, 1.0, 0.0,
6577 0.0, 0.0, 0.0, 1.0,
6578 ]);
6579 self.concat(app, &rotation);
6580 }
6581
6582 pub fn translate(self: RenderHandle<Self>, app: &mut App, x: f64, y: f64, z: f64) {
6584 #[rustfmt::skip]
6585 let translation = Matrix4::from_flutter_array(&[
6586 1.0, 0.0, 0.0, 0.0,
6587 0.0, 1.0, 0.0, 0.0,
6588 0.0, 0.0, 1.0, 0.0,
6589 x as f32, y as f32, z as f32, 1.0,
6590 ]);
6591 self.concat(app, &translation);
6592 }
6593
6594 pub fn scale(self: RenderHandle<Self>, app: &mut App, x: f64, y: Option<f64>, z: Option<f64>) {
6596 let (y, z) = (y.unwrap_or(x) as f32, z.unwrap_or(x) as f32);
6597 #[rustfmt::skip]
6598 let scale = Matrix4::from_flutter_array(&[
6599 x as f32, 0.0, 0.0, 0.0,
6600 0.0, y, 0.0, 0.0,
6601 0.0, 0.0, z, 0.0,
6602 0.0, 0.0, 0.0, 1.0,
6603 ]);
6604 self.concat(app, &scale);
6605 }
6606
6607 fn concat(self: RenderHandle<Self>, app: &mut App, other: &Matrix4) {
6610 crate::object::multiply(&mut self.get_mut(app).transform, other);
6611 self.mark_needs_paint(app);
6612 }
6613
6614 fn effective_transform(self: RenderHandle<Self>, app: &App) -> Matrix4 {
6617 let this = self.get(app);
6618 let resolved_alignment = this
6619 .alignment
6620 .map(|alignment| alignment.resolve(this.text_direction));
6621 let origin = this.origin;
6622 if origin.is_none() && resolved_alignment.is_none() {
6623 return this.transform;
6624 }
6625 let mut result = Matrix4::IDENTITY;
6626 if let Some(origin) = origin {
6627 crate::object::translate(&mut result, origin.dx(), origin.dy());
6628 }
6629 let translation = resolved_alignment.map(|alignment| alignment.along_size(self.size(app)));
6630 if let Some(translation) = translation {
6631 crate::object::translate(&mut result, translation.dx(), translation.dy());
6632 }
6633 crate::object::multiply(&mut result, &self.get(app).transform);
6634 if let Some(translation) = translation {
6635 crate::object::translate(&mut result, -translation.dx(), -translation.dy());
6636 }
6637 if let Some(origin) = origin {
6638 crate::object::translate(&mut result, -origin.dx(), -origin.dy());
6639 }
6640 result
6641 }
6642
6643 fn paint_through_matrix_filter(
6646 self: RenderHandle<Self>,
6647 app: &mut App,
6648 context: &mut PaintingContext,
6649 offset: Offset,
6650 transform: Matrix4,
6651 filter_quality: FilterQuality,
6652 ) {
6653 let mut effective_transform = Matrix4::IDENTITY;
6654 crate::object::translate(&mut effective_transform, offset.dx(), offset.dy());
6655 crate::object::multiply(&mut effective_transform, &transform);
6656 crate::object::translate(&mut effective_transform, -offset.dx(), -offset.dy());
6657 let filter = ImageFilter::matrix(effective_transform, filter_quality);
6658 let layer = match self.as_object().layer_as::<ImageFilterLayer>(app) {
6659 Some(filter_layer) => filter_layer,
6660 None => {
6661 let layer = ImageFilterLayer::new(app);
6662 self.as_object()
6663 .set_layer(app, Some(layer.as_container_layer()));
6664 layer
6665 }
6666 };
6667 layer.set_image_filter(app, filter);
6668 context.push_layer(
6669 app,
6670 layer.as_container_layer(),
6671 |app, context, offset| RenderProxyBoxMixin::paint(self, app, context, offset),
6672 offset,
6673 None,
6674 );
6675 }
6676}
6677
6678impl RenderObjectWithChildMixin for RenderTransform {
6679 type ChildType = AnyRenderBox;
6680
6681 fn child_data(self: RenderHandle<Self>, app: &App) -> &RenderObjectWithChildData<AnyRenderBox> {
6682 &self.get(app).child
6683 }
6684
6685 fn child_data_mut(
6686 self: RenderHandle<Self>,
6687 app: &mut App,
6688 ) -> &mut RenderObjectWithChildData<AnyRenderBox> {
6689 &mut self.get_mut(app).child
6690 }
6691}
6692
6693impl RenderProxyBoxMixin for RenderTransform {}
6694
6695impl RenderObject for RenderTransform {
6696 crate::render_object_accessors!();
6697
6698 fn debug_fill_properties(
6699 self: RenderHandle<Self>,
6700 app: &App,
6701 properties: &mut DiagnosticPropertiesBuilder,
6702 ) {
6703 let this = self.get(app);
6704 properties.add(TransformProperty::new("transform matrix", this.transform));
6705 properties.add(DiagnosticsProperty::<Offset>::new("origin", this.origin));
6706 properties.add(DiagnosticsProperty::<AlignmentGeometry>::new(
6707 "alignment",
6708 this.alignment,
6709 ));
6710 properties.add(
6711 EnumProperty::<TextDirection>::new("textDirection", this.text_direction)
6712 .default_value(None),
6713 );
6714 properties.add(DiagnosticsProperty::<bool>::new(
6715 "transformHitTests",
6716 Some(this.transform_hit_tests),
6717 ));
6718 }
6719
6720 fn always_needs_compositing(self: RenderHandle<Self>, app: &App) -> bool {
6721 self.child(app).is_some() && self.get(app).filter_quality.is_some()
6722 }
6723
6724 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
6725 RenderProxyBoxMixin::perform_layout(self, app);
6726 }
6727
6728 fn paint(
6729 self: RenderHandle<Self>,
6730 app: &mut App,
6731 context: &mut PaintingContext,
6732 offset: Offset,
6733 ) {
6734 if self.child(app).is_none() {
6735 return;
6736 }
6737 let transform = self.effective_transform(app);
6738 if let Some(filter_quality) = self.filter_quality(app) {
6739 self.paint_through_matrix_filter(app, context, offset, transform, filter_quality);
6740 return;
6741 }
6742 let Some(child_offset) = get_as_translation(transform) else {
6743 let determinant = transform.determinant();
6746 if determinant == 0.0 || !determinant.is_finite() {
6747 self.as_object().set_layer(app, None);
6748 return;
6749 }
6750 let old = self.as_object().layer_as::<TransformLayer>(app);
6751 let layer = context.push_transform(
6752 app,
6753 self.as_object().needs_compositing(app),
6754 offset,
6755 transform,
6756 |app, context, offset| {
6757 RenderProxyBoxMixin::paint(self, app, context, offset);
6758 },
6759 old,
6760 );
6761 self.as_object()
6762 .set_layer(app, layer.map(|layer| layer.as_container_layer()));
6763 return;
6764 };
6765 RenderProxyBoxMixin::paint(self, app, context, offset + child_offset);
6766 self.as_object().set_layer(app, None);
6767 }
6768
6769 fn visit_children(
6770 self: RenderHandle<Self>,
6771 app: &App,
6772 visitor: &mut dyn FnMut(AnyRenderObject),
6773 ) {
6774 if let Some(child) = self.child(app) {
6775 visitor(child.as_object());
6776 }
6777 }
6778}
6779
6780impl RenderBox for RenderTransform {
6781 crate::render_box_accessors!();
6782
6783 fn setup_parent_data(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject) {
6784 RenderProxyBoxMixin::setup_parent_data(self, app, child);
6785 }
6786
6787 fn apply_paint_transform(
6788 self: RenderHandle<Self>,
6789 app: &App,
6790 _child: AnyRenderObject,
6791 transform: &mut Matrix4,
6792 ) {
6793 crate::object::multiply(transform, &self.effective_transform(app));
6794 }
6795
6796 fn hit_test(
6797 self: RenderHandle<Self>,
6798 app: &mut App,
6799 result: &mut BoxHitTestResult<'_>,
6800 position: Offset,
6801 ) -> bool {
6802 RenderBox::hit_test_children(self, app, result, position)
6807 }
6808
6809 fn hit_test_children(
6810 self: RenderHandle<Self>,
6811 app: &mut App,
6812 result: &mut BoxHitTestResult<'_>,
6813 position: Offset,
6814 ) -> bool {
6815 let transform = self
6816 .transform_hit_tests(app)
6817 .then(|| self.effective_transform(app));
6818 result.add_with_paint_transform(transform, position, |result, position| {
6819 RenderProxyBoxMixin::hit_test_children(self, app, result, position)
6820 })
6821 }
6822
6823 fn compute_min_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
6824 RenderProxyBoxMixin::compute_min_intrinsic_width(self, app, height)
6825 }
6826
6827 fn compute_max_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
6828 RenderProxyBoxMixin::compute_max_intrinsic_width(self, app, height)
6829 }
6830
6831 fn compute_min_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
6832 RenderProxyBoxMixin::compute_min_intrinsic_height(self, app, width)
6833 }
6834
6835 fn compute_max_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
6836 RenderProxyBoxMixin::compute_max_intrinsic_height(self, app, width)
6837 }
6838
6839 fn compute_distance_to_actual_baseline(
6840 self: RenderHandle<Self>,
6841 app: &mut App,
6842 baseline: TextBaseline,
6843 ) -> Option<f64> {
6844 RenderProxyBoxMixin::compute_distance_to_actual_baseline(self, app, baseline)
6845 }
6846
6847 fn compute_dry_baseline(
6848 self: RenderHandle<Self>,
6849 app: &mut App,
6850 constraints: BoxConstraints,
6851 baseline: TextBaseline,
6852 ) -> Option<f64> {
6853 RenderProxyBoxMixin::compute_dry_baseline(self, app, constraints, baseline)
6854 }
6855
6856 fn compute_dry_layout(
6857 self: RenderHandle<Self>,
6858 app: &mut App,
6859 constraints: BoxConstraints,
6860 ) -> Size {
6861 RenderProxyBoxMixin::compute_dry_layout(self, app, constraints)
6862 }
6863}
6864
6865pub struct RenderFittedBox {
6867 render_object: RenderObjectData,
6868 render_box: RenderBoxData,
6869 child: RenderObjectWithChildData<AnyRenderBox>,
6870 fit: BoxFit,
6871 alignment: AlignmentGeometry,
6872 text_direction: Option<TextDirection>,
6873 resolved_alignment: Option<Alignment>,
6874 clip_behavior: Clip,
6875 has_visual_overflow: Option<bool>,
6876 transform: Option<Matrix4>,
6877}
6878
6879fn fit_affects_layout(fit: BoxFit) -> bool {
6881 match fit {
6882 BoxFit::ScaleDown => true,
6883 BoxFit::Contain
6884 | BoxFit::Cover
6885 | BoxFit::Fill
6886 | BoxFit::FitHeight
6887 | BoxFit::FitWidth
6888 | BoxFit::None => false,
6889 }
6890}
6891
6892impl RenderFittedBox {
6893 pub fn new(
6895 app: &mut App,
6896 fit: BoxFit,
6897 alignment: AlignmentGeometry,
6898 text_direction: Option<TextDirection>,
6899 child: Option<AnyRenderBox>,
6900 ) -> RenderHandle<RenderFittedBox> {
6901 let this = RenderHandle::new_box(
6902 app,
6903 RenderFittedBox {
6904 render_object: RenderObjectData::new(),
6905 render_box: RenderBoxData::new(),
6906 child: RenderObjectWithChildData::new(),
6907 fit,
6908 alignment,
6909 text_direction,
6910 resolved_alignment: None,
6911 clip_behavior: Clip::None,
6912 has_visual_overflow: None,
6913 transform: None,
6914 },
6915 );
6916 this.set_child(app, child);
6917 this
6918 }
6919
6920 fn resolve(self: RenderHandle<Self>, app: &mut App) -> Alignment {
6921 let this = self.get(app);
6922 if let Some(resolved) = this.resolved_alignment {
6923 return resolved;
6924 }
6925 let resolved = this.alignment.resolve(this.text_direction);
6926 self.get_mut(app).resolved_alignment = Some(resolved);
6927 resolved
6928 }
6929
6930 fn mark_need_resolution(self: RenderHandle<Self>, app: &mut App) {
6931 self.get_mut(app).resolved_alignment = None;
6932 self.mark_needs_paint(app);
6933 }
6934
6935 pub fn fit(self: RenderHandle<Self>, app: &App) -> BoxFit {
6937 self.get(app).fit
6938 }
6939
6940 pub fn set_fit(self: RenderHandle<Self>, app: &mut App, value: BoxFit) {
6942 let last_fit = self.get(app).fit;
6943 if last_fit == value {
6944 return;
6945 }
6946 self.get_mut(app).fit = value;
6947 if fit_affects_layout(last_fit) || fit_affects_layout(value) {
6948 RenderBox::mark_needs_layout(self, app);
6949 } else {
6950 self.clear_paint_data(app);
6951 self.mark_needs_paint(app);
6952 }
6953 }
6954
6955 pub fn alignment(self: RenderHandle<Self>, app: &App) -> AlignmentGeometry {
6961 self.get(app).alignment
6962 }
6963
6964 pub fn set_alignment(self: RenderHandle<Self>, app: &mut App, value: AlignmentGeometry) {
6966 if self.get(app).alignment == value {
6967 return;
6968 }
6969 self.get_mut(app).alignment = value;
6970 self.clear_paint_data(app);
6971 self.mark_need_resolution(app);
6972 }
6973
6974 pub fn text_direction(self: RenderHandle<Self>, app: &App) -> Option<TextDirection> {
6976 self.get(app).text_direction
6977 }
6978
6979 pub fn set_text_direction(
6981 self: RenderHandle<Self>,
6982 app: &mut App,
6983 value: Option<TextDirection>,
6984 ) {
6985 if self.get(app).text_direction == value {
6986 return;
6987 }
6988 self.get_mut(app).text_direction = value;
6989 self.clear_paint_data(app);
6990 self.mark_need_resolution(app);
6991 }
6992
6993 pub fn clip_behavior(self: RenderHandle<Self>, app: &App) -> Clip {
6995 self.get(app).clip_behavior
6996 }
6997
6998 pub fn set_clip_behavior(self: RenderHandle<Self>, app: &mut App, value: Clip) {
7000 if self.get(app).clip_behavior == value {
7001 return;
7002 }
7003 self.get_mut(app).clip_behavior = value;
7004 self.mark_needs_paint(app);
7005 }
7006
7007 fn clear_paint_data(self: RenderHandle<Self>, app: &mut App) {
7008 let this = self.get_mut(app);
7009 this.has_visual_overflow = None;
7010 this.transform = None;
7011 }
7012
7013 fn paint_data(self: RenderHandle<Self>, app: &App) -> (bool, Matrix4) {
7016 let Some(child) = self.child(app) else {
7017 return (false, Matrix4::IDENTITY);
7018 };
7019 let this = self.get(app);
7020 let resolved_alignment = this
7021 .resolved_alignment
7022 .unwrap_or_else(|| this.alignment.resolve(this.text_direction));
7023 let child_size = child.size(app);
7024 let sizes = apply_box_fit(this.fit, child_size, self.size(app));
7025 let scale_x = sizes.destination.width() / sizes.source.width();
7026 let scale_y = sizes.destination.height() / sizes.source.height();
7027 let source_rect = resolved_alignment.inscribe(sizes.source, Offset::ZERO & child_size);
7028 let destination_rect =
7029 resolved_alignment.inscribe(sizes.destination, Offset::ZERO & self.size(app));
7030 debug_assert!(scale_x.is_finite() && scale_y.is_finite());
7031 let mut transform =
7032 Matrix4::translation(destination_rect.left as f32, destination_rect.top as f32);
7033 crate::object::multiply(
7034 &mut transform,
7035 &Matrix4::scale(scale_x as f32, scale_y as f32),
7036 );
7037 crate::object::translate(&mut transform, -source_rect.left, -source_rect.top);
7038 let has_visual_overflow =
7039 source_rect.width() < child_size.width() || source_rect.height() < child_size.height();
7040 (has_visual_overflow, transform)
7041 }
7042
7043 fn update_paint_data(self: RenderHandle<Self>, app: &mut App) {
7044 if self.get(app).transform.is_some() {
7045 return;
7046 }
7047 self.resolve(app);
7049 let (has_visual_overflow, transform) = self.paint_data(app);
7050 let this = self.get_mut(app);
7051 this.has_visual_overflow = Some(has_visual_overflow);
7052 this.transform = Some(transform);
7053 }
7054
7055 fn paint_child_with_transform(
7056 self: RenderHandle<Self>,
7057 app: &mut App,
7058 context: &mut PaintingContext,
7059 offset: Offset,
7060 ) -> Option<Handle<TransformLayer>> {
7061 let transform = self.get(app).transform.expect("update_paint_data ran");
7062 match get_as_translation(transform) {
7063 Some(child_offset) => {
7064 RenderProxyBoxMixin::paint(self, app, context, offset + child_offset);
7065 None
7066 }
7067 None => context.push_transform(
7068 app,
7069 self.as_object().needs_compositing(app),
7070 offset,
7071 transform,
7072 |app, context, offset| RenderProxyBoxMixin::paint(self, app, context, offset),
7073 self.as_object().layer_as::<TransformLayer>(app),
7074 ),
7075 }
7076 }
7077}
7078
7079impl RenderObjectWithChildMixin for RenderFittedBox {
7080 type ChildType = AnyRenderBox;
7081
7082 fn child_data(self: RenderHandle<Self>, app: &App) -> &RenderObjectWithChildData<AnyRenderBox> {
7083 &self.get(app).child
7084 }
7085
7086 fn child_data_mut(
7087 self: RenderHandle<Self>,
7088 app: &mut App,
7089 ) -> &mut RenderObjectWithChildData<AnyRenderBox> {
7090 &mut self.get_mut(app).child
7091 }
7092}
7093
7094impl RenderProxyBoxMixin for RenderFittedBox {}
7095
7096impl RenderObject for RenderFittedBox {
7097 crate::render_object_accessors!();
7098
7099 fn debug_fill_properties(
7100 self: RenderHandle<Self>,
7101 app: &App,
7102 properties: &mut DiagnosticPropertiesBuilder,
7103 ) {
7104 let this = self.get(app);
7105 properties.add(EnumProperty::<BoxFit>::new("fit", Some(this.fit)));
7106 properties.add(DiagnosticsProperty::<AlignmentGeometry>::new(
7107 "alignment",
7108 Some(this.alignment),
7109 ));
7110 properties.add(
7111 EnumProperty::<TextDirection>::new("textDirection", this.text_direction)
7112 .default_value(None),
7113 );
7114 }
7115
7116 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
7117 let constraints = self.constraints(app);
7118 let Some(child) = self.child(app) else {
7119 self.set_size(app, constraints.smallest());
7120 return;
7121 };
7122 child.layout(app, BoxConstraints::new(), true);
7123 let child_size = child.size(app);
7124 let size = match self.fit(app) {
7125 BoxFit::ScaleDown => {
7126 let size_constraints = constraints.loosen();
7127 let unconstrained_size = size_constraints
7128 .constrain_size_and_attempt_to_preserve_aspect_ratio(child_size);
7129 constraints.constrain(unconstrained_size)
7130 }
7131 BoxFit::Contain
7132 | BoxFit::Cover
7133 | BoxFit::Fill
7134 | BoxFit::FitHeight
7135 | BoxFit::FitWidth
7136 | BoxFit::None => {
7137 constraints.constrain_size_and_attempt_to_preserve_aspect_ratio(child_size)
7138 }
7139 };
7140 self.set_size(app, size);
7141 self.clear_paint_data(app);
7142 }
7143
7144 fn paint(
7145 self: RenderHandle<Self>,
7146 app: &mut App,
7147 context: &mut PaintingContext,
7148 offset: Offset,
7149 ) {
7150 let Some(child) = self.child(app) else {
7151 return;
7152 };
7153 if self.size(app).is_empty() || child.size(app).is_empty() {
7154 return;
7155 }
7156 self.update_paint_data(app);
7157 let clip_behavior = self.clip_behavior(app);
7158 if self.get(app).has_visual_overflow == Some(true) && clip_behavior != Clip::None {
7159 let clip_rect = Offset::ZERO & self.size(app);
7160 let old = self.as_object().layer_as::<ClipRectLayer>(app);
7161 let layer = context.push_clip_rect(
7162 app,
7163 self.as_object().needs_compositing(app),
7164 offset,
7165 clip_rect,
7166 |app, context, offset| {
7167 let _ = self.paint_child_with_transform(app, context, offset);
7168 },
7169 clip_behavior,
7170 old,
7171 );
7172 self.as_object()
7173 .set_layer(app, layer.map(|layer| layer.as_container_layer()));
7174 } else {
7175 let layer = self.paint_child_with_transform(app, context, offset);
7176 self.as_object()
7177 .set_layer(app, layer.map(|layer| layer.as_container_layer()));
7178 }
7179 }
7180
7181 fn paints_child(self: RenderHandle<Self>, app: &App, child: AnyRenderObject) -> bool {
7182 debug_assert!(child.parent(app) == Some(self.as_object()));
7183 let child = child.as_box().expect("a fitted box has a box child");
7184 !self.size(app).is_empty() && !child.size(app).is_empty()
7185 }
7186
7187 fn visit_children(
7188 self: RenderHandle<Self>,
7189 app: &App,
7190 visitor: &mut dyn FnMut(AnyRenderObject),
7191 ) {
7192 if let Some(child) = self.child(app) {
7193 visitor(child.as_object());
7194 }
7195 }
7196}
7197
7198impl RenderBox for RenderFittedBox {
7199 crate::render_box_accessors!();
7200
7201 fn setup_parent_data(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject) {
7202 RenderProxyBoxMixin::setup_parent_data(self, app, child);
7203 }
7204
7205 fn apply_paint_transform(
7206 self: RenderHandle<Self>,
7207 app: &App,
7208 child: AnyRenderObject,
7209 transform: &mut Matrix4,
7210 ) {
7211 if !RenderObject::paints_child(self, app, child) {
7212 *transform = crate::object::zero_matrix();
7213 return;
7214 }
7215 let (_, fitted) = self.paint_data(app);
7216 crate::object::multiply(transform, &fitted);
7217 }
7218
7219 fn hit_test_children(
7220 self: RenderHandle<Self>,
7221 app: &mut App,
7222 result: &mut BoxHitTestResult<'_>,
7223 position: Offset,
7224 ) -> bool {
7225 let child_is_empty = self
7226 .child(app)
7227 .is_none_or(|child| child.size(app).is_empty());
7228 if self.size(app).is_empty() || child_is_empty {
7229 return false;
7230 }
7231 self.update_paint_data(app);
7232 let transform = self.get(app).transform;
7233 result.add_with_paint_transform(transform, position, |result, position| {
7234 RenderProxyBoxMixin::hit_test_children(self, app, result, position)
7235 })
7236 }
7237
7238 fn compute_min_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
7239 RenderProxyBoxMixin::compute_min_intrinsic_width(self, app, height)
7240 }
7241
7242 fn compute_max_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
7243 RenderProxyBoxMixin::compute_max_intrinsic_width(self, app, height)
7244 }
7245
7246 fn compute_min_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
7247 RenderProxyBoxMixin::compute_min_intrinsic_height(self, app, width)
7248 }
7249
7250 fn compute_max_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
7251 RenderProxyBoxMixin::compute_max_intrinsic_height(self, app, width)
7252 }
7253
7254 fn compute_distance_to_actual_baseline(
7255 self: RenderHandle<Self>,
7256 app: &mut App,
7257 baseline: TextBaseline,
7258 ) -> Option<f64> {
7259 RenderProxyBoxMixin::compute_distance_to_actual_baseline(self, app, baseline)
7260 }
7261
7262 fn compute_dry_layout(
7263 self: RenderHandle<Self>,
7264 app: &mut App,
7265 constraints: BoxConstraints,
7266 ) -> Size {
7267 let Some(child) = self.child(app) else {
7268 return constraints.smallest();
7269 };
7270 let child_size = child.get_dry_layout(app, BoxConstraints::new());
7271 match self.fit(app) {
7272 BoxFit::ScaleDown => {
7273 let size_constraints = constraints.loosen();
7274 let unconstrained_size = size_constraints
7275 .constrain_size_and_attempt_to_preserve_aspect_ratio(child_size);
7276 constraints.constrain(unconstrained_size)
7277 }
7278 BoxFit::Contain
7279 | BoxFit::Cover
7280 | BoxFit::Fill
7281 | BoxFit::FitHeight
7282 | BoxFit::FitWidth
7283 | BoxFit::None => {
7284 constraints.constrain_size_and_attempt_to_preserve_aspect_ratio(child_size)
7285 }
7286 }
7287 }
7288
7289 fn compute_dry_baseline(
7290 self: RenderHandle<Self>,
7291 app: &mut App,
7292 _constraints: BoxConstraints,
7293 baseline: TextBaseline,
7294 ) -> Option<f64> {
7295 self.child(app)?
7298 .get_dry_baseline(app, BoxConstraints::new(), baseline)
7299 }
7300}
7301
7302pub struct RenderFractionalTranslation {
7312 render_object: RenderObjectData,
7313 render_box: RenderBoxData,
7314 child: RenderObjectWithChildData<AnyRenderBox>,
7315 translation: Offset,
7316 transform_hit_tests: bool,
7317}
7318
7319impl RenderFractionalTranslation {
7320 pub fn new(
7322 app: &mut App,
7323 translation: Offset,
7324 transform_hit_tests: bool,
7325 child: Option<AnyRenderBox>,
7326 ) -> RenderHandle<RenderFractionalTranslation> {
7327 let this = RenderHandle::new_box(
7328 app,
7329 RenderFractionalTranslation {
7330 render_object: RenderObjectData::new(),
7331 render_box: RenderBoxData::new(),
7332 child: RenderObjectWithChildData::new(),
7333 translation,
7334 transform_hit_tests,
7335 },
7336 );
7337 this.set_child(app, child);
7338 this
7339 }
7340
7341 pub fn translation(self: RenderHandle<Self>, app: &App) -> Offset {
7346 self.get(app).translation
7347 }
7348
7349 pub fn set_translation(self: RenderHandle<Self>, app: &mut App, value: Offset) {
7351 if self.get(app).translation == value {
7352 return;
7353 }
7354 self.get_mut(app).translation = value;
7355 self.mark_needs_paint(app);
7356 }
7357
7358 pub fn transform_hit_tests(self: RenderHandle<Self>, app: &App) -> bool {
7366 self.get(app).transform_hit_tests
7367 }
7368
7369 pub fn set_transform_hit_tests(self: RenderHandle<Self>, app: &mut App, value: bool) {
7371 self.get_mut(app).transform_hit_tests = value;
7372 }
7373
7374 fn absolute_translation(self: RenderHandle<Self>, app: &App) -> Offset {
7376 let translation = self.get(app).translation;
7377 let size = self.size(app);
7378 Offset::new(
7379 translation.dx() * size.width(),
7380 translation.dy() * size.height(),
7381 )
7382 }
7383}
7384
7385impl RenderObjectWithChildMixin for RenderFractionalTranslation {
7386 type ChildType = AnyRenderBox;
7387
7388 fn child_data(self: RenderHandle<Self>, app: &App) -> &RenderObjectWithChildData<AnyRenderBox> {
7389 &self.get(app).child
7390 }
7391
7392 fn child_data_mut(
7393 self: RenderHandle<Self>,
7394 app: &mut App,
7395 ) -> &mut RenderObjectWithChildData<AnyRenderBox> {
7396 &mut self.get_mut(app).child
7397 }
7398}
7399
7400impl RenderProxyBoxMixin for RenderFractionalTranslation {}
7401
7402impl RenderObject for RenderFractionalTranslation {
7403 crate::render_object_accessors!();
7404
7405 fn debug_fill_properties(
7406 self: RenderHandle<Self>,
7407 app: &App,
7408 properties: &mut DiagnosticPropertiesBuilder,
7409 ) {
7410 let this = self.get(app);
7411 properties.add(DiagnosticsProperty::<Offset>::new(
7412 "translation",
7413 Some(this.translation),
7414 ));
7415 properties.add(DiagnosticsProperty::<bool>::new(
7416 "transformHitTests",
7417 Some(this.transform_hit_tests),
7418 ));
7419 }
7420
7421 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
7422 RenderProxyBoxMixin::perform_layout(self, app);
7423 }
7424
7425 fn paint(
7426 self: RenderHandle<Self>,
7427 app: &mut App,
7428 context: &mut PaintingContext,
7429 offset: Offset,
7430 ) {
7431 debug_assert!(!self.debug_needs_layout(app));
7432 if self.child(app).is_none() {
7433 return;
7434 }
7435 let translation = self.absolute_translation(app);
7436 RenderProxyBoxMixin::paint(self, app, context, offset + translation);
7437 }
7438
7439 fn visit_children(
7440 self: RenderHandle<Self>,
7441 app: &App,
7442 visitor: &mut dyn FnMut(AnyRenderObject),
7443 ) {
7444 if let Some(child) = self.child(app) {
7445 visitor(child.as_object());
7446 }
7447 }
7448}
7449
7450impl RenderBox for RenderFractionalTranslation {
7451 crate::render_box_accessors!();
7452
7453 fn setup_parent_data(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject) {
7454 RenderProxyBoxMixin::setup_parent_data(self, app, child);
7455 }
7456
7457 fn apply_paint_transform(
7458 self: RenderHandle<Self>,
7459 app: &App,
7460 _child: AnyRenderObject,
7461 transform: &mut Matrix4,
7462 ) {
7463 let translation = self.absolute_translation(app);
7464 crate::object::translate(transform, translation.dx(), translation.dy());
7465 }
7466
7467 fn hit_test(
7468 self: RenderHandle<Self>,
7469 app: &mut App,
7470 result: &mut BoxHitTestResult<'_>,
7471 position: Offset,
7472 ) -> bool {
7473 RenderBox::hit_test_children(self, app, result, position)
7478 }
7479
7480 fn hit_test_children(
7481 self: RenderHandle<Self>,
7482 app: &mut App,
7483 result: &mut BoxHitTestResult<'_>,
7484 position: Offset,
7485 ) -> bool {
7486 debug_assert!(!self.debug_needs_layout(app));
7487 let offset = self
7488 .transform_hit_tests(app)
7489 .then(|| self.absolute_translation(app));
7490 result.add_with_paint_offset(offset, position, |result, position| {
7491 RenderProxyBoxMixin::hit_test_children(self, app, result, position)
7492 })
7493 }
7494
7495 fn compute_min_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
7496 RenderProxyBoxMixin::compute_min_intrinsic_width(self, app, height)
7497 }
7498
7499 fn compute_max_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
7500 RenderProxyBoxMixin::compute_max_intrinsic_width(self, app, height)
7501 }
7502
7503 fn compute_min_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
7504 RenderProxyBoxMixin::compute_min_intrinsic_height(self, app, width)
7505 }
7506
7507 fn compute_max_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
7508 RenderProxyBoxMixin::compute_max_intrinsic_height(self, app, width)
7509 }
7510
7511 fn compute_distance_to_actual_baseline(
7512 self: RenderHandle<Self>,
7513 app: &mut App,
7514 baseline: TextBaseline,
7515 ) -> Option<f64> {
7516 RenderProxyBoxMixin::compute_distance_to_actual_baseline(self, app, baseline)
7517 }
7518
7519 fn compute_dry_baseline(
7520 self: RenderHandle<Self>,
7521 app: &mut App,
7522 constraints: BoxConstraints,
7523 baseline: TextBaseline,
7524 ) -> Option<f64> {
7525 RenderProxyBoxMixin::compute_dry_baseline(self, app, constraints, baseline)
7526 }
7527
7528 fn compute_dry_layout(
7529 self: RenderHandle<Self>,
7530 app: &mut App,
7531 constraints: BoxConstraints,
7532 ) -> Size {
7533 RenderProxyBoxMixin::compute_dry_layout(self, app, constraints)
7534 }
7535}
7536
7537pub struct RenderIgnorePointer {
7549 render_object: RenderObjectData,
7550 render_box: RenderBoxData,
7551 child: RenderObjectWithChildData<AnyRenderBox>,
7552 ignoring: bool,
7553}
7554
7555impl RenderIgnorePointer {
7556 pub fn new(
7558 app: &mut App,
7559 ignoring: bool,
7560 child: Option<AnyRenderBox>,
7561 ) -> RenderHandle<RenderIgnorePointer> {
7562 let this = RenderHandle::new_box(
7563 app,
7564 RenderIgnorePointer {
7565 render_object: RenderObjectData::new(),
7566 render_box: RenderBoxData::new(),
7567 child: RenderObjectWithChildData::new(),
7568 ignoring,
7569 },
7570 );
7571 this.set_child(app, child);
7572 this
7573 }
7574
7575 pub fn ignoring(self: RenderHandle<Self>, app: &App) -> bool {
7580 self.get(app).ignoring
7581 }
7582
7583 pub fn set_ignoring(self: RenderHandle<Self>, app: &mut App, value: bool) {
7585 if value == self.get(app).ignoring {
7586 return;
7587 }
7588 self.get_mut(app).ignoring = value;
7589 }
7590}
7591
7592impl RenderObjectWithChildMixin for RenderIgnorePointer {
7593 type ChildType = AnyRenderBox;
7594
7595 fn child_data(self: RenderHandle<Self>, app: &App) -> &RenderObjectWithChildData<AnyRenderBox> {
7596 &self.get(app).child
7597 }
7598
7599 fn child_data_mut(
7600 self: RenderHandle<Self>,
7601 app: &mut App,
7602 ) -> &mut RenderObjectWithChildData<AnyRenderBox> {
7603 &mut self.get_mut(app).child
7604 }
7605}
7606
7607impl RenderProxyBoxMixin for RenderIgnorePointer {}
7608
7609impl RenderObject for RenderIgnorePointer {
7610 crate::render_object_accessors!();
7611
7612 fn debug_fill_properties(
7613 self: RenderHandle<Self>,
7614 app: &App,
7615 properties: &mut DiagnosticPropertiesBuilder,
7616 ) {
7617 properties.add(DiagnosticsProperty::<bool>::new(
7618 "ignoring",
7619 Some(self.get(app).ignoring),
7620 ));
7621 }
7622
7623 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
7624 RenderProxyBoxMixin::perform_layout(self, app);
7625 }
7626
7627 fn paint(
7628 self: RenderHandle<Self>,
7629 app: &mut App,
7630 context: &mut PaintingContext,
7631 offset: Offset,
7632 ) {
7633 RenderProxyBoxMixin::paint(self, app, context, offset);
7634 }
7635
7636 fn visit_children(
7637 self: RenderHandle<Self>,
7638 app: &App,
7639 visitor: &mut dyn FnMut(AnyRenderObject),
7640 ) {
7641 if let Some(child) = self.child(app) {
7642 visitor(child.as_object());
7643 }
7644 }
7645}
7646
7647impl RenderBox for RenderIgnorePointer {
7648 crate::render_box_accessors!();
7649
7650 fn setup_parent_data(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject) {
7651 RenderProxyBoxMixin::setup_parent_data(self, app, child);
7652 }
7653
7654 fn apply_paint_transform(
7655 self: RenderHandle<Self>,
7656 app: &App,
7657 child: AnyRenderObject,
7658 transform: &mut Matrix4,
7659 ) {
7660 RenderProxyBoxMixin::apply_paint_transform(self, app, child, transform);
7661 }
7662
7663 fn hit_test(
7664 self: RenderHandle<Self>,
7665 app: &mut App,
7666 result: &mut BoxHitTestResult<'_>,
7667 position: Offset,
7668 ) -> bool {
7669 !self.ignoring(app) && RenderBoxBase::hit_test(self, app, result, position)
7670 }
7671
7672 fn hit_test_children(
7673 self: RenderHandle<Self>,
7674 app: &mut App,
7675 result: &mut BoxHitTestResult<'_>,
7676 position: Offset,
7677 ) -> bool {
7678 RenderProxyBoxMixin::hit_test_children(self, app, result, position)
7679 }
7680
7681 fn compute_min_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
7682 RenderProxyBoxMixin::compute_min_intrinsic_width(self, app, height)
7683 }
7684
7685 fn compute_max_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
7686 RenderProxyBoxMixin::compute_max_intrinsic_width(self, app, height)
7687 }
7688
7689 fn compute_min_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
7690 RenderProxyBoxMixin::compute_min_intrinsic_height(self, app, width)
7691 }
7692
7693 fn compute_max_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
7694 RenderProxyBoxMixin::compute_max_intrinsic_height(self, app, width)
7695 }
7696
7697 fn compute_distance_to_actual_baseline(
7698 self: RenderHandle<Self>,
7699 app: &mut App,
7700 baseline: TextBaseline,
7701 ) -> Option<f64> {
7702 RenderProxyBoxMixin::compute_distance_to_actual_baseline(self, app, baseline)
7703 }
7704
7705 fn compute_dry_baseline(
7706 self: RenderHandle<Self>,
7707 app: &mut App,
7708 constraints: BoxConstraints,
7709 baseline: TextBaseline,
7710 ) -> Option<f64> {
7711 RenderProxyBoxMixin::compute_dry_baseline(self, app, constraints, baseline)
7712 }
7713
7714 fn compute_dry_layout(
7715 self: RenderHandle<Self>,
7716 app: &mut App,
7717 constraints: BoxConstraints,
7718 ) -> Size {
7719 RenderProxyBoxMixin::compute_dry_layout(self, app, constraints)
7720 }
7721}
7722
7723pub struct RenderOffstage {
7727 render_object: RenderObjectData,
7728 render_box: RenderBoxData,
7729 child: RenderObjectWithChildData<AnyRenderBox>,
7730 offstage: bool,
7731}
7732
7733impl RenderOffstage {
7734 pub fn new(
7736 app: &mut App,
7737 offstage: bool,
7738 child: Option<AnyRenderBox>,
7739 ) -> RenderHandle<RenderOffstage> {
7740 let this = RenderHandle::new_box(
7741 app,
7742 RenderOffstage {
7743 render_object: RenderObjectData::new(),
7744 render_box: RenderBoxData::new(),
7745 child: RenderObjectWithChildData::new(),
7746 offstage,
7747 },
7748 );
7749 this.set_child(app, child);
7750 this
7751 }
7752
7753 pub fn offstage(self: RenderHandle<Self>, app: &App) -> bool {
7761 self.get(app).offstage
7762 }
7763
7764 pub fn set_offstage(self: RenderHandle<Self>, app: &mut App, value: bool) {
7766 if value == self.get(app).offstage {
7767 return;
7768 }
7769 self.get_mut(app).offstage = value;
7770 self.as_object()
7771 .mark_needs_layout_for_sized_by_parent_change(app);
7772 }
7773}
7774
7775impl RenderObjectWithChildMixin for RenderOffstage {
7776 type ChildType = AnyRenderBox;
7777
7778 fn child_data(self: RenderHandle<Self>, app: &App) -> &RenderObjectWithChildData<AnyRenderBox> {
7779 &self.get(app).child
7780 }
7781
7782 fn child_data_mut(
7783 self: RenderHandle<Self>,
7784 app: &mut App,
7785 ) -> &mut RenderObjectWithChildData<AnyRenderBox> {
7786 &mut self.get_mut(app).child
7787 }
7788}
7789
7790impl RenderProxyBoxMixin for RenderOffstage {}
7791
7792impl RenderObject for RenderOffstage {
7793 crate::render_object_accessors!();
7794
7795 fn debug_fill_properties(
7796 self: RenderHandle<Self>,
7797 app: &App,
7798 properties: &mut DiagnosticPropertiesBuilder,
7799 ) {
7800 properties.add(DiagnosticsProperty::<bool>::new(
7801 "offstage",
7802 Some(self.get(app).offstage),
7803 ));
7804 }
7805
7806 fn debug_describe_children(
7807 self: RenderHandle<Self>,
7808 app: &App,
7809 ) -> Vec<Rc<dyn waft_foundation::DiagnosticsNode>> {
7810 let Some(child) = self.child(app) else {
7811 return Vec::new();
7812 };
7813 let style = if self.get(app).offstage {
7814 waft_foundation::DiagnosticsTreeStyle::Offstage
7815 } else {
7816 waft_foundation::DiagnosticsTreeStyle::Sparse
7817 };
7818 vec![Rc::new(
7819 child
7820 .as_object()
7821 .to_diagnostics_node(app, "child")
7822 .with_style(style),
7823 )]
7824 }
7825
7826 fn sized_by_parent(self: RenderHandle<Self>, app: &App) -> bool {
7827 self.get(app).offstage
7828 }
7829
7830 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
7831 if !self.get(app).offstage {
7832 RenderProxyBoxMixin::perform_layout(self, app);
7833 return;
7834 }
7835 if let Some(child) = self.child(app) {
7836 let constraints = self.constraints(app);
7837 child.layout(app, constraints, false);
7838 }
7839 }
7840
7841 fn paint(
7842 self: RenderHandle<Self>,
7843 app: &mut App,
7844 context: &mut PaintingContext,
7845 offset: Offset,
7846 ) {
7847 if self.get(app).offstage {
7848 return;
7849 }
7850 RenderProxyBoxMixin::paint(self, app, context, offset);
7851 }
7852
7853 fn paints_child(self: RenderHandle<Self>, app: &App, child: AnyRenderObject) -> bool {
7854 debug_assert!(child.parent(app) == Some(self.as_object()));
7855 !self.get(app).offstage
7856 }
7857
7858 fn visit_children(
7859 self: RenderHandle<Self>,
7860 app: &App,
7861 visitor: &mut dyn FnMut(AnyRenderObject),
7862 ) {
7863 if let Some(child) = self.child(app) {
7864 visitor(child.as_object());
7865 }
7866 }
7867}
7868
7869impl RenderBox for RenderOffstage {
7870 crate::render_box_accessors!();
7871
7872 fn setup_parent_data(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject) {
7873 RenderProxyBoxMixin::setup_parent_data(self, app, child);
7874 }
7875
7876 fn apply_paint_transform(
7877 self: RenderHandle<Self>,
7878 app: &App,
7879 child: AnyRenderObject,
7880 transform: &mut Matrix4,
7881 ) {
7882 RenderProxyBoxMixin::apply_paint_transform(self, app, child, transform);
7883 }
7884
7885 fn hit_test(
7886 self: RenderHandle<Self>,
7887 app: &mut App,
7888 result: &mut BoxHitTestResult<'_>,
7889 position: Offset,
7890 ) -> bool {
7891 !self.get(app).offstage && RenderBoxBase::hit_test(self, app, result, position)
7892 }
7893
7894 fn hit_test_children(
7895 self: RenderHandle<Self>,
7896 app: &mut App,
7897 result: &mut BoxHitTestResult<'_>,
7898 position: Offset,
7899 ) -> bool {
7900 RenderProxyBoxMixin::hit_test_children(self, app, result, position)
7901 }
7902
7903 fn compute_min_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
7904 if self.get(app).offstage {
7905 return 0.0;
7906 }
7907 RenderProxyBoxMixin::compute_min_intrinsic_width(self, app, height)
7908 }
7909
7910 fn compute_max_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
7911 if self.get(app).offstage {
7912 return 0.0;
7913 }
7914 RenderProxyBoxMixin::compute_max_intrinsic_width(self, app, height)
7915 }
7916
7917 fn compute_min_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
7918 if self.get(app).offstage {
7919 return 0.0;
7920 }
7921 RenderProxyBoxMixin::compute_min_intrinsic_height(self, app, width)
7922 }
7923
7924 fn compute_max_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
7925 if self.get(app).offstage {
7926 return 0.0;
7927 }
7928 RenderProxyBoxMixin::compute_max_intrinsic_height(self, app, width)
7929 }
7930
7931 fn compute_distance_to_actual_baseline(
7932 self: RenderHandle<Self>,
7933 app: &mut App,
7934 baseline: TextBaseline,
7935 ) -> Option<f64> {
7936 if self.get(app).offstage {
7937 return None;
7938 }
7939 RenderProxyBoxMixin::compute_distance_to_actual_baseline(self, app, baseline)
7940 }
7941
7942 fn compute_dry_baseline(
7943 self: RenderHandle<Self>,
7944 app: &mut App,
7945 constraints: BoxConstraints,
7946 baseline: TextBaseline,
7947 ) -> Option<f64> {
7948 if self.get(app).offstage {
7949 return None;
7950 }
7951 RenderProxyBoxMixin::compute_dry_baseline(self, app, constraints, baseline)
7952 }
7953
7954 fn compute_dry_layout(
7955 self: RenderHandle<Self>,
7956 app: &mut App,
7957 constraints: BoxConstraints,
7958 ) -> Size {
7959 if self.get(app).offstage {
7960 return constraints.smallest();
7961 }
7962 RenderProxyBoxMixin::compute_dry_layout(self, app, constraints)
7963 }
7964
7965 fn perform_resize(self: RenderHandle<Self>, app: &mut App) {
7967 debug_assert!(self.get(app).offstage);
7968 RenderBoxBase::perform_resize(self, app);
7969 }
7970}
7971
7972pub struct RenderAbsorbPointer {
7985 render_object: RenderObjectData,
7986 render_box: RenderBoxData,
7987 child: RenderObjectWithChildData<AnyRenderBox>,
7988 absorbing: bool,
7989}
7990
7991impl RenderAbsorbPointer {
7992 pub fn new(
7994 app: &mut App,
7995 absorbing: bool,
7996 child: Option<AnyRenderBox>,
7997 ) -> RenderHandle<RenderAbsorbPointer> {
7998 let this = RenderHandle::new_box(
7999 app,
8000 RenderAbsorbPointer {
8001 render_object: RenderObjectData::new(),
8002 render_box: RenderBoxData::new(),
8003 child: RenderObjectWithChildData::new(),
8004 absorbing,
8005 },
8006 );
8007 this.set_child(app, child);
8008 this
8009 }
8010
8011 pub fn absorbing(self: RenderHandle<Self>, app: &App) -> bool {
8017 self.get(app).absorbing
8018 }
8019
8020 pub fn set_absorbing(self: RenderHandle<Self>, app: &mut App, value: bool) {
8022 if self.get(app).absorbing == value {
8023 return;
8024 }
8025 self.get_mut(app).absorbing = value;
8026 }
8027}
8028
8029impl RenderObjectWithChildMixin for RenderAbsorbPointer {
8030 type ChildType = AnyRenderBox;
8031
8032 fn child_data(self: RenderHandle<Self>, app: &App) -> &RenderObjectWithChildData<AnyRenderBox> {
8033 &self.get(app).child
8034 }
8035
8036 fn child_data_mut(
8037 self: RenderHandle<Self>,
8038 app: &mut App,
8039 ) -> &mut RenderObjectWithChildData<AnyRenderBox> {
8040 &mut self.get_mut(app).child
8041 }
8042}
8043
8044impl RenderProxyBoxMixin for RenderAbsorbPointer {}
8045
8046impl RenderObject for RenderAbsorbPointer {
8047 crate::render_object_accessors!();
8048
8049 fn debug_fill_properties(
8050 self: RenderHandle<Self>,
8051 app: &App,
8052 properties: &mut DiagnosticPropertiesBuilder,
8053 ) {
8054 properties.add(DiagnosticsProperty::<bool>::new(
8055 "absorbing",
8056 Some(self.get(app).absorbing),
8057 ));
8058 }
8059
8060 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
8061 RenderProxyBoxMixin::perform_layout(self, app);
8062 }
8063
8064 fn paint(
8065 self: RenderHandle<Self>,
8066 app: &mut App,
8067 context: &mut PaintingContext,
8068 offset: Offset,
8069 ) {
8070 RenderProxyBoxMixin::paint(self, app, context, offset);
8071 }
8072
8073 fn visit_children(
8074 self: RenderHandle<Self>,
8075 app: &App,
8076 visitor: &mut dyn FnMut(AnyRenderObject),
8077 ) {
8078 if let Some(child) = self.child(app) {
8079 visitor(child.as_object());
8080 }
8081 }
8082}
8083
8084impl RenderBox for RenderAbsorbPointer {
8085 crate::render_box_accessors!();
8086
8087 fn setup_parent_data(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject) {
8088 RenderProxyBoxMixin::setup_parent_data(self, app, child);
8089 }
8090
8091 fn apply_paint_transform(
8092 self: RenderHandle<Self>,
8093 app: &App,
8094 child: AnyRenderObject,
8095 transform: &mut Matrix4,
8096 ) {
8097 RenderProxyBoxMixin::apply_paint_transform(self, app, child, transform);
8098 }
8099
8100 fn hit_test(
8101 self: RenderHandle<Self>,
8102 app: &mut App,
8103 result: &mut BoxHitTestResult<'_>,
8104 position: Offset,
8105 ) -> bool {
8106 if self.absorbing(app) {
8107 return self.size(app).contains(position);
8108 }
8109 RenderBoxBase::hit_test(self, app, result, position)
8110 }
8111
8112 fn hit_test_children(
8113 self: RenderHandle<Self>,
8114 app: &mut App,
8115 result: &mut BoxHitTestResult<'_>,
8116 position: Offset,
8117 ) -> bool {
8118 RenderProxyBoxMixin::hit_test_children(self, app, result, position)
8119 }
8120
8121 fn compute_min_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
8122 RenderProxyBoxMixin::compute_min_intrinsic_width(self, app, height)
8123 }
8124
8125 fn compute_max_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
8126 RenderProxyBoxMixin::compute_max_intrinsic_width(self, app, height)
8127 }
8128
8129 fn compute_min_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
8130 RenderProxyBoxMixin::compute_min_intrinsic_height(self, app, width)
8131 }
8132
8133 fn compute_max_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
8134 RenderProxyBoxMixin::compute_max_intrinsic_height(self, app, width)
8135 }
8136
8137 fn compute_distance_to_actual_baseline(
8138 self: RenderHandle<Self>,
8139 app: &mut App,
8140 baseline: TextBaseline,
8141 ) -> Option<f64> {
8142 RenderProxyBoxMixin::compute_distance_to_actual_baseline(self, app, baseline)
8143 }
8144
8145 fn compute_dry_baseline(
8146 self: RenderHandle<Self>,
8147 app: &mut App,
8148 constraints: BoxConstraints,
8149 baseline: TextBaseline,
8150 ) -> Option<f64> {
8151 RenderProxyBoxMixin::compute_dry_baseline(self, app, constraints, baseline)
8152 }
8153
8154 fn compute_dry_layout(
8155 self: RenderHandle<Self>,
8156 app: &mut App,
8157 constraints: BoxConstraints,
8158 ) -> Size {
8159 RenderProxyBoxMixin::compute_dry_layout(self, app, constraints)
8160 }
8161}
8162
8163pub struct RenderColoredBox {
8168 render_object: RenderObjectData,
8169 render_box: RenderBoxData,
8170 child: RenderObjectWithChildData<AnyRenderBox>,
8171 color: Color,
8172 is_anti_alias: bool,
8173 behavior: HitTestBehavior,
8174}
8175
8176impl RenderColoredBox {
8177 pub fn new(
8179 app: &mut App,
8180 color: Color,
8181 is_anti_alias: bool,
8182 child: Option<AnyRenderBox>,
8183 ) -> RenderHandle<RenderColoredBox> {
8184 let this = RenderHandle::new_box(
8185 app,
8186 RenderColoredBox {
8187 render_object: RenderObjectData::new(),
8188 render_box: RenderBoxData::new(),
8189 child: RenderObjectWithChildData::new(),
8190 color,
8191 is_anti_alias,
8192 behavior: HitTestBehavior::Opaque,
8193 },
8194 );
8195 this.set_child(app, child);
8196 this
8197 }
8198
8199 pub fn color(self: RenderHandle<Self>, app: &App) -> Color {
8201 self.get(app).color
8202 }
8203
8204 pub fn set_color(self: RenderHandle<Self>, app: &mut App, value: Color) {
8206 if value == self.get(app).color {
8207 return;
8208 }
8209 self.get_mut(app).color = value;
8210 self.mark_needs_paint(app);
8211 }
8212
8213 pub fn is_anti_alias(self: RenderHandle<Self>, app: &App) -> bool {
8215 self.get(app).is_anti_alias
8216 }
8217
8218 pub fn set_is_anti_alias(self: RenderHandle<Self>, app: &mut App, value: bool) {
8220 if value == self.get(app).is_anti_alias {
8221 return;
8222 }
8223 self.get_mut(app).is_anti_alias = value;
8224 self.mark_needs_paint(app);
8225 }
8226}
8227
8228impl RenderObjectWithChildMixin for RenderColoredBox {
8229 type ChildType = AnyRenderBox;
8230
8231 fn child_data(self: RenderHandle<Self>, app: &App) -> &RenderObjectWithChildData<AnyRenderBox> {
8232 &self.get(app).child
8233 }
8234
8235 fn child_data_mut(
8236 self: RenderHandle<Self>,
8237 app: &mut App,
8238 ) -> &mut RenderObjectWithChildData<AnyRenderBox> {
8239 &mut self.get_mut(app).child
8240 }
8241}
8242
8243impl RenderProxyBoxMixin for RenderColoredBox {}
8244
8245impl RenderProxyBoxWithHitTestBehavior for RenderColoredBox {
8246 fn behavior(self: RenderHandle<Self>, app: &App) -> HitTestBehavior {
8247 self.get(app).behavior
8248 }
8249}
8250
8251impl RenderObject for RenderColoredBox {
8252 crate::render_object_accessors!();
8253
8254 fn debug_fill_properties(
8255 self: RenderHandle<Self>,
8256 app: &App,
8257 properties: &mut DiagnosticPropertiesBuilder,
8258 ) {
8259 RenderProxyBoxWithHitTestBehavior::debug_fill_properties(self, app, properties);
8260 }
8261
8262 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
8263 RenderProxyBoxMixin::perform_layout(self, app);
8264 }
8265
8266 fn paint(
8267 self: RenderHandle<Self>,
8268 app: &mut App,
8269 context: &mut PaintingContext,
8270 offset: Offset,
8271 ) {
8272 let size = self.size(app);
8277 if size.gt(&Size::ZERO) {
8278 let paint = Paint {
8279 color: self.get(app).color.into(),
8280 ..Paint::default()
8281 };
8282 context.canvas().draw_rect(offset & size, &paint);
8283 }
8284 if let Some(child) = self.child(app) {
8285 context.paint_child(app, child.as_object(), offset);
8286 }
8287 }
8288
8289 fn visit_children(
8290 self: RenderHandle<Self>,
8291 app: &App,
8292 visitor: &mut dyn FnMut(AnyRenderObject),
8293 ) {
8294 if let Some(child) = self.child(app) {
8295 visitor(child.as_object());
8296 }
8297 }
8298}
8299
8300impl RenderBox for RenderColoredBox {
8301 crate::render_box_accessors!();
8302
8303 fn setup_parent_data(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject) {
8304 RenderProxyBoxMixin::setup_parent_data(self, app, child);
8305 }
8306
8307 fn apply_paint_transform(
8308 self: RenderHandle<Self>,
8309 app: &App,
8310 child: AnyRenderObject,
8311 transform: &mut Matrix4,
8312 ) {
8313 RenderProxyBoxMixin::apply_paint_transform(self, app, child, transform);
8314 }
8315
8316 fn hit_test(
8317 self: RenderHandle<Self>,
8318 app: &mut App,
8319 result: &mut BoxHitTestResult<'_>,
8320 position: Offset,
8321 ) -> bool {
8322 RenderProxyBoxWithHitTestBehavior::hit_test(self, app, result, position)
8323 }
8324
8325 fn hit_test_self(self: RenderHandle<Self>, app: &App, position: Offset) -> bool {
8326 RenderProxyBoxWithHitTestBehavior::hit_test_self(self, app, position)
8327 }
8328
8329 fn hit_test_children(
8330 self: RenderHandle<Self>,
8331 app: &mut App,
8332 result: &mut BoxHitTestResult<'_>,
8333 position: Offset,
8334 ) -> bool {
8335 RenderProxyBoxMixin::hit_test_children(self, app, result, position)
8336 }
8337
8338 fn compute_min_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
8339 RenderProxyBoxMixin::compute_min_intrinsic_width(self, app, height)
8340 }
8341
8342 fn compute_max_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
8343 RenderProxyBoxMixin::compute_max_intrinsic_width(self, app, height)
8344 }
8345
8346 fn compute_min_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
8347 RenderProxyBoxMixin::compute_min_intrinsic_height(self, app, width)
8348 }
8349
8350 fn compute_max_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
8351 RenderProxyBoxMixin::compute_max_intrinsic_height(self, app, width)
8352 }
8353
8354 fn compute_distance_to_actual_baseline(
8355 self: RenderHandle<Self>,
8356 app: &mut App,
8357 baseline: TextBaseline,
8358 ) -> Option<f64> {
8359 RenderProxyBoxMixin::compute_distance_to_actual_baseline(self, app, baseline)
8360 }
8361
8362 fn compute_dry_baseline(
8363 self: RenderHandle<Self>,
8364 app: &mut App,
8365 constraints: BoxConstraints,
8366 baseline: TextBaseline,
8367 ) -> Option<f64> {
8368 RenderProxyBoxMixin::compute_dry_baseline(self, app, constraints, baseline)
8369 }
8370
8371 fn compute_dry_layout(
8372 self: RenderHandle<Self>,
8373 app: &mut App,
8374 constraints: BoxConstraints,
8375 ) -> Size {
8376 RenderProxyBoxMixin::compute_dry_layout(self, app, constraints)
8377 }
8378}
8379
8380pub struct RenderMetaData {
8387 render_object: RenderObjectData,
8388 render_box: RenderBoxData,
8389 child: RenderObjectWithChildData<AnyRenderBox>,
8390 meta_data: Option<Rc<dyn Any>>,
8391 behavior: HitTestBehavior,
8392}
8393
8394impl RenderMetaData {
8395 pub fn new(
8399 app: &mut App,
8400 meta_data: Option<Rc<dyn Any>>,
8401 behavior: HitTestBehavior,
8402 child: Option<AnyRenderBox>,
8403 ) -> RenderHandle<Self> {
8404 let this = RenderHandle::new_box(
8405 app,
8406 RenderMetaData {
8407 render_object: RenderObjectData::new(),
8408 render_box: RenderBoxData::new(),
8409 child: RenderObjectWithChildData::new(),
8410 meta_data,
8411 behavior,
8412 },
8413 );
8414 this.set_child(app, child);
8415 this
8416 }
8417
8418 pub fn meta_data(self: RenderHandle<Self>, app: &App) -> Option<Rc<dyn Any>> {
8420 self.get(app).meta_data.clone()
8421 }
8422
8423 pub fn set_meta_data(self: RenderHandle<Self>, app: &mut App, value: Option<Rc<dyn Any>>) {
8425 self.get_mut(app).meta_data = value;
8426 }
8427
8428 pub fn set_behavior(self: RenderHandle<Self>, app: &mut App, value: HitTestBehavior) {
8430 self.get_mut(app).behavior = value;
8431 }
8432}
8433
8434impl RenderObjectWithChildMixin for RenderMetaData {
8435 type ChildType = AnyRenderBox;
8436
8437 fn child_data(self: RenderHandle<Self>, app: &App) -> &RenderObjectWithChildData<AnyRenderBox> {
8438 &self.get(app).child
8439 }
8440
8441 fn child_data_mut(
8442 self: RenderHandle<Self>,
8443 app: &mut App,
8444 ) -> &mut RenderObjectWithChildData<AnyRenderBox> {
8445 &mut self.get_mut(app).child
8446 }
8447}
8448
8449impl RenderProxyBoxMixin for RenderMetaData {}
8450
8451impl RenderProxyBoxWithHitTestBehavior for RenderMetaData {
8452 fn behavior(self: RenderHandle<Self>, app: &App) -> HitTestBehavior {
8453 self.get(app).behavior
8454 }
8455}
8456
8457impl RenderObject for RenderMetaData {
8458 crate::render_object_accessors!();
8459
8460 fn debug_fill_properties(
8461 self: RenderHandle<Self>,
8462 app: &App,
8463 properties: &mut DiagnosticPropertiesBuilder,
8464 ) {
8465 RenderProxyBoxWithHitTestBehavior::debug_fill_properties(self, app, properties);
8466 let meta_data = self.get(app).meta_data.clone();
8467 properties.add(DiagnosticsProperty::<String>::new(
8468 "metaData",
8469 meta_data.map(|_| "Instance of 'Object'".to_string()),
8470 ));
8471 }
8472
8473 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
8474 RenderProxyBoxMixin::perform_layout(self, app);
8475 }
8476
8477 fn paint(
8478 self: RenderHandle<Self>,
8479 app: &mut App,
8480 context: &mut PaintingContext,
8481 offset: Offset,
8482 ) {
8483 RenderProxyBoxMixin::paint(self, app, context, offset);
8484 }
8485
8486 fn visit_children(
8487 self: RenderHandle<Self>,
8488 app: &App,
8489 visitor: &mut dyn FnMut(AnyRenderObject),
8490 ) {
8491 if let Some(child) = self.child(app) {
8492 visitor(child.as_object());
8493 }
8494 }
8495}
8496
8497impl RenderBox for RenderMetaData {
8498 crate::render_box_accessors!();
8499
8500 fn setup_parent_data(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject) {
8501 RenderProxyBoxMixin::setup_parent_data(self, app, child);
8502 }
8503
8504 fn apply_paint_transform(
8505 self: RenderHandle<Self>,
8506 app: &App,
8507 child: AnyRenderObject,
8508 transform: &mut Matrix4,
8509 ) {
8510 RenderProxyBoxMixin::apply_paint_transform(self, app, child, transform);
8511 }
8512
8513 fn hit_test(
8514 self: RenderHandle<Self>,
8515 app: &mut App,
8516 result: &mut BoxHitTestResult<'_>,
8517 position: Offset,
8518 ) -> bool {
8519 RenderProxyBoxWithHitTestBehavior::hit_test(self, app, result, position)
8520 }
8521
8522 fn hit_test_self(self: RenderHandle<Self>, app: &App, position: Offset) -> bool {
8523 RenderProxyBoxWithHitTestBehavior::hit_test_self(self, app, position)
8524 }
8525
8526 fn hit_test_children(
8527 self: RenderHandle<Self>,
8528 app: &mut App,
8529 result: &mut BoxHitTestResult<'_>,
8530 position: Offset,
8531 ) -> bool {
8532 RenderProxyBoxMixin::hit_test_children(self, app, result, position)
8533 }
8534
8535 fn compute_min_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
8536 RenderProxyBoxMixin::compute_min_intrinsic_width(self, app, height)
8537 }
8538
8539 fn compute_max_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
8540 RenderProxyBoxMixin::compute_max_intrinsic_width(self, app, height)
8541 }
8542
8543 fn compute_min_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
8544 RenderProxyBoxMixin::compute_min_intrinsic_height(self, app, width)
8545 }
8546
8547 fn compute_max_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
8548 RenderProxyBoxMixin::compute_max_intrinsic_height(self, app, width)
8549 }
8550
8551 fn compute_distance_to_actual_baseline(
8552 self: RenderHandle<Self>,
8553 app: &mut App,
8554 baseline: TextBaseline,
8555 ) -> Option<f64> {
8556 RenderProxyBoxMixin::compute_distance_to_actual_baseline(self, app, baseline)
8557 }
8558
8559 fn compute_dry_baseline(
8560 self: RenderHandle<Self>,
8561 app: &mut App,
8562 constraints: BoxConstraints,
8563 baseline: TextBaseline,
8564 ) -> Option<f64> {
8565 RenderProxyBoxMixin::compute_dry_baseline(self, app, constraints, baseline)
8566 }
8567
8568 fn compute_dry_layout(
8569 self: RenderHandle<Self>,
8570 app: &mut App,
8571 constraints: BoxConstraints,
8572 ) -> Size {
8573 RenderProxyBoxMixin::compute_dry_layout(self, app, constraints)
8574 }
8575}
8576
8577pub struct RenderSemanticsAnnotations {
8579 render_object: RenderObjectData,
8580 render_box: RenderBoxData,
8581 child: RenderObjectWithChildData<AnyRenderBox>,
8582 semantics_annotations: SemanticsAnnotationsData,
8583}
8584
8585impl RenderSemanticsAnnotations {
8586 #[allow(clippy::too_many_arguments)]
8592 pub fn new(
8593 app: &mut App,
8594 properties: Rc<SemanticsProperties>,
8595 container: bool,
8596 explicit_child_nodes: bool,
8597 exclude_semantics: bool,
8598 block_user_actions: bool,
8599 locale_for_subtree: Option<Locale>,
8600 text_direction: Option<TextDirection>,
8601 child: Option<AnyRenderBox>,
8602 ) -> RenderHandle<RenderSemanticsAnnotations> {
8603 let this = RenderHandle::new_box(
8604 app,
8605 RenderSemanticsAnnotations {
8606 render_object: RenderObjectData::new(),
8607 render_box: RenderBoxData::new(),
8608 child: RenderObjectWithChildData::new(),
8609 semantics_annotations: SemanticsAnnotationsData::new(),
8610 },
8611 );
8612 this.set_child(app, child);
8613 this.init_semantics_annotations(
8614 app,
8615 properties,
8616 container,
8617 explicit_child_nodes,
8618 exclude_semantics,
8619 block_user_actions,
8620 locale_for_subtree,
8621 text_direction,
8622 );
8623 this
8624 }
8625}
8626
8627impl SemanticsAnnotationsMixin for RenderSemanticsAnnotations {
8628 fn semantics_annotations_data(
8629 self: RenderHandle<Self>,
8630 app: &App,
8631 ) -> &SemanticsAnnotationsData {
8632 &self.get(app).semantics_annotations
8633 }
8634
8635 fn semantics_annotations_data_mut(
8636 self: RenderHandle<Self>,
8637 app: &mut App,
8638 ) -> &mut SemanticsAnnotationsData {
8639 &mut self.get_mut(app).semantics_annotations
8640 }
8641}
8642
8643impl RenderObjectWithChildMixin for RenderSemanticsAnnotations {
8644 type ChildType = AnyRenderBox;
8645
8646 fn child_data(self: RenderHandle<Self>, app: &App) -> &RenderObjectWithChildData<AnyRenderBox> {
8647 &self.get(app).child
8648 }
8649
8650 fn child_data_mut(
8651 self: RenderHandle<Self>,
8652 app: &mut App,
8653 ) -> &mut RenderObjectWithChildData<AnyRenderBox> {
8654 &mut self.get_mut(app).child
8655 }
8656}
8657
8658impl RenderProxyBoxMixin for RenderSemanticsAnnotations {}
8659
8660impl RenderObject for RenderSemanticsAnnotations {
8661 crate::render_object_accessors!();
8662
8663 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
8664 RenderProxyBoxMixin::perform_layout(self, app);
8665 }
8666
8667 fn paint(
8668 self: RenderHandle<Self>,
8669 app: &mut App,
8670 context: &mut PaintingContext,
8671 offset: Offset,
8672 ) {
8673 RenderProxyBoxMixin::paint(self, app, context, offset);
8674 }
8675
8676 fn visit_children(
8677 self: RenderHandle<Self>,
8678 app: &App,
8679 visitor: &mut dyn FnMut(AnyRenderObject),
8680 ) {
8681 if let Some(child) = self.child(app) {
8682 visitor(child.as_object());
8683 }
8684 }
8685}
8686
8687impl RenderBox for RenderSemanticsAnnotations {
8688 crate::render_box_accessors!();
8689
8690 fn setup_parent_data(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject) {
8691 RenderProxyBoxMixin::setup_parent_data(self, app, child);
8692 }
8693
8694 fn apply_paint_transform(
8695 self: RenderHandle<Self>,
8696 app: &App,
8697 child: AnyRenderObject,
8698 transform: &mut Matrix4,
8699 ) {
8700 RenderProxyBoxMixin::apply_paint_transform(self, app, child, transform);
8701 }
8702
8703 fn hit_test_children(
8704 self: RenderHandle<Self>,
8705 app: &mut App,
8706 result: &mut BoxHitTestResult<'_>,
8707 position: Offset,
8708 ) -> bool {
8709 RenderProxyBoxMixin::hit_test_children(self, app, result, position)
8710 }
8711
8712 fn compute_min_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
8713 RenderProxyBoxMixin::compute_min_intrinsic_width(self, app, height)
8714 }
8715
8716 fn compute_max_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
8717 RenderProxyBoxMixin::compute_max_intrinsic_width(self, app, height)
8718 }
8719
8720 fn compute_min_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
8721 RenderProxyBoxMixin::compute_min_intrinsic_height(self, app, width)
8722 }
8723
8724 fn compute_max_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
8725 RenderProxyBoxMixin::compute_max_intrinsic_height(self, app, width)
8726 }
8727
8728 fn compute_distance_to_actual_baseline(
8729 self: RenderHandle<Self>,
8730 app: &mut App,
8731 baseline: TextBaseline,
8732 ) -> Option<f64> {
8733 RenderProxyBoxMixin::compute_distance_to_actual_baseline(self, app, baseline)
8734 }
8735
8736 fn compute_dry_baseline(
8737 self: RenderHandle<Self>,
8738 app: &mut App,
8739 constraints: BoxConstraints,
8740 baseline: TextBaseline,
8741 ) -> Option<f64> {
8742 RenderProxyBoxMixin::compute_dry_baseline(self, app, constraints, baseline)
8743 }
8744
8745 fn compute_dry_layout(
8746 self: RenderHandle<Self>,
8747 app: &mut App,
8748 constraints: BoxConstraints,
8749 ) -> Size {
8750 RenderProxyBoxMixin::compute_dry_layout(self, app, constraints)
8751 }
8752}
8753
8754pub struct RenderBlockSemantics {
8760 render_object: RenderObjectData,
8761 render_box: RenderBoxData,
8762 child: RenderObjectWithChildData<AnyRenderBox>,
8763 blocking: bool,
8764}
8765
8766impl RenderBlockSemantics {
8767 pub fn new(
8770 app: &mut App,
8771 blocking: bool,
8772 child: Option<AnyRenderBox>,
8773 ) -> RenderHandle<RenderBlockSemantics> {
8774 let this = RenderHandle::new_box(
8775 app,
8776 RenderBlockSemantics {
8777 render_object: RenderObjectData::new(),
8778 render_box: RenderBoxData::new(),
8779 child: RenderObjectWithChildData::new(),
8780 blocking,
8781 },
8782 );
8783 this.set_child(app, child);
8784 this
8785 }
8786
8787 pub fn blocking(self: RenderHandle<Self>, app: &App) -> bool {
8790 self.get(app).blocking
8791 }
8792
8793 pub fn set_blocking(self: RenderHandle<Self>, app: &mut App, value: bool) {
8795 if value == self.get(app).blocking {
8796 return;
8797 }
8798 self.get_mut(app).blocking = value;
8799 }
8800}
8801
8802impl RenderObjectWithChildMixin for RenderBlockSemantics {
8803 type ChildType = AnyRenderBox;
8804
8805 fn child_data(self: RenderHandle<Self>, app: &App) -> &RenderObjectWithChildData<AnyRenderBox> {
8806 &self.get(app).child
8807 }
8808
8809 fn child_data_mut(
8810 self: RenderHandle<Self>,
8811 app: &mut App,
8812 ) -> &mut RenderObjectWithChildData<AnyRenderBox> {
8813 &mut self.get_mut(app).child
8814 }
8815}
8816
8817impl RenderProxyBoxMixin for RenderBlockSemantics {}
8818
8819impl RenderObject for RenderBlockSemantics {
8820 crate::render_object_accessors!();
8821
8822 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
8823 RenderProxyBoxMixin::perform_layout(self, app);
8824 }
8825
8826 fn paint(
8827 self: RenderHandle<Self>,
8828 app: &mut App,
8829 context: &mut PaintingContext,
8830 offset: Offset,
8831 ) {
8832 RenderProxyBoxMixin::paint(self, app, context, offset);
8833 }
8834
8835 fn visit_children(
8836 self: RenderHandle<Self>,
8837 app: &App,
8838 visitor: &mut dyn FnMut(AnyRenderObject),
8839 ) {
8840 if let Some(child) = self.child(app) {
8841 visitor(child.as_object());
8842 }
8843 }
8844}
8845
8846impl RenderBox for RenderBlockSemantics {
8847 crate::render_box_accessors!();
8848
8849 fn setup_parent_data(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject) {
8850 RenderProxyBoxMixin::setup_parent_data(self, app, child);
8851 }
8852
8853 fn apply_paint_transform(
8854 self: RenderHandle<Self>,
8855 app: &App,
8856 child: AnyRenderObject,
8857 transform: &mut Matrix4,
8858 ) {
8859 RenderProxyBoxMixin::apply_paint_transform(self, app, child, transform);
8860 }
8861
8862 fn hit_test_children(
8863 self: RenderHandle<Self>,
8864 app: &mut App,
8865 result: &mut BoxHitTestResult<'_>,
8866 position: Offset,
8867 ) -> bool {
8868 RenderProxyBoxMixin::hit_test_children(self, app, result, position)
8869 }
8870
8871 fn compute_min_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
8872 RenderProxyBoxMixin::compute_min_intrinsic_width(self, app, height)
8873 }
8874
8875 fn compute_max_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
8876 RenderProxyBoxMixin::compute_max_intrinsic_width(self, app, height)
8877 }
8878
8879 fn compute_min_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
8880 RenderProxyBoxMixin::compute_min_intrinsic_height(self, app, width)
8881 }
8882
8883 fn compute_max_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
8884 RenderProxyBoxMixin::compute_max_intrinsic_height(self, app, width)
8885 }
8886
8887 fn compute_distance_to_actual_baseline(
8888 self: RenderHandle<Self>,
8889 app: &mut App,
8890 baseline: TextBaseline,
8891 ) -> Option<f64> {
8892 RenderProxyBoxMixin::compute_distance_to_actual_baseline(self, app, baseline)
8893 }
8894
8895 fn compute_dry_baseline(
8896 self: RenderHandle<Self>,
8897 app: &mut App,
8898 constraints: BoxConstraints,
8899 baseline: TextBaseline,
8900 ) -> Option<f64> {
8901 RenderProxyBoxMixin::compute_dry_baseline(self, app, constraints, baseline)
8902 }
8903
8904 fn compute_dry_layout(
8905 self: RenderHandle<Self>,
8906 app: &mut App,
8907 constraints: BoxConstraints,
8908 ) -> Size {
8909 RenderProxyBoxMixin::compute_dry_layout(self, app, constraints)
8910 }
8911}
8912
8913pub struct RenderMergeSemantics {
8921 render_object: RenderObjectData,
8922 render_box: RenderBoxData,
8923 child: RenderObjectWithChildData<AnyRenderBox>,
8924}
8925
8926impl RenderMergeSemantics {
8927 pub fn new(app: &mut App, child: Option<AnyRenderBox>) -> RenderHandle<RenderMergeSemantics> {
8929 let this = RenderHandle::new_box(
8930 app,
8931 RenderMergeSemantics {
8932 render_object: RenderObjectData::new(),
8933 render_box: RenderBoxData::new(),
8934 child: RenderObjectWithChildData::new(),
8935 },
8936 );
8937 this.set_child(app, child);
8938 this
8939 }
8940}
8941
8942impl RenderObjectWithChildMixin for RenderMergeSemantics {
8943 type ChildType = AnyRenderBox;
8944
8945 fn child_data(self: RenderHandle<Self>, app: &App) -> &RenderObjectWithChildData<AnyRenderBox> {
8946 &self.get(app).child
8947 }
8948
8949 fn child_data_mut(
8950 self: RenderHandle<Self>,
8951 app: &mut App,
8952 ) -> &mut RenderObjectWithChildData<AnyRenderBox> {
8953 &mut self.get_mut(app).child
8954 }
8955}
8956
8957impl RenderProxyBoxMixin for RenderMergeSemantics {}
8958
8959impl RenderObject for RenderMergeSemantics {
8960 crate::render_object_accessors!();
8961
8962 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
8963 RenderProxyBoxMixin::perform_layout(self, app);
8964 }
8965
8966 fn paint(
8967 self: RenderHandle<Self>,
8968 app: &mut App,
8969 context: &mut PaintingContext,
8970 offset: Offset,
8971 ) {
8972 RenderProxyBoxMixin::paint(self, app, context, offset);
8973 }
8974
8975 fn visit_children(
8976 self: RenderHandle<Self>,
8977 app: &App,
8978 visitor: &mut dyn FnMut(AnyRenderObject),
8979 ) {
8980 if let Some(child) = self.child(app) {
8981 visitor(child.as_object());
8982 }
8983 }
8984}
8985
8986impl RenderBox for RenderMergeSemantics {
8987 crate::render_box_accessors!();
8988
8989 fn setup_parent_data(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject) {
8990 RenderProxyBoxMixin::setup_parent_data(self, app, child);
8991 }
8992
8993 fn apply_paint_transform(
8994 self: RenderHandle<Self>,
8995 app: &App,
8996 child: AnyRenderObject,
8997 transform: &mut Matrix4,
8998 ) {
8999 RenderProxyBoxMixin::apply_paint_transform(self, app, child, transform);
9000 }
9001
9002 fn hit_test_children(
9003 self: RenderHandle<Self>,
9004 app: &mut App,
9005 result: &mut BoxHitTestResult<'_>,
9006 position: Offset,
9007 ) -> bool {
9008 RenderProxyBoxMixin::hit_test_children(self, app, result, position)
9009 }
9010
9011 fn compute_min_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
9012 RenderProxyBoxMixin::compute_min_intrinsic_width(self, app, height)
9013 }
9014
9015 fn compute_max_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
9016 RenderProxyBoxMixin::compute_max_intrinsic_width(self, app, height)
9017 }
9018
9019 fn compute_min_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
9020 RenderProxyBoxMixin::compute_min_intrinsic_height(self, app, width)
9021 }
9022
9023 fn compute_max_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
9024 RenderProxyBoxMixin::compute_max_intrinsic_height(self, app, width)
9025 }
9026
9027 fn compute_distance_to_actual_baseline(
9028 self: RenderHandle<Self>,
9029 app: &mut App,
9030 baseline: TextBaseline,
9031 ) -> Option<f64> {
9032 RenderProxyBoxMixin::compute_distance_to_actual_baseline(self, app, baseline)
9033 }
9034
9035 fn compute_dry_baseline(
9036 self: RenderHandle<Self>,
9037 app: &mut App,
9038 constraints: BoxConstraints,
9039 baseline: TextBaseline,
9040 ) -> Option<f64> {
9041 RenderProxyBoxMixin::compute_dry_baseline(self, app, constraints, baseline)
9042 }
9043
9044 fn compute_dry_layout(
9045 self: RenderHandle<Self>,
9046 app: &mut App,
9047 constraints: BoxConstraints,
9048 ) -> Size {
9049 RenderProxyBoxMixin::compute_dry_layout(self, app, constraints)
9050 }
9051}
9052
9053pub struct RenderExcludeSemantics {
9061 render_object: RenderObjectData,
9062 render_box: RenderBoxData,
9063 child: RenderObjectWithChildData<AnyRenderBox>,
9064 excluding: bool,
9065}
9066
9067impl RenderExcludeSemantics {
9068 pub fn new(
9071 app: &mut App,
9072 excluding: bool,
9073 child: Option<AnyRenderBox>,
9074 ) -> RenderHandle<RenderExcludeSemantics> {
9075 let this = RenderHandle::new_box(
9076 app,
9077 RenderExcludeSemantics {
9078 render_object: RenderObjectData::new(),
9079 render_box: RenderBoxData::new(),
9080 child: RenderObjectWithChildData::new(),
9081 excluding,
9082 },
9083 );
9084 this.set_child(app, child);
9085 this
9086 }
9087
9088 pub fn excluding(self: RenderHandle<Self>, app: &App) -> bool {
9090 self.get(app).excluding
9091 }
9092
9093 pub fn set_excluding(self: RenderHandle<Self>, app: &mut App, value: bool) {
9095 if value == self.get(app).excluding {
9096 return;
9097 }
9098 self.get_mut(app).excluding = value;
9099 }
9100}
9101
9102impl RenderObjectWithChildMixin for RenderExcludeSemantics {
9103 type ChildType = AnyRenderBox;
9104
9105 fn child_data(self: RenderHandle<Self>, app: &App) -> &RenderObjectWithChildData<AnyRenderBox> {
9106 &self.get(app).child
9107 }
9108
9109 fn child_data_mut(
9110 self: RenderHandle<Self>,
9111 app: &mut App,
9112 ) -> &mut RenderObjectWithChildData<AnyRenderBox> {
9113 &mut self.get_mut(app).child
9114 }
9115}
9116
9117impl RenderProxyBoxMixin for RenderExcludeSemantics {}
9118
9119impl RenderObject for RenderExcludeSemantics {
9120 crate::render_object_accessors!();
9121
9122 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
9123 RenderProxyBoxMixin::perform_layout(self, app);
9124 }
9125
9126 fn paint(
9127 self: RenderHandle<Self>,
9128 app: &mut App,
9129 context: &mut PaintingContext,
9130 offset: Offset,
9131 ) {
9132 RenderProxyBoxMixin::paint(self, app, context, offset);
9133 }
9134
9135 fn visit_children(
9136 self: RenderHandle<Self>,
9137 app: &App,
9138 visitor: &mut dyn FnMut(AnyRenderObject),
9139 ) {
9140 if let Some(child) = self.child(app) {
9141 visitor(child.as_object());
9142 }
9143 }
9144}
9145
9146impl RenderBox for RenderExcludeSemantics {
9147 crate::render_box_accessors!();
9148
9149 fn setup_parent_data(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject) {
9150 RenderProxyBoxMixin::setup_parent_data(self, app, child);
9151 }
9152
9153 fn apply_paint_transform(
9154 self: RenderHandle<Self>,
9155 app: &App,
9156 child: AnyRenderObject,
9157 transform: &mut Matrix4,
9158 ) {
9159 RenderProxyBoxMixin::apply_paint_transform(self, app, child, transform);
9160 }
9161
9162 fn hit_test_children(
9163 self: RenderHandle<Self>,
9164 app: &mut App,
9165 result: &mut BoxHitTestResult<'_>,
9166 position: Offset,
9167 ) -> bool {
9168 RenderProxyBoxMixin::hit_test_children(self, app, result, position)
9169 }
9170
9171 fn compute_min_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
9172 RenderProxyBoxMixin::compute_min_intrinsic_width(self, app, height)
9173 }
9174
9175 fn compute_max_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
9176 RenderProxyBoxMixin::compute_max_intrinsic_width(self, app, height)
9177 }
9178
9179 fn compute_min_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
9180 RenderProxyBoxMixin::compute_min_intrinsic_height(self, app, width)
9181 }
9182
9183 fn compute_max_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
9184 RenderProxyBoxMixin::compute_max_intrinsic_height(self, app, width)
9185 }
9186
9187 fn compute_distance_to_actual_baseline(
9188 self: RenderHandle<Self>,
9189 app: &mut App,
9190 baseline: TextBaseline,
9191 ) -> Option<f64> {
9192 RenderProxyBoxMixin::compute_distance_to_actual_baseline(self, app, baseline)
9193 }
9194
9195 fn compute_dry_baseline(
9196 self: RenderHandle<Self>,
9197 app: &mut App,
9198 constraints: BoxConstraints,
9199 baseline: TextBaseline,
9200 ) -> Option<f64> {
9201 RenderProxyBoxMixin::compute_dry_baseline(self, app, constraints, baseline)
9202 }
9203
9204 fn compute_dry_layout(
9205 self: RenderHandle<Self>,
9206 app: &mut App,
9207 constraints: BoxConstraints,
9208 ) -> Size {
9209 RenderProxyBoxMixin::compute_dry_layout(self, app, constraints)
9210 }
9211}
9212
9213pub struct RenderIndexedSemantics {
9220 render_object: RenderObjectData,
9221 render_box: RenderBoxData,
9222 child: RenderObjectWithChildData<AnyRenderBox>,
9223 index: i32,
9224}
9225
9226impl RenderIndexedSemantics {
9227 pub fn new(
9229 app: &mut App,
9230 index: i32,
9231 child: Option<AnyRenderBox>,
9232 ) -> RenderHandle<RenderIndexedSemantics> {
9233 let this = RenderHandle::new_box(
9234 app,
9235 RenderIndexedSemantics {
9236 render_object: RenderObjectData::new(),
9237 render_box: RenderBoxData::new(),
9238 child: RenderObjectWithChildData::new(),
9239 index,
9240 },
9241 );
9242 this.set_child(app, child);
9243 this
9244 }
9245
9246 pub fn index(self: RenderHandle<Self>, app: &App) -> i32 {
9248 self.get(app).index
9249 }
9250
9251 pub fn set_index(self: RenderHandle<Self>, app: &mut App, value: i32) {
9253 if value == self.index(app) {
9254 return;
9255 }
9256 self.get_mut(app).index = value;
9257 }
9258}
9259
9260impl RenderObjectWithChildMixin for RenderIndexedSemantics {
9261 type ChildType = AnyRenderBox;
9262
9263 fn child_data(self: RenderHandle<Self>, app: &App) -> &RenderObjectWithChildData<AnyRenderBox> {
9264 &self.get(app).child
9265 }
9266
9267 fn child_data_mut(
9268 self: RenderHandle<Self>,
9269 app: &mut App,
9270 ) -> &mut RenderObjectWithChildData<AnyRenderBox> {
9271 &mut self.get_mut(app).child
9272 }
9273}
9274
9275impl RenderProxyBoxMixin for RenderIndexedSemantics {}
9276
9277impl RenderObject for RenderIndexedSemantics {
9278 crate::render_object_accessors!();
9279
9280 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
9281 RenderProxyBoxMixin::perform_layout(self, app);
9282 }
9283
9284 fn paint(
9285 self: RenderHandle<Self>,
9286 app: &mut App,
9287 context: &mut PaintingContext,
9288 offset: Offset,
9289 ) {
9290 RenderProxyBoxMixin::paint(self, app, context, offset);
9291 }
9292
9293 fn visit_children(
9294 self: RenderHandle<Self>,
9295 app: &App,
9296 visitor: &mut dyn FnMut(AnyRenderObject),
9297 ) {
9298 if let Some(child) = self.child(app) {
9299 visitor(child.as_object());
9300 }
9301 }
9302}
9303
9304impl RenderBox for RenderIndexedSemantics {
9305 crate::render_box_accessors!();
9306
9307 fn setup_parent_data(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject) {
9308 RenderProxyBoxMixin::setup_parent_data(self, app, child);
9309 }
9310
9311 fn apply_paint_transform(
9312 self: RenderHandle<Self>,
9313 app: &App,
9314 child: AnyRenderObject,
9315 transform: &mut Matrix4,
9316 ) {
9317 RenderProxyBoxMixin::apply_paint_transform(self, app, child, transform);
9318 }
9319
9320 fn hit_test_children(
9321 self: RenderHandle<Self>,
9322 app: &mut App,
9323 result: &mut BoxHitTestResult<'_>,
9324 position: Offset,
9325 ) -> bool {
9326 RenderProxyBoxMixin::hit_test_children(self, app, result, position)
9327 }
9328
9329 fn compute_min_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
9330 RenderProxyBoxMixin::compute_min_intrinsic_width(self, app, height)
9331 }
9332
9333 fn compute_max_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
9334 RenderProxyBoxMixin::compute_max_intrinsic_width(self, app, height)
9335 }
9336
9337 fn compute_min_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
9338 RenderProxyBoxMixin::compute_min_intrinsic_height(self, app, width)
9339 }
9340
9341 fn compute_max_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
9342 RenderProxyBoxMixin::compute_max_intrinsic_height(self, app, width)
9343 }
9344
9345 fn compute_distance_to_actual_baseline(
9346 self: RenderHandle<Self>,
9347 app: &mut App,
9348 baseline: TextBaseline,
9349 ) -> Option<f64> {
9350 RenderProxyBoxMixin::compute_distance_to_actual_baseline(self, app, baseline)
9351 }
9352
9353 fn compute_dry_baseline(
9354 self: RenderHandle<Self>,
9355 app: &mut App,
9356 constraints: BoxConstraints,
9357 baseline: TextBaseline,
9358 ) -> Option<f64> {
9359 RenderProxyBoxMixin::compute_dry_baseline(self, app, constraints, baseline)
9360 }
9361
9362 fn compute_dry_layout(
9363 self: RenderHandle<Self>,
9364 app: &mut App,
9365 constraints: BoxConstraints,
9366 ) -> Size {
9367 RenderProxyBoxMixin::compute_dry_layout(self, app, constraints)
9368 }
9369}
9370
9371pub struct RenderBackdropFilter {
9376 render_object: RenderObjectData,
9377 render_box: RenderBoxData,
9378 child: RenderObjectWithChildData<AnyRenderBox>,
9379 filter_config: ImageFilterConfig,
9380 blend_mode: BlendMode,
9381 enabled: bool,
9382 backdrop_key: Option<BackdropKey>,
9383}
9384
9385impl RenderBackdropFilter {
9386 pub fn new(
9390 app: &mut App,
9391 filter_config: ImageFilterConfig,
9392 blend_mode: BlendMode,
9393 enabled: bool,
9394 backdrop_key: Option<BackdropKey>,
9395 child: Option<AnyRenderBox>,
9396 ) -> RenderHandle<Self> {
9397 let this = RenderHandle::new_box(
9398 app,
9399 RenderBackdropFilter {
9400 render_object: RenderObjectData::new(),
9401 render_box: RenderBoxData::new(),
9402 child: RenderObjectWithChildData::new(),
9403 filter_config,
9404 blend_mode,
9405 enabled,
9406 backdrop_key,
9407 },
9408 );
9409 this.set_child(app, child);
9410 this
9411 }
9412
9413 pub fn enabled(self: RenderHandle<Self>, app: &App) -> bool {
9415 self.get(app).enabled
9416 }
9417
9418 pub fn set_enabled(self: RenderHandle<Self>, app: &mut App, value: bool) {
9420 if self.get(app).enabled == value {
9421 return;
9422 }
9423 self.get_mut(app).enabled = value;
9424 self.mark_needs_paint(app);
9425 }
9426
9427 pub fn filter(self: RenderHandle<Self>, app: &App) -> ImageFilter {
9432 self.get(app)
9433 .filter_config
9434 .filter()
9435 .expect(
9436 "This getter should only be called when the filter is assigned via the \
9437 `filter` setter.",
9438 )
9439 .clone()
9440 }
9441
9442 pub fn set_filter(self: RenderHandle<Self>, app: &mut App, value: ImageFilter) {
9444 self.set_filter_config(app, ImageFilterConfig::new(value));
9445 }
9446
9447 pub fn filter_config(self: RenderHandle<Self>, app: &App) -> &ImageFilterConfig {
9449 &self.get(app).filter_config
9450 }
9451
9452 pub fn set_filter_config(self: RenderHandle<Self>, app: &mut App, value: ImageFilterConfig) {
9454 if self.get(app).filter_config == value {
9455 return;
9456 }
9457 self.get_mut(app).filter_config = value;
9458 self.mark_needs_paint(app);
9459 }
9460
9461 pub fn blend_mode(self: RenderHandle<Self>, app: &App) -> BlendMode {
9464 self.get(app).blend_mode
9465 }
9466
9467 pub fn set_blend_mode(self: RenderHandle<Self>, app: &mut App, value: BlendMode) {
9469 if self.get(app).blend_mode == value {
9470 return;
9471 }
9472 self.get_mut(app).blend_mode = value;
9473 self.mark_needs_paint(app);
9474 }
9475
9476 pub fn backdrop_key(self: RenderHandle<Self>, app: &App) -> Option<BackdropKey> {
9478 self.get(app).backdrop_key
9479 }
9480
9481 pub fn set_backdrop_key(self: RenderHandle<Self>, app: &mut App, value: Option<BackdropKey>) {
9483 if self.get(app).backdrop_key == value {
9484 return;
9485 }
9486 self.get_mut(app).backdrop_key = value;
9487 self.mark_needs_paint(app);
9488 }
9489}
9490
9491impl RenderObjectWithChildMixin for RenderBackdropFilter {
9492 type ChildType = AnyRenderBox;
9493
9494 fn child_data(self: RenderHandle<Self>, app: &App) -> &RenderObjectWithChildData<AnyRenderBox> {
9495 &self.get(app).child
9496 }
9497
9498 fn child_data_mut(
9499 self: RenderHandle<Self>,
9500 app: &mut App,
9501 ) -> &mut RenderObjectWithChildData<AnyRenderBox> {
9502 &mut self.get_mut(app).child
9503 }
9504}
9505
9506impl RenderProxyBoxMixin for RenderBackdropFilter {}
9507
9508impl RenderObject for RenderBackdropFilter {
9509 crate::render_object_accessors!();
9510
9511 fn debug_fill_properties(
9512 self: RenderHandle<Self>,
9513 app: &App,
9514 properties: &mut DiagnosticPropertiesBuilder,
9515 ) {
9516 let this = self.get(app);
9517 properties.add(
9518 DiagnosticsProperty::<ImageFilterConfig>::new(
9519 "filterConfig",
9520 Some(this.filter_config.clone()),
9521 )
9522 .default_value(None),
9523 );
9524 properties.add(EnumProperty::<BlendMode>::new(
9525 "blendMode",
9526 Some(this.blend_mode),
9527 ));
9528 properties.add(FlagProperty::new("enabled", Some(this.enabled)).if_true("enabled"));
9529 }
9530
9531 fn always_needs_compositing(self: RenderHandle<Self>, app: &App) -> bool {
9532 self.child(app).is_some()
9533 }
9534
9535 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
9536 RenderProxyBoxMixin::perform_layout(self, app);
9537 }
9538
9539 fn paint(
9540 self: RenderHandle<Self>,
9541 app: &mut App,
9542 context: &mut PaintingContext,
9543 offset: Offset,
9544 ) {
9545 if !self.get(app).enabled {
9546 RenderProxyBoxMixin::paint(self, app, context, offset);
9547 return;
9548 }
9549 let bounds = offset & self.size(app);
9550 let effective_filter = self
9551 .get(app)
9552 .filter_config
9553 .resolve(ImageFilterContext { bounds });
9554 if self.child(app).is_some() {
9555 debug_assert!(self.as_object().needs_compositing(app));
9556 let (blend_mode, backdrop_key) = {
9557 let this = self.get(app);
9558 (this.blend_mode, this.backdrop_key)
9559 };
9560 let layer = match self.as_object().layer_as::<BackdropFilterLayer>(app) {
9561 Some(layer) => layer,
9562 None => {
9563 let layer = BackdropFilterLayer::new(app);
9564 self.as_object()
9565 .set_layer(app, Some(layer.as_container_layer()));
9566 layer
9567 }
9568 };
9569 layer.set_filter(app, Some(effective_filter));
9570 layer.set_blend_mode(app, blend_mode);
9571 layer.set_backdrop_key(app, backdrop_key);
9572 context.push_layer(
9573 app,
9574 layer.as_container_layer(),
9575 |app, context, offset| RenderProxyBoxMixin::paint(self, app, context, offset),
9576 offset,
9577 None,
9578 );
9579 } else {
9580 self.as_object().set_layer(app, None);
9581 }
9582 }
9583
9584 fn visit_children(
9585 self: RenderHandle<Self>,
9586 app: &App,
9587 visitor: &mut dyn FnMut(AnyRenderObject),
9588 ) {
9589 if let Some(child) = self.child(app) {
9590 visitor(child.as_object());
9591 }
9592 }
9593}
9594
9595impl RenderBox for RenderBackdropFilter {
9596 crate::render_box_accessors!();
9597
9598 fn setup_parent_data(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject) {
9599 RenderProxyBoxMixin::setup_parent_data(self, app, child);
9600 }
9601
9602 fn apply_paint_transform(
9603 self: RenderHandle<Self>,
9604 app: &App,
9605 child: AnyRenderObject,
9606 transform: &mut Matrix4,
9607 ) {
9608 RenderProxyBoxMixin::apply_paint_transform(self, app, child, transform);
9609 }
9610
9611 fn hit_test_children(
9612 self: RenderHandle<Self>,
9613 app: &mut App,
9614 result: &mut BoxHitTestResult<'_>,
9615 position: Offset,
9616 ) -> bool {
9617 RenderProxyBoxMixin::hit_test_children(self, app, result, position)
9618 }
9619
9620 fn compute_min_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
9621 RenderProxyBoxMixin::compute_min_intrinsic_width(self, app, height)
9622 }
9623
9624 fn compute_max_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
9625 RenderProxyBoxMixin::compute_max_intrinsic_width(self, app, height)
9626 }
9627
9628 fn compute_min_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
9629 RenderProxyBoxMixin::compute_min_intrinsic_height(self, app, width)
9630 }
9631
9632 fn compute_max_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
9633 RenderProxyBoxMixin::compute_max_intrinsic_height(self, app, width)
9634 }
9635
9636 fn compute_distance_to_actual_baseline(
9637 self: RenderHandle<Self>,
9638 app: &mut App,
9639 baseline: TextBaseline,
9640 ) -> Option<f64> {
9641 RenderProxyBoxMixin::compute_distance_to_actual_baseline(self, app, baseline)
9642 }
9643
9644 fn compute_dry_baseline(
9645 self: RenderHandle<Self>,
9646 app: &mut App,
9647 constraints: BoxConstraints,
9648 baseline: TextBaseline,
9649 ) -> Option<f64> {
9650 RenderProxyBoxMixin::compute_dry_baseline(self, app, constraints, baseline)
9651 }
9652
9653 fn compute_dry_layout(
9654 self: RenderHandle<Self>,
9655 app: &mut App,
9656 constraints: BoxConstraints,
9657 ) -> Size {
9658 RenderProxyBoxMixin::compute_dry_layout(self, app, constraints)
9659 }
9660}
9661
9662pub struct RenderAnnotatedRegion<T> {
9667 render_object: RenderObjectData,
9668 render_box: RenderBoxData,
9669 child: RenderObjectWithChildData<AnyRenderBox>,
9670 value: Rc<T>,
9671 sized: bool,
9672 layer_handle: LayerHandle<Handle<AnnotatedRegionLayer>>,
9673}
9674
9675impl<T: PartialEq + 'static> RenderAnnotatedRegion<T> {
9676 pub fn new(
9681 app: &mut App,
9682 value: Rc<T>,
9683 sized: bool,
9684 child: Option<AnyRenderBox>,
9685 ) -> RenderHandle<RenderAnnotatedRegion<T>> {
9686 let this = RenderHandle::new_box(
9687 app,
9688 RenderAnnotatedRegion {
9689 render_object: RenderObjectData::new(),
9690 render_box: RenderBoxData::new(),
9691 child: RenderObjectWithChildData::new(),
9692 value,
9693 sized,
9694 layer_handle: LayerHandle::new(),
9695 },
9696 );
9697 this.set_child(app, child);
9698 this
9699 }
9700
9701 pub fn value(self: RenderHandle<Self>, app: &App) -> Rc<T> {
9704 Rc::clone(&self.get(app).value)
9705 }
9706
9707 pub fn set_value(self: RenderHandle<Self>, app: &mut App, new_value: Rc<T>) {
9709 if *self.get(app).value == *new_value {
9710 return;
9711 }
9712 self.get_mut(app).value = new_value;
9713 self.mark_needs_paint(app);
9714 }
9715
9716 pub fn sized(self: RenderHandle<Self>, app: &App) -> bool {
9718 self.get(app).sized
9719 }
9720
9721 pub fn set_sized(self: RenderHandle<Self>, app: &mut App, value: bool) {
9723 if self.get(app).sized == value {
9724 return;
9725 }
9726 self.get_mut(app).sized = value;
9727 self.mark_needs_paint(app);
9728 }
9729}
9730
9731impl<T: PartialEq + 'static> RenderObjectWithChildMixin for RenderAnnotatedRegion<T> {
9732 type ChildType = AnyRenderBox;
9733
9734 fn child_data(self: RenderHandle<Self>, app: &App) -> &RenderObjectWithChildData<AnyRenderBox> {
9735 &self.get(app).child
9736 }
9737
9738 fn child_data_mut(
9739 self: RenderHandle<Self>,
9740 app: &mut App,
9741 ) -> &mut RenderObjectWithChildData<AnyRenderBox> {
9742 &mut self.get_mut(app).child
9743 }
9744}
9745
9746impl<T: PartialEq + 'static> RenderProxyBoxMixin for RenderAnnotatedRegion<T> {}
9747
9748impl<T: PartialEq + 'static> RenderObject for RenderAnnotatedRegion<T> {
9749 crate::render_object_accessors!();
9750
9751 fn always_needs_compositing(self: RenderHandle<Self>, _app: &App) -> bool {
9752 true
9753 }
9754
9755 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
9756 RenderProxyBoxMixin::perform_layout(self, app);
9757 }
9758
9759 fn paint(
9760 self: RenderHandle<Self>,
9761 app: &mut App,
9762 context: &mut PaintingContext,
9763 offset: Offset,
9764 ) {
9765 let sized = self.sized(app);
9766 let value: Rc<dyn Any> = self.value(app);
9767 let layer = AnnotatedRegionLayer::new(app, value);
9768 if sized {
9769 layer.set_size(app, Some(self.size(app)));
9770 layer.set_offset(app, offset);
9771 }
9772 LayerHandle::set_layer(app, |app| &mut self.get_mut(app).layer_handle, Some(layer));
9773 context.push_layer(
9774 app,
9775 layer.as_container_layer(),
9776 |app, context, offset| RenderProxyBoxMixin::paint(self, app, context, offset),
9777 offset,
9778 None,
9779 );
9780 }
9781
9782 fn dispose(self: RenderHandle<Self>, app: &mut App) {
9783 LayerHandle::set_layer(app, |app| &mut self.get_mut(app).layer_handle, None);
9784 crate::object::RenderObjectBase::dispose(self, app);
9785 }
9786
9787 fn visit_children(
9788 self: RenderHandle<Self>,
9789 app: &App,
9790 visitor: &mut dyn FnMut(AnyRenderObject),
9791 ) {
9792 if let Some(child) = self.child(app) {
9793 visitor(child.as_object());
9794 }
9795 }
9796}
9797
9798impl<T: PartialEq + 'static> RenderBox for RenderAnnotatedRegion<T> {
9799 crate::render_box_accessors!();
9800
9801 fn setup_parent_data(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject) {
9802 RenderProxyBoxMixin::setup_parent_data(self, app, child);
9803 }
9804
9805 fn apply_paint_transform(
9806 self: RenderHandle<Self>,
9807 app: &App,
9808 child: AnyRenderObject,
9809 transform: &mut Matrix4,
9810 ) {
9811 RenderProxyBoxMixin::apply_paint_transform(self, app, child, transform);
9812 }
9813
9814 fn hit_test_children(
9815 self: RenderHandle<Self>,
9816 app: &mut App,
9817 result: &mut BoxHitTestResult<'_>,
9818 position: Offset,
9819 ) -> bool {
9820 RenderProxyBoxMixin::hit_test_children(self, app, result, position)
9821 }
9822
9823 fn compute_min_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
9824 RenderProxyBoxMixin::compute_min_intrinsic_width(self, app, height)
9825 }
9826
9827 fn compute_max_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
9828 RenderProxyBoxMixin::compute_max_intrinsic_width(self, app, height)
9829 }
9830
9831 fn compute_min_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
9832 RenderProxyBoxMixin::compute_min_intrinsic_height(self, app, width)
9833 }
9834
9835 fn compute_max_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
9836 RenderProxyBoxMixin::compute_max_intrinsic_height(self, app, width)
9837 }
9838
9839 fn compute_distance_to_actual_baseline(
9840 self: RenderHandle<Self>,
9841 app: &mut App,
9842 baseline: TextBaseline,
9843 ) -> Option<f64> {
9844 RenderProxyBoxMixin::compute_distance_to_actual_baseline(self, app, baseline)
9845 }
9846
9847 fn compute_dry_baseline(
9848 self: RenderHandle<Self>,
9849 app: &mut App,
9850 constraints: BoxConstraints,
9851 baseline: TextBaseline,
9852 ) -> Option<f64> {
9853 RenderProxyBoxMixin::compute_dry_baseline(self, app, constraints, baseline)
9854 }
9855
9856 fn compute_dry_layout(
9857 self: RenderHandle<Self>,
9858 app: &mut App,
9859 constraints: BoxConstraints,
9860 ) -> Size {
9861 RenderProxyBoxMixin::compute_dry_layout(self, app, constraints)
9862 }
9863}
9864
9865#[cfg(test)]
9866mod tests {
9867 use waft_animation::{k_always_complete_animation, k_always_dismissed_animation};
9868 use waft_embedder::ColorFilter;
9869 use waft_embedder::valo::{self, Op, Point};
9870 use waft_foundation::AppCell;
9871 use waft_foundation::{Ref, ValueNotifier};
9872 use waft_gestures::HitTestResult;
9873 use waft_painting::BoxDecoration;
9874
9875 use super::*;
9876 use crate::layer::ErasedLayer;
9877 use crate::pipeline_owner::PipelineOwner;
9878 use crate::testing::{
9879 CanvasMethod, EnginePhase, count_calls, ignoring_hash_codes, layout_with, painted_ops,
9880 pump_frame, test_render_root,
9881 };
9882 use crate::view::ViewConfiguration;
9883 use waft_embedder::SceneBuilder;
9884
9885 #[test]
9890 fn a_limited_box_dump_shows_each_objects_layout() {
9891 let cell = AppCell::new();
9892 let mut app = cell.borrow_mut();
9893 let child = RenderConstrainedBox::new(
9894 &mut app,
9895 BoxConstraints::tight_for(Some(300.0), Some(400.0)),
9896 None,
9897 );
9898 let limited = RenderLimitedBox::new(&mut app, 100.0, 200.0, Some(child.as_box()));
9899 let parent = crate::RenderConstrainedOverflowBox::new(
9900 &mut app,
9901 Some(0.0),
9902 Some(f64::INFINITY),
9903 Some(0.0),
9904 Some(f64::INFINITY),
9905 crate::OverflowBoxFit::Max,
9906 AlignmentGeometry::CENTER,
9907 None,
9908 Some(limited.as_box()),
9909 );
9910 crate::testing::layout(&mut app, parent.as_box());
9911 assert_eq!(child.as_box().size(&app), Size::new(100.0, 200.0));
9912 assert_eq!(
9913 ignoring_hash_codes(
9914 &parent
9915 .as_box()
9916 .as_object()
9917 .to_string_deep_with(&app, waft_foundation::DiagnosticLevel::Info)
9918 ),
9919 "RenderConstrainedOverflowBox#00000 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE\n\
9920 \u{20}│ parentData: <none> (can use size)\n\
9921 \u{20}│ constraints: BoxConstraints(w=800.0, h=600.0)\n\
9922 \u{20}│ size: Size(800.0, 600.0)\n\
9923 \u{20}│ alignment: Alignment.center\n\
9924 \u{20}│ minWidth: 0.0\n\
9925 \u{20}│ maxWidth: Infinity\n\
9926 \u{20}│ minHeight: 0.0\n\
9927 \u{20}│ maxHeight: Infinity\n\
9928 \u{20}│ fit: max\n\
9929 \u{20}│\n\
9930 \u{20}└─child: RenderLimitedBox#00000 relayoutBoundary=up1 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE\n\
9931 \u{20} │ parentData: offset=Offset(350.0, 200.0) (can use size)\n\
9932 \u{20} │ constraints: BoxConstraints(unconstrained)\n\
9933 \u{20} │ size: Size(100.0, 200.0)\n\
9934 \u{20} │ maxWidth: 100.0\n\
9935 \u{20} │ maxHeight: 200.0\n\
9936 \u{20} │\n\
9937 \u{20} └─child: RenderConstrainedBox#00000 relayoutBoundary=up2 NEEDS-PAINT\n\
9938 \u{20} parentData: <none> (can use size)\n\
9939 \u{20} constraints: BoxConstraints(0.0<=w<=100.0, 0.0<=h<=200.0)\n\
9940 \u{20} size: Size(100.0, 200.0)\n\
9941 \u{20} additionalConstraints: BoxConstraints(w=300.0, h=400.0)\n"
9942 );
9943 }
9944
9945 fn sized_box(app: &mut App, size: Size) -> RenderHandle<RenderConstrainedBox> {
9946 RenderConstrainedBox::new(app, BoxConstraints::tight(size), None)
9947 }
9948
9949 struct IntrinsicTestBox {
9952 render_object: RenderObjectData,
9953 render_box: RenderBoxData,
9954 intrinsic: Size,
9955 }
9956
9957 impl RenderObject for IntrinsicTestBox {
9958 crate::render_object_accessors!();
9959
9960 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
9961 let intrinsic = self.get(app).intrinsic;
9962 let size = self.constraints(app).constrain(intrinsic);
9963 self.set_size(app, size);
9964 }
9965 }
9966
9967 impl RenderBox for IntrinsicTestBox {
9968 crate::render_box_accessors!();
9969
9970 fn compute_min_intrinsic_width(
9971 self: RenderHandle<Self>,
9972 app: &mut App,
9973 _height: f64,
9974 ) -> f64 {
9975 self.get(app).intrinsic.width()
9976 }
9977
9978 fn compute_max_intrinsic_width(
9979 self: RenderHandle<Self>,
9980 app: &mut App,
9981 _height: f64,
9982 ) -> f64 {
9983 self.get(app).intrinsic.width()
9984 }
9985
9986 fn compute_min_intrinsic_height(
9987 self: RenderHandle<Self>,
9988 app: &mut App,
9989 _width: f64,
9990 ) -> f64 {
9991 self.get(app).intrinsic.height()
9992 }
9993
9994 fn compute_max_intrinsic_height(
9995 self: RenderHandle<Self>,
9996 app: &mut App,
9997 _width: f64,
9998 ) -> f64 {
9999 self.get(app).intrinsic.height()
10000 }
10001
10002 fn compute_dry_layout(
10003 self: RenderHandle<Self>,
10004 app: &mut App,
10005 constraints: BoxConstraints,
10006 ) -> Size {
10007 constraints.constrain(self.get(app).intrinsic)
10008 }
10009 }
10010
10011 fn intrinsic_box(app: &mut App, intrinsic: Size) -> RenderHandle<IntrinsicTestBox> {
10012 RenderHandle::new_box(
10013 app,
10014 IntrinsicTestBox {
10015 render_object: RenderObjectData::new(),
10016 render_box: RenderBoxData::new(),
10017 intrinsic,
10018 },
10019 )
10020 }
10021
10022 #[test]
10025 fn constrained_box_intrinsics_enforce_the_additional_constraints() {
10026 let cell = AppCell::new();
10027 let mut app = cell.borrow_mut();
10028 let child = intrinsic_box(&mut app, Size::new(20.0, 30.0));
10029 let loose = RenderConstrainedBox::new(
10030 &mut app,
10031 BoxConstraints::new().min_width(50.0).max_width(60.0),
10032 Some(child.as_box()),
10033 );
10034 assert_eq!(loose.as_box().get_min_intrinsic_width(&mut app, 0.0), 50.0);
10035 assert_eq!(loose.as_box().get_max_intrinsic_width(&mut app, 0.0), 50.0);
10036 assert_eq!(loose.as_box().get_min_intrinsic_height(&mut app, 0.0), 30.0);
10037
10038 let child = intrinsic_box(&mut app, Size::new(20.0, 30.0));
10039 let tight = RenderConstrainedBox::new(
10040 &mut app,
10041 BoxConstraints::tight(Size::new(80.0, 90.0)),
10042 Some(child.as_box()),
10043 );
10044 assert_eq!(tight.as_box().get_max_intrinsic_width(&mut app, 0.0), 80.0);
10045 assert_eq!(tight.as_box().get_max_intrinsic_height(&mut app, 0.0), 90.0);
10046 }
10047
10048 #[test]
10051 fn intrinsic_width_sizes_the_child_to_its_max_intrinsic_width() {
10052 let cell = AppCell::new();
10053 let mut app = cell.borrow_mut();
10054 let child = intrinsic_box(&mut app, Size::new(100.0, 40.0));
10055 let intrinsic = RenderIntrinsicWidth::new(&mut app, None, None, Some(child.as_box()));
10056 intrinsic.layout(&mut app, BoxConstraints::new().max_width(500.0), false);
10057 assert_eq!(intrinsic.size(&app), Size::new(100.0, 40.0));
10058 assert_eq!(child.size(&app), Size::new(100.0, 40.0));
10059
10060 intrinsic.set_step_width(&mut app, Some(30.0));
10061 intrinsic.layout(&mut app, BoxConstraints::new().max_width(500.0), false);
10062 assert_eq!(intrinsic.size(&app), Size::new(120.0, 40.0));
10063 }
10064
10065 #[test]
10067 fn intrinsic_width_dry_layout_matches_its_layout() {
10068 let cell = AppCell::new();
10069 let mut app = cell.borrow_mut();
10070 let child = intrinsic_box(&mut app, Size::new(100.0, 40.0));
10071 let intrinsic = RenderIntrinsicWidth::new(&mut app, None, None, Some(child.as_box()));
10072 let constraints = BoxConstraints::new().max_width(500.0);
10073 let dry = intrinsic.as_box().get_dry_layout(&mut app, constraints);
10074 intrinsic.layout(&mut app, constraints, false);
10075 assert_eq!(dry, intrinsic.size(&app));
10076 }
10077
10078 #[test]
10080 fn intrinsic_height_sizes_the_child_to_its_max_intrinsic_height() {
10081 let cell = AppCell::new();
10082 let mut app = cell.borrow_mut();
10083 let child = intrinsic_box(&mut app, Size::new(100.0, 40.0));
10084 let intrinsic = RenderIntrinsicHeight::new(&mut app, Some(child.as_box()));
10085 intrinsic.layout(&mut app, BoxConstraints::new().max_height(500.0), false);
10086 assert_eq!(intrinsic.size(&app), Size::new(100.0, 40.0));
10087 assert_eq!(
10088 intrinsic
10089 .as_box()
10090 .get_max_intrinsic_width(&mut app, f64::INFINITY),
10091 100.0
10092 );
10093 }
10094
10095 #[test]
10098 fn fitted_box_scales_its_child_into_itself() {
10099 let cell = AppCell::new();
10100 let mut app = cell.borrow_mut();
10101 let child = sized_box(&mut app, Size::new(100.0, 100.0));
10102 let fitted = RenderFittedBox::new(
10103 &mut app,
10104 BoxFit::Contain,
10105 AlignmentGeometry::CENTER,
10106 None,
10107 Some(child.as_box()),
10108 );
10109 fitted.layout(
10110 &mut app,
10111 BoxConstraints::tight(Size::new(50.0, 50.0)),
10112 false,
10113 );
10114 assert_eq!(fitted.size(&app), Size::new(50.0, 50.0));
10115 assert_eq!(child.size(&app), Size::new(100.0, 100.0));
10116
10117 let mut transform = Matrix4::IDENTITY;
10118 RenderBox::apply_paint_transform(fitted, &app, child.as_object(), &mut transform);
10119 assert_eq!(
10120 waft_painting::transform_point(&transform, Offset::new(100.0, 100.0)),
10121 Offset::new(50.0, 50.0)
10122 );
10123 }
10124
10125 #[test]
10128 fn aspect_ratio_sizes_itself_from_the_width() {
10129 let cell = AppCell::new();
10130 let mut app = cell.borrow_mut();
10131 let child = sized_box(&mut app, Size::new(10.0, 10.0));
10132 let aspect = RenderAspectRatio::new(&mut app, 2.0, Some(child.as_box()));
10133 aspect.layout(
10134 &mut app,
10135 BoxConstraints::new().max_width(200.0).max_height(200.0),
10136 false,
10137 );
10138 assert_eq!(aspect.size(&app), Size::new(200.0, 100.0));
10139 assert_eq!(child.size(&app), Size::new(200.0, 100.0));
10140 assert_eq!(
10141 aspect.as_box().get_min_intrinsic_width(&mut app, 50.0),
10142 100.0
10143 );
10144 assert_eq!(
10145 aspect.as_box().get_min_intrinsic_height(&mut app, 50.0),
10146 25.0
10147 );
10148 }
10149
10150 #[test]
10152 fn aspect_ratio_infers_the_width_from_an_unbounded_axis() {
10153 let cell = AppCell::new();
10154 let mut app = cell.borrow_mut();
10155 let aspect = RenderAspectRatio::new(&mut app, 0.5, None);
10156 aspect.layout(&mut app, BoxConstraints::new().max_height(100.0), false);
10157 assert_eq!(aspect.size(&app), Size::new(50.0, 100.0));
10158 }
10159
10160 #[test]
10161 fn constrained_box_without_child() {
10162 let cell = AppCell::new();
10163 let mut app = cell.borrow_mut();
10164 let box_ =
10165 RenderConstrainedBox::new(&mut app, BoxConstraints::tight(Size::new(80.0, 40.0)), None);
10166 box_.layout(&mut app, BoxConstraints::new(), false);
10167 assert_eq!(box_.size(&app), Size::new(80.0, 40.0));
10168 }
10169
10170 #[test]
10171 fn additional_constraints_change_marks_layout() {
10172 let cell = AppCell::new();
10173 let mut app = cell.borrow_mut();
10174 let box_ =
10175 RenderConstrainedBox::new(&mut app, BoxConstraints::tight(Size::new(10.0, 10.0)), None);
10176 box_.layout(&mut app, BoxConstraints::new(), false);
10177 assert!(!box_.debug_needs_layout(&app));
10178 box_.set_additional_constraints(&mut app, BoxConstraints::tight(Size::new(20.0, 20.0)));
10179 assert!(box_.debug_needs_layout(&app));
10180 box_.layout(&mut app, BoxConstraints::new(), false);
10181 assert_eq!(box_.size(&app), Size::new(20.0, 20.0));
10182 }
10183
10184 #[test]
10186 fn proxy_box_child_gets_empty_parent_data() {
10187 let cell = AppCell::new();
10188 let mut app = cell.borrow_mut();
10189 let child = sized_box(&mut app, Size::new(10.0, 10.0));
10190 let parent = RenderConstrainedBox::new(
10191 &mut app,
10192 BoxConstraints::tight(Size::new(10.0, 10.0)),
10193 Some(child.as_box()),
10194 );
10195 parent.layout(&mut app, BoxConstraints::new(), false);
10196 assert!(child.as_box().parent_data_is::<EmptyParentData>(&app));
10197 }
10198
10199 #[test]
10202 fn render_opacity_composites_only_when_visible() {
10203 let cell = AppCell::new();
10204 let mut app = cell.borrow_mut();
10205 for (opacity, composites) in [(0.0, false), (1.0, true), (0.1, true)] {
10206 let child = sized_box(&mut app, Size::new(1.0, 1.0));
10207 let opacity = RenderOpacity::new(&mut app, opacity, Some(child.as_box()));
10208 assert_eq!(opacity.as_object().is_repaint_boundary(&app), composites);
10209 }
10210 }
10211
10212 #[test]
10214 fn non_painted_layers_are_detached() {
10215 let cell = AppCell::new();
10216 let mut app = cell.borrow_mut();
10217 let inner = RenderDecoratedBox::new(
10218 &mut app,
10219 DecorationRef::new(BoxDecoration::new()),
10220 DecorationPosition::Background,
10221 ImageConfiguration::EMPTY,
10222 None,
10223 );
10224 let boundary = RenderRepaintBoundary::new(&mut app, Some(inner.as_box()));
10225 let opacity = RenderOpacity::new(&mut app, 1.0, Some(boundary.as_box()));
10226 layout_with(
10227 &mut app,
10228 opacity.as_box(),
10229 None,
10230 AlignmentGeometry::CENTER,
10231 EnginePhase::Paint,
10232 );
10233 assert!(!inner.as_object().is_repaint_boundary(&app));
10234 assert!(inner.as_object().debug_layer(&app).is_none());
10235 assert!(boundary.as_object().is_repaint_boundary(&app));
10236 let layer = boundary.as_object().debug_layer(&app).expect("painted");
10237 assert!(layer.as_layer().attached(&app), "this time it painted");
10238
10239 opacity.set_opacity(&mut app, 0.0);
10240 pump_frame(&mut app, EnginePhase::Paint);
10241 assert!(inner.as_object().debug_layer(&app).is_none());
10242 let layer = boundary.as_object().debug_layer(&app).expect("kept");
10243 assert!(!layer.as_layer().attached(&app), "this time it did not");
10244
10245 opacity.set_opacity(&mut app, 0.5);
10246 pump_frame(&mut app, EnginePhase::Paint);
10247 let layer = boundary.as_object().debug_layer(&app).expect("kept");
10248 assert!(layer.as_layer().attached(&app), "this time it did again");
10249 }
10250
10251 #[test]
10252 fn animated_opacity_follows_its_animation() {
10253 let cell = AppCell::new();
10254 let mut app = cell.borrow_mut();
10255 let child = sized_box(&mut app, Size::new(1.0, 1.0));
10256 let dismissed = k_always_dismissed_animation(&mut app);
10257 let complete = k_always_complete_animation(&mut app);
10258 let fade = RenderAnimatedOpacity::new(&mut app, dismissed, Some(child.as_box()));
10259 assert!(!fade.as_object().is_repaint_boundary(&app));
10260 layout_with(
10261 &mut app,
10262 fade.as_box(),
10263 Some(BoxConstraints::tight(Size::new(100.0, 100.0))),
10264 AlignmentGeometry::CENTER,
10265 EnginePhase::Paint,
10266 );
10267
10268 fade.set_opacity(&mut app, complete);
10269 assert!(fade.as_object().is_repaint_boundary(&app));
10270 assert!(fade.as_object().debug_needs_paint(&app));
10271 pump_frame(&mut app, EnginePhase::Paint);
10272 let layer = fade.as_object().debug_layer(&app).expect("a boundary now");
10273 let opacity = app
10274 .handle::<OpacityLayer>(layer.id())
10275 .expect("an OpacityLayer");
10276 assert_eq!(opacity.alpha(&app), Some(255));
10277 }
10278
10279 #[test]
10281 fn render_opacity_paints_its_child_only_above_zero_opacity() {
10282 let cell = AppCell::new();
10283 let mut app = cell.borrow_mut();
10284 for (opacity, paints) in [(0.0, false), (0.001, false), (0.01, true), (1.0, true)] {
10285 let child = sized_box(&mut app, Size::new(1.0, 1.0));
10286 let opacity = RenderOpacity::new(&mut app, opacity, Some(child.as_box()));
10287 assert_eq!(
10288 opacity.as_object().paints_child(&app, child.as_object()),
10289 paints
10290 );
10291 }
10292 }
10293
10294 #[test]
10296 fn animated_opacity_paints_its_child_while_its_animation_is_above_zero() {
10297 let cell = AppCell::new();
10298 let mut app = cell.borrow_mut();
10299 let child = sized_box(&mut app, Size::new(1.0, 1.0));
10300 let dismissed = k_always_dismissed_animation(&mut app);
10301 let complete = k_always_complete_animation(&mut app);
10302 let fade = RenderAnimatedOpacity::new(&mut app, dismissed, Some(child.as_box()));
10303 assert!(!fade.as_object().paints_child(&app, child.as_object()));
10304 fade.set_opacity(&mut app, complete);
10305 assert!(fade.as_object().paints_child(&app, child.as_object()));
10306 }
10307
10308 #[test]
10311 fn fitted_box_does_not_paint_an_empty_child() {
10312 let cell = AppCell::new();
10313 let mut app = cell.borrow_mut();
10314 let child = sized_box(&mut app, Size::new(0.0, 100.0));
10315 let fitted = RenderFittedBox::new(
10316 &mut app,
10317 BoxFit::Contain,
10318 AlignmentGeometry::CENTER,
10319 None,
10320 Some(child.as_box()),
10321 );
10322 fitted.layout(
10323 &mut app,
10324 BoxConstraints::tight(Size::new(50.0, 50.0)),
10325 false,
10326 );
10327 assert!(!fitted.as_object().paints_child(&app, child.as_object()));
10328 let mut transform = Matrix4::IDENTITY;
10329 RenderBox::apply_paint_transform(fitted, &app, child.as_object(), &mut transform);
10330 assert_eq!(transform, crate::object::zero_matrix());
10331
10332 let painted = sized_box(&mut app, Size::new(100.0, 100.0));
10333 fitted.set_child(&mut app, Some(painted.as_box()));
10334 fitted.layout(
10335 &mut app,
10336 BoxConstraints::tight(Size::new(50.0, 50.0)),
10337 false,
10338 );
10339 assert!(fitted.as_object().paints_child(&app, painted.as_object()));
10340 }
10341
10342 #[test]
10344 fn a_render_object_paints_its_child_by_default() {
10345 let cell = AppCell::new();
10346 let mut app = cell.borrow_mut();
10347 let child = sized_box(&mut app, Size::new(10.0, 10.0));
10348 let parent = RenderConstrainedBox::new(
10349 &mut app,
10350 BoxConstraints::tight(Size::new(10.0, 10.0)),
10351 Some(child.as_box()),
10352 );
10353 assert!(parent.as_object().paints_child(&app, child.as_object()));
10354 }
10355
10356 #[test]
10358 fn a_decorated_box_dump_shows_its_decoration() {
10359 let cell = AppCell::new();
10360 let mut app = cell.borrow_mut();
10361 let decorated = RenderDecoratedBox::new(
10362 &mut app,
10363 DecorationRef::new(BoxDecoration::new()),
10364 DecorationPosition::Background,
10365 ImageConfiguration::EMPTY,
10366 None,
10367 );
10368 assert_eq!(
10369 ignoring_hash_codes(
10370 &decorated
10371 .as_object()
10372 .to_string_deep_with(&app, waft_foundation::DiagnosticLevel::Info)
10373 ),
10374 "RenderDecoratedBox#00000 NEEDS-LAYOUT NEEDS-PAINT DETACHED\n\
10375 \u{20} parentData: MISSING\n\
10376 \u{20} constraints: MISSING\n\
10377 \u{20} size: MISSING\n\
10378 \u{20} decoration: BoxDecoration:\n\
10379 \u{20} <no decorations specified>\n\
10380 \u{20} configuration: ImageConfiguration()\n"
10381 );
10382 }
10383
10384 #[test]
10385 fn decorated_box_paints_its_decoration() {
10386 let cell = AppCell::new();
10387 let mut app = cell.borrow_mut();
10388 let decorated = RenderDecoratedBox::new(
10389 &mut app,
10390 DecorationRef::new(BoxDecoration::new().color(Color::from_argb(255, 255, 0, 0))),
10391 DecorationPosition::Background,
10392 ImageConfiguration::EMPTY,
10393 None,
10394 );
10395 layout_with(
10396 &mut app,
10397 decorated.as_box(),
10398 Some(BoxConstraints::tight(Size::new(100.0, 100.0))),
10399 AlignmentGeometry::CENTER,
10400 EnginePhase::Paint,
10401 );
10402 let ops = scene_ops(&mut app);
10403 assert!(
10404 ops.iter()
10405 .any(|op| matches!(op, waft_embedder::valo::Op::DrawDisplayList { .. })),
10406 "{ops:?}"
10407 );
10408 }
10409
10410 fn opaque_leaf(app: &mut App) -> RenderHandle<RenderPointerListener> {
10412 RenderPointerListener::new(app, HitTestBehavior::Opaque, None)
10413 }
10414
10415 const RED: Color = Color::from_argb(255, 255, 0, 0);
10416 const BLUE: Color = Color::from_argb(255, 0, 0, 255);
10417
10418 fn red_box(app: &mut App) -> RenderHandle<RenderColoredBox> {
10419 RenderColoredBox::new(app, RED, true, None)
10420 }
10421
10422 fn hit_test(app: &mut App, target: AnyRenderBox, position: Offset) -> (bool, usize) {
10424 let mut result = HitTestResult::new();
10425 let is_hit = target.hit_test(app, &mut BoxHitTestResult::wrap(&mut result), position);
10426 (is_hit, result.path().len())
10427 }
10428
10429 fn picture_has_clip(app: &mut App, render: AnyRenderObject) -> bool {
10431 painted_ops(app, render)
10432 .iter()
10433 .any(|op| matches!(op, Op::ClipPath { .. }))
10434 }
10435
10436 fn drawn_rects(app: &mut App, render: AnyRenderObject) -> Vec<(valo::Rect, valo::Color)> {
10438 painted_ops(app, render)
10439 .iter()
10440 .filter_map(|op| match op {
10441 Op::DrawRect { rect, paint, .. } => Some((*rect, paint.color)),
10442 _ => None,
10443 })
10444 .collect()
10445 }
10446
10447 fn fill(rect: Rect, color: Color) -> (valo::Rect, valo::Color) {
10448 (rect.into(), color.into())
10449 }
10450
10451 #[test]
10452 fn limited_box_limits_only_unbounded_constraints() {
10453 let cell = AppCell::new();
10454 let mut app = cell.borrow_mut();
10455 let child = opaque_leaf(&mut app);
10456 let limited = RenderLimitedBox::new(&mut app, 100.0, 50.0, Some(child.as_box()));
10457
10458 limited.layout(&mut app, BoxConstraints::new(), false);
10459 assert_eq!(limited.size(&app), Size::new(100.0, 50.0));
10460
10461 limited.layout(
10462 &mut app,
10463 BoxConstraints::loose(Size::new(30.0, 30.0)),
10464 false,
10465 );
10466 assert_eq!(
10467 limited.size(&app),
10468 Size::new(30.0, 30.0),
10469 "a bounded constraint is left alone"
10470 );
10471 }
10472
10473 #[test]
10474 fn limited_box_without_child_is_empty() {
10475 let cell = AppCell::new();
10476 let mut app = cell.borrow_mut();
10477 let limited = RenderLimitedBox::new(&mut app, 100.0, 50.0, None);
10478 limited.layout(&mut app, BoxConstraints::new(), false);
10479 assert_eq!(limited.size(&app), Size::ZERO);
10480 }
10481
10482 struct LeftHalfClipper;
10484
10485 impl CustomClipper<Rect> for LeftHalfClipper {
10486 fn get_clip(&self, _app: &App, size: Size) -> Rect {
10487 Rect::from_ltwh(0.0, 0.0, size.width() / 2.0, size.height())
10488 }
10489
10490 fn get_approximate_clip_rect(&self, app: &App, size: Size) -> Rect {
10491 self.get_clip(app, size)
10492 }
10493
10494 fn should_reclip(&self, _app: &App, _old_clipper: &dyn CustomClipper<Rect>) -> bool {
10495 false
10496 }
10497
10498 fn as_any(&self) -> &dyn Any {
10499 self
10500 }
10501 }
10502
10503 impl CustomClipper<RRect> for LeftHalfClipper {
10504 fn get_clip(&self, _app: &App, size: Size) -> RRect {
10505 RRect::from_rect_xy(
10506 Rect::from_ltwh(0.0, 0.0, size.width() / 2.0, size.height()),
10507 0.0,
10508 0.0,
10509 )
10510 }
10511
10512 fn should_reclip(&self, _app: &App, _old_clipper: &dyn CustomClipper<RRect>) -> bool {
10513 false
10514 }
10515
10516 fn as_any(&self) -> &dyn Any {
10517 self
10518 }
10519 }
10520
10521 struct NotifyingClipper {
10523 reclip: Rc<dyn Listenable>,
10524 }
10525
10526 impl CustomClipper<Rect> for NotifyingClipper {
10527 fn reclip(&self) -> Option<&Rc<dyn Listenable>> {
10528 Some(&self.reclip)
10529 }
10530
10531 fn get_clip(&self, _app: &App, size: Size) -> Rect {
10532 Offset::ZERO & size
10533 }
10534
10535 fn should_reclip(&self, _app: &App, _old_clipper: &dyn CustomClipper<Rect>) -> bool {
10536 false
10537 }
10538
10539 fn as_any(&self) -> &dyn Any {
10540 self
10541 }
10542 }
10543
10544 #[test]
10545 fn clip_rect_pushes_its_clipper_and_clips_hit_tests() {
10546 let cell = AppCell::new();
10547 let mut app = cell.borrow_mut();
10548 let child = opaque_leaf(&mut app);
10549 let clipper: Rc<dyn CustomClipper<Rect>> = Rc::new(LeftHalfClipper);
10550 let clip = RenderClipRect::new(
10551 &mut app,
10552 Some(clipper),
10553 Clip::HardEdge,
10554 Some(child.as_box()),
10555 );
10556 layout_with(
10557 &mut app,
10558 clip.as_box(),
10559 Some(BoxConstraints::tight(Size::new(100.0, 100.0))),
10560 AlignmentGeometry::CENTER,
10561 EnginePhase::Paint,
10562 );
10563
10564 let ops = painted_ops(&mut app, clip.as_object());
10565 let clip_path = ops
10566 .iter()
10567 .find_map(|op| match op {
10568 Op::ClipPath { path, .. } => Some(path),
10569 _ => None,
10570 })
10571 .expect("the recording clips");
10572 assert_eq!(
10573 clip_path.bounds(),
10574 Rect::from_ltwh(0.0, 0.0, 50.0, 100.0).into()
10575 );
10576
10577 assert!(hit_test(&mut app, clip.as_box(), Offset::new(25.0, 50.0)).0);
10578 assert!(
10579 !hit_test(&mut app, clip.as_box(), Offset::new(75.0, 50.0)).0,
10580 "outside the clipper's clip"
10581 );
10582 }
10583
10584 #[test]
10585 fn clip_rect_without_clipping_paints_its_child_directly() {
10586 let cell = AppCell::new();
10587 let mut app = cell.borrow_mut();
10588 let child = red_box(&mut app);
10589 let clip = RenderClipRect::new(&mut app, None, Clip::None, Some(child.as_box()));
10590 layout_with(
10591 &mut app,
10592 clip.as_box(),
10593 Some(BoxConstraints::tight(Size::new(100.0, 100.0))),
10594 AlignmentGeometry::CENTER,
10595 EnginePhase::Paint,
10596 );
10597
10598 assert!(
10599 !picture_has_clip(&mut app, clip.as_object()),
10600 "Clip::None paints the child directly"
10601 );
10602 assert_eq!(
10603 drawn_rects(&mut app, clip.as_object()),
10604 [fill(Rect::from_ltwh(0.0, 0.0, 100.0, 100.0), RED)]
10605 );
10606 }
10607
10608 #[test]
10611 fn custom_clip_extenders_respect_clip_behavior_when_described() {
10612 let cell = AppCell::new();
10613 let mut app = cell.borrow_mut();
10614 let child = RenderConstrainedBox::new(
10615 &mut app,
10616 BoxConstraints::tight_for(Some(200.0), Some(200.0)),
10617 None,
10618 );
10619 let clip = RenderClipRect::new(&mut app, None, Clip::None, Some(child.as_box()));
10620 layout_with(
10621 &mut app,
10622 clip.as_box(),
10623 Some(BoxConstraints::tight(Size::new(100.0, 100.0))),
10624 AlignmentGeometry::CENTER,
10625 EnginePhase::Paint,
10626 );
10627
10628 assert_eq!(
10629 clip.as_object()
10630 .describe_approximate_paint_clip(&app, child.as_object()),
10631 None
10632 );
10633 for clip_behavior in [
10634 Clip::HardEdge,
10635 Clip::AntiAlias,
10636 Clip::AntiAliasWithSaveLayer,
10637 ] {
10638 clip.set_clip_behavior(&mut app, clip_behavior);
10639 assert_eq!(
10640 clip.as_object()
10641 .describe_approximate_paint_clip(&app, child.as_object()),
10642 Some(Offset::ZERO & clip.size(&app)),
10643 "{clip_behavior:?}"
10644 );
10645 }
10646 }
10647
10648 #[test]
10651 fn a_custom_clip_asks_its_clipper_for_an_approximate_rect() {
10652 let cell = AppCell::new();
10653 let mut app = cell.borrow_mut();
10654 let child = RenderConstrainedBox::new(
10655 &mut app,
10656 BoxConstraints::tight_for(Some(200.0), Some(200.0)),
10657 None,
10658 );
10659 let clipper: Rc<dyn CustomClipper<Rect>> = Rc::new(LeftHalfClipper);
10660 let clip = RenderClipRect::new(
10661 &mut app,
10662 Some(clipper),
10663 Clip::HardEdge,
10664 Some(child.as_box()),
10665 );
10666 layout_with(
10667 &mut app,
10668 clip.as_box(),
10669 Some(BoxConstraints::tight(Size::new(100.0, 100.0))),
10670 AlignmentGeometry::CENTER,
10671 EnginePhase::Paint,
10672 );
10673
10674 assert_eq!(
10675 clip.as_object()
10676 .describe_approximate_paint_clip(&app, child.as_object()),
10677 Some(Rect::from_ltwh(0.0, 0.0, 50.0, 100.0))
10678 );
10679 }
10680
10681 #[test]
10682 fn clip_rrect_pushes_its_border_radius() {
10683 let cell = AppCell::new();
10684 let mut app = cell.borrow_mut();
10685 let child = opaque_leaf(&mut app);
10686 let clip = RenderClipRRect::new(
10687 &mut app,
10688 BorderRadiusGeometry::circular(20.0),
10689 None,
10690 Clip::AntiAlias,
10691 None,
10692 Some(child.as_box()),
10693 );
10694 layout_with(
10695 &mut app,
10696 clip.as_box(),
10697 Some(BoxConstraints::tight(Size::new(100.0, 100.0))),
10698 AlignmentGeometry::CENTER,
10699 EnginePhase::Paint,
10700 );
10701
10702 let bounds = Rect::from_ltwh(0.0, 0.0, 100.0, 100.0);
10703 let ops = painted_ops(&mut app, clip.as_object());
10704 let clip_path = ops
10705 .iter()
10706 .find_map(|op| match op {
10707 Op::ClipPath { path, .. } => Some(path),
10708 _ => None,
10709 })
10710 .expect("the recording starts with the clip");
10711 assert_eq!(clip_path.bounds(), bounds.into());
10712
10713 assert!(
10714 hit_test(&mut app, clip.as_box(), Offset::new(99.0, 99.0)).0,
10715 "without a clipper the hit test is not clipped, as in Dart"
10716 );
10717 }
10718
10719 #[test]
10720 fn clip_rrect_clips_hit_tests_to_its_clipper() {
10721 let cell = AppCell::new();
10722 let mut app = cell.borrow_mut();
10723 let child = opaque_leaf(&mut app);
10724 let clipper: Rc<dyn CustomClipper<RRect>> = Rc::new(LeftHalfClipper);
10725 let clip = RenderClipRRect::new(
10726 &mut app,
10727 BorderRadiusGeometry::ZERO,
10728 Some(clipper),
10729 Clip::AntiAlias,
10730 None,
10731 Some(child.as_box()),
10732 );
10733 clip.layout(
10734 &mut app,
10735 BoxConstraints::tight(Size::new(100.0, 100.0)),
10736 false,
10737 );
10738
10739 assert!(hit_test(&mut app, clip.as_box(), Offset::new(25.0, 50.0)).0);
10740 assert!(!hit_test(&mut app, clip.as_box(), Offset::new(75.0, 50.0)).0);
10741 }
10742
10743 #[test]
10745 fn clip_rect_reclips_on_notification_and_on_resize() {
10746 let cell = AppCell::new();
10747 let mut app = cell.borrow_mut();
10748 let reclip = app.create(ValueNotifier::new(0));
10749 let clipper: Rc<dyn CustomClipper<Rect>> = Rc::new(NotifyingClipper {
10750 reclip: Rc::new(reclip.clone()),
10751 });
10752 let child = red_box(&mut app);
10753 let clip = RenderClipRect::new(
10754 &mut app,
10755 Some(clipper),
10756 Clip::HardEdge,
10757 Some(child.as_box()),
10758 );
10759 layout_with(
10760 &mut app,
10761 clip.as_box(),
10762 Some(BoxConstraints::tight(Size::new(100.0, 100.0))),
10763 AlignmentGeometry::CENTER,
10764 EnginePhase::Paint,
10765 );
10766 assert!(clip.custom_clip_data(&app).clip.is_some());
10767
10768 reclip.set_value(&mut app, 1);
10769 assert!(
10770 clip.custom_clip_data(&app).clip.is_none(),
10771 "the clipper's notification dropped the cached clip"
10772 );
10773 assert!(clip.as_object().debug_needs_paint(&app));
10774 pump_frame(&mut app, EnginePhase::Paint);
10775 assert!(clip.custom_clip_data(&app).clip.is_some());
10776
10777 clip.layout(
10778 &mut app,
10779 BoxConstraints::tight(Size::new(50.0, 50.0)),
10780 false,
10781 );
10782 assert!(
10783 clip.custom_clip_data(&app).clip.is_none(),
10784 "a new size dropped the cached clip"
10785 );
10786 }
10787
10788 #[test]
10789 fn transform_paints_under_its_matrix() {
10790 let cell = AppCell::new();
10791 let mut app = cell.borrow_mut();
10792 let child = red_box(&mut app);
10793 let transform = RenderTransform::new(
10794 &mut app,
10795 Matrix4::scale(2.0, 2.0),
10796 None,
10797 None,
10798 None,
10799 true,
10800 None,
10801 Some(child.as_box()),
10802 );
10803 layout_with(
10804 &mut app,
10805 transform.as_box(),
10806 Some(BoxConstraints::tight(Size::new(100.0, 100.0))),
10807 AlignmentGeometry::CENTER,
10808 EnginePhase::Paint,
10809 );
10810
10811 let ops = painted_ops(&mut app, transform.as_object());
10812 let pushed = ops.iter().find_map(|op| match op {
10813 Op::Transform(transform) => Some(*transform),
10814 _ => None,
10815 });
10816 assert_eq!(pushed, Some(Matrix4::scale(2.0, 2.0)));
10817 }
10818
10819 #[test]
10821 fn transform_by_a_translation_paints_at_an_offset() {
10822 let cell = AppCell::new();
10823 let mut app = cell.borrow_mut();
10824 let child = red_box(&mut app);
10825 let transform = RenderTransform::new(
10826 &mut app,
10827 Matrix4::translation(10.0, 20.0),
10828 None,
10829 None,
10830 None,
10831 true,
10832 None,
10833 Some(child.as_box()),
10834 );
10835 layout_with(
10836 &mut app,
10837 transform.as_box(),
10838 Some(BoxConstraints::tight(Size::new(100.0, 100.0))),
10839 AlignmentGeometry::CENTER,
10840 EnginePhase::Paint,
10841 );
10842
10843 assert!(
10844 !painted_ops(&mut app, transform.as_object())
10845 .iter()
10846 .any(|op| matches!(op, Op::Transform(_))),
10847 "a translation is folded into the child's paint offset"
10848 );
10849 assert_eq!(
10850 drawn_rects(&mut app, transform.as_object()),
10851 [fill(Rect::from_ltwh(10.0, 20.0, 100.0, 100.0), RED)]
10852 );
10853 }
10854
10855 #[test]
10856 fn transform_hit_tests_through_its_matrix() {
10857 let cell = AppCell::new();
10858 let mut app = cell.borrow_mut();
10859 let child = opaque_leaf(&mut app);
10860 let transform = RenderTransform::new(
10861 &mut app,
10862 Matrix4::scale(2.0, 2.0),
10863 None,
10864 None,
10865 None,
10866 true,
10867 None,
10868 Some(child.as_box()),
10869 );
10870 transform.layout(
10871 &mut app,
10872 BoxConstraints::tight(Size::new(100.0, 100.0)),
10873 false,
10874 );
10875
10876 assert_eq!(
10877 hit_test(&mut app, transform.as_box(), Offset::new(150.0, 50.0)),
10878 (true, 1),
10879 "the child covers twice the box, and the transform does not add itself"
10880 );
10881
10882 transform.set_transform_hit_tests(&mut app, false);
10883 assert!(!hit_test(&mut app, transform.as_box(), Offset::new(150.0, 50.0)).0);
10884 assert!(hit_test(&mut app, transform.as_box(), Offset::new(50.0, 50.0)).0);
10885 }
10886
10887 #[test]
10889 fn transform_scales_around_its_alignment_and_origin() {
10890 let cell = AppCell::new();
10891 let mut app = cell.borrow_mut();
10892 let child = opaque_leaf(&mut app);
10893 let transform = RenderTransform::new(
10894 &mut app,
10895 Matrix4::scale(2.0, 2.0),
10896 None,
10897 Some(AlignmentGeometry::CENTER),
10898 None,
10899 true,
10900 None,
10901 Some(child.as_box()),
10902 );
10903 transform.layout(
10904 &mut app,
10905 BoxConstraints::tight(Size::new(100.0, 100.0)),
10906 false,
10907 );
10908 assert!(hit_test(&mut app, transform.as_box(), Offset::new(140.0, 140.0)).0);
10909 assert!(!hit_test(&mut app, transform.as_box(), Offset::new(160.0, 160.0)).0);
10910
10911 transform.set_alignment(&mut app, None);
10912 transform.set_origin(&mut app, Some(Offset::new(50.0, 50.0)));
10913 assert!(
10914 hit_test(&mut app, transform.as_box(), Offset::new(140.0, 140.0)).0,
10915 "an origin at the centre is the same conjugation"
10916 );
10917 assert!(!hit_test(&mut app, transform.as_box(), Offset::new(160.0, 160.0)).0);
10918 }
10919
10920 #[test]
10921 fn transform_applies_its_paint_transform_to_the_child() {
10922 let cell = AppCell::new();
10923 let mut app = cell.borrow_mut();
10924 let child = opaque_leaf(&mut app);
10925 let transform = RenderTransform::new(
10926 &mut app,
10927 Matrix4::translation(10.0, 20.0),
10928 None,
10929 None,
10930 None,
10931 true,
10932 None,
10933 Some(child.as_box()),
10934 );
10935 let mut matrix = Matrix4::IDENTITY;
10936 RenderBox::apply_paint_transform(transform, &app, child.as_object(), &mut matrix);
10937 assert_eq!(matrix, Matrix4::translation(10.0, 20.0));
10938 }
10939
10940 #[test]
10941 fn fractional_translation_offsets_paint_and_hits() {
10942 let cell = AppCell::new();
10943 let mut app = cell.borrow_mut();
10944 let child = red_box(&mut app);
10945 let translated = RenderFractionalTranslation::new(
10946 &mut app,
10947 Offset::new(0.5, 0.0),
10948 true,
10949 Some(child.as_box()),
10950 );
10951 layout_with(
10952 &mut app,
10953 translated.as_box(),
10954 Some(BoxConstraints::tight(Size::new(100.0, 100.0))),
10955 AlignmentGeometry::CENTER,
10956 EnginePhase::Paint,
10957 );
10958
10959 assert_eq!(
10960 drawn_rects(&mut app, translated.as_object()),
10961 [fill(Rect::from_ltwh(50.0, 0.0, 100.0, 100.0), RED)],
10962 "half the width to the right"
10963 );
10964
10965 assert!(hit_test(&mut app, translated.as_box(), Offset::new(75.0, 50.0)).0);
10966 assert!(!hit_test(&mut app, translated.as_box(), Offset::new(25.0, 50.0)).0);
10967
10968 translated.set_transform_hit_tests(&mut app, false);
10969 assert!(
10970 hit_test(&mut app, translated.as_box(), Offset::new(25.0, 50.0)).0,
10971 "an untransformed hit test reaches the child where it was laid out"
10972 );
10973 }
10974
10975 #[test]
10976 fn ignore_pointer_is_invisible_to_hit_testing() {
10977 let cell = AppCell::new();
10978 let mut app = cell.borrow_mut();
10979 let child = opaque_leaf(&mut app);
10980 let ignoring = RenderIgnorePointer::new(&mut app, true, Some(child.as_box()));
10981 ignoring.layout(
10982 &mut app,
10983 BoxConstraints::tight(Size::new(100.0, 100.0)),
10984 false,
10985 );
10986
10987 assert_eq!(
10988 hit_test(&mut app, ignoring.as_box(), Offset::new(50.0, 50.0)),
10989 (false, 0)
10990 );
10991
10992 ignoring.set_ignoring(&mut app, false);
10993 assert_eq!(
10994 hit_test(&mut app, ignoring.as_box(), Offset::new(50.0, 50.0)),
10995 (true, 2),
10996 "the child and the ignore pointer itself"
10997 );
10998 }
10999
11000 #[test]
11001 fn absorb_pointer_takes_the_hit_from_its_subtree() {
11002 let cell = AppCell::new();
11003 let mut app = cell.borrow_mut();
11004 let child = opaque_leaf(&mut app);
11005 let absorbing = RenderAbsorbPointer::new(&mut app, true, Some(child.as_box()));
11006 absorbing.layout(
11007 &mut app,
11008 BoxConstraints::tight(Size::new(100.0, 100.0)),
11009 false,
11010 );
11011
11012 assert_eq!(
11013 hit_test(&mut app, absorbing.as_box(), Offset::new(50.0, 50.0)),
11014 (true, 0),
11015 "hit testing stops here, and nothing is added to the path"
11016 );
11017 assert_eq!(
11018 hit_test(&mut app, absorbing.as_box(), Offset::new(150.0, 50.0)),
11019 (false, 0)
11020 );
11021
11022 absorbing.set_absorbing(&mut app, false);
11023 assert_eq!(
11024 hit_test(&mut app, absorbing.as_box(), Offset::new(50.0, 50.0)),
11025 (true, 2)
11026 );
11027 }
11028
11029 #[test]
11030 fn offstage_lays_out_without_painting_or_hit_testing() {
11031 let cell = AppCell::new();
11032 let mut app = cell.borrow_mut();
11033 let child = red_box(&mut app);
11034 let offstage = RenderOffstage::new(&mut app, true, Some(child.as_box()));
11035 layout_with(
11036 &mut app,
11037 offstage.as_box(),
11038 Some(BoxConstraints::tight(Size::new(100.0, 100.0))),
11039 AlignmentGeometry::CENTER,
11040 EnginePhase::Paint,
11041 );
11042
11043 assert!(RenderObject::sized_by_parent(offstage, &app));
11044 assert_eq!(child.size(&app), Size::new(100.0, 100.0), "still laid out");
11045 assert!(
11046 !picture_has_clip(&mut app, offstage.as_object()),
11047 "offstage paints nothing"
11048 );
11049 assert_eq!(
11050 hit_test(&mut app, offstage.as_box(), Offset::new(50.0, 50.0)),
11051 (false, 0)
11052 );
11053 assert!(!offstage.as_object().paints_child(&app, child.as_object()));
11054
11055 offstage.set_offstage(&mut app, false);
11056 pump_frame(&mut app, EnginePhase::Paint);
11057 assert_eq!(
11058 drawn_rects(&mut app, offstage.as_object()),
11059 [fill(Rect::from_ltwh(0.0, 0.0, 100.0, 100.0), RED)]
11060 );
11061 assert!(hit_test(&mut app, offstage.as_box(), Offset::new(50.0, 50.0)).0);
11062 assert!(offstage.as_object().paints_child(&app, child.as_object()));
11063 }
11064
11065 #[test]
11066 fn colored_box_fills_its_bounds() {
11067 let cell = AppCell::new();
11068 let mut app = cell.borrow_mut();
11069 let colored = red_box(&mut app);
11070 layout_with(
11071 &mut app,
11072 colored.as_box(),
11073 Some(BoxConstraints::tight(Size::new(100.0, 100.0))),
11074 AlignmentGeometry::CENTER,
11075 EnginePhase::Paint,
11076 );
11077
11078 assert_eq!(
11079 drawn_rects(&mut app, colored.as_object()),
11080 [fill(Rect::from_ltwh(0.0, 0.0, 100.0, 100.0), RED)]
11081 );
11082 assert_eq!(
11083 hit_test(&mut app, colored.as_box(), Offset::new(50.0, 50.0)),
11084 (true, 1),
11085 "an opaque box is hit by itself"
11086 );
11087 }
11088
11089 #[test]
11090 fn colored_box_paints_its_child_over_the_color() {
11091 let cell = AppCell::new();
11092 let mut app = cell.borrow_mut();
11093 let child = red_box(&mut app);
11094 let colored = RenderColoredBox::new(&mut app, BLUE, true, Some(child.as_box()));
11095 layout_with(
11096 &mut app,
11097 colored.as_box(),
11098 Some(BoxConstraints::tight(Size::new(100.0, 100.0))),
11099 AlignmentGeometry::CENTER,
11100 EnginePhase::Paint,
11101 );
11102
11103 let bounds = Rect::from_ltwh(0.0, 0.0, 100.0, 100.0);
11104 assert_eq!(
11105 drawn_rects(&mut app, colored.as_object()),
11106 [fill(bounds, BLUE), fill(bounds, RED)]
11107 );
11108 }
11109
11110 #[test]
11111 fn meta_data_carries_its_payload_and_hit_tests_by_behavior() {
11112 let cell = AppCell::new();
11113 let mut app = cell.borrow_mut();
11114 let payload: Rc<dyn Any> = Rc::new(42u32);
11115 let opaque = RenderMetaData::new(
11116 &mut app,
11117 Some(Rc::clone(&payload)),
11118 HitTestBehavior::Opaque,
11119 None,
11120 );
11121 opaque.layout(
11122 &mut app,
11123 BoxConstraints::tight(Size::new(10.0, 10.0)),
11124 false,
11125 );
11126 assert_eq!(
11127 opaque
11128 .meta_data(&app)
11129 .and_then(|data| data.downcast::<u32>().ok())
11130 .as_deref(),
11131 Some(&42)
11132 );
11133 let mut result = HitTestResult::new();
11134 assert!(opaque.as_box().hit_test(
11135 &mut app,
11136 &mut BoxHitTestResult::wrap(&mut result),
11137 Offset::new(5.0, 5.0)
11138 ));
11139 assert_eq!(result.path().len(), 1);
11140
11141 let deferring = RenderMetaData::new(&mut app, None, HitTestBehavior::DeferToChild, None);
11142 deferring.layout(
11143 &mut app,
11144 BoxConstraints::tight(Size::new(10.0, 10.0)),
11145 false,
11146 );
11147 let mut result = HitTestResult::new();
11148 assert!(!deferring.as_box().hit_test(
11149 &mut app,
11150 &mut BoxHitTestResult::wrap(&mut result),
11151 Offset::new(5.0, 5.0)
11152 ));
11153 assert!(result.path().is_empty());
11154
11155 let child = opaque_leaf(&mut app);
11157 deferring.set_child(&mut app, Some(child.as_box()));
11158 deferring.layout(
11159 &mut app,
11160 BoxConstraints::tight(Size::new(10.0, 10.0)),
11161 false,
11162 );
11163 let mut result = HitTestResult::new();
11164 assert!(deferring.as_box().hit_test(
11165 &mut app,
11166 &mut BoxHitTestResult::wrap(&mut result),
11167 Offset::new(5.0, 5.0)
11168 ));
11169 assert_eq!(result.path().len(), 2, "the child, then the meta data");
11170 }
11171
11172 fn scene_ops(app: &mut App) -> Vec<Op> {
11174 let scene = test_render_root(app)
11175 .as_object()
11176 .debug_layer(app)
11177 .expect("painted")
11178 .build_scene(app, SceneBuilder::new());
11179 waft_embedder::flattened_ops(&waft_embedder::slices(&scene, |_| None).picture_with_room())
11180 }
11181
11182 #[test]
11183 fn a_backdrop_filter_blurs_under_its_bounds_before_its_child_paints() {
11184 let cell = AppCell::new();
11185 let mut app = cell.borrow_mut();
11186 let child = RenderColoredBox::new(&mut app, Color::new(0xFF00FF00), true, None);
11187 let filter = RenderBackdropFilter::new(
11188 &mut app,
11189 ImageFilterConfig::new(ImageFilter::blur(6.0, 6.0)),
11190 BlendMode::SrcOver,
11191 true,
11192 None,
11193 Some(child.as_box()),
11194 );
11195 layout_with(
11196 &mut app,
11197 filter.as_box(),
11198 Some(BoxConstraints::tight(Size::new(100.0, 100.0))),
11199 AlignmentGeometry::CENTER,
11200 EnginePhase::Paint,
11201 );
11202 let ops = scene_ops(&mut app);
11203 let blur = ops
11204 .iter()
11205 .position(|op| {
11206 matches!(
11207 op,
11208 Op::SaveLayer {
11209 backdrop: Some(_),
11210 ..
11211 }
11212 )
11213 })
11214 .expect("a backdrop layer");
11215 let draw = ops
11216 .iter()
11217 .position(|op| matches!(op, Op::DrawRect { .. }))
11218 .expect("the child's paint");
11219 assert!(blur < draw, "the blur precedes the child: {ops:?}");
11220 if let Op::SaveLayer {
11221 backdrop: Some(backdrop),
11222 ..
11223 } = &ops[blur]
11224 {
11225 assert_eq!(
11226 backdrop.filter,
11227 waft_embedder::valo::ImageFilter::blur(6.0, 6.0)
11228 );
11229 assert_eq!(backdrop.shared_key, None);
11230 }
11231
11232 let key = BackdropKey::new();
11233 filter.set_backdrop_key(&mut app, Some(key));
11234 pump_frame(&mut app, EnginePhase::Paint);
11235 let ops = scene_ops(&mut app);
11236 assert!(
11237 ops.iter().any(|op| matches!(
11238 op,
11239 Op::SaveLayer {
11240 backdrop: Some(valo::Backdrop {
11241 shared_key: Some(_),
11242 ..
11243 }),
11244 ..
11245 }
11246 )),
11247 "a keyed filter shares its blur: {ops:?}"
11248 );
11249
11250 filter.set_enabled(&mut app, false);
11251 pump_frame(&mut app, EnginePhase::Paint);
11252 let ops = scene_ops(&mut app);
11253 assert!(
11254 !ops.iter().any(|op| matches!(
11255 op,
11256 Op::SaveLayer {
11257 backdrop: Some(_),
11258 ..
11259 }
11260 )),
11261 "disabled paints the child only: {ops:?}"
11262 );
11263 }
11264
11265 #[test]
11266 fn a_composed_backdrop_filter_reaches_the_backdrop_whole() {
11267 let cell = AppCell::new();
11268 let mut app = cell.borrow_mut();
11269 let child = RenderColoredBox::new(&mut app, Color::new(0xFF00FF00), true, None);
11270 let saturation = ColorFilter::saturation(1.8);
11271 let filter = RenderBackdropFilter::new(
11272 &mut app,
11273 ImageFilterConfig::compose(
11274 ImageFilterConfig::new(ImageFilter::Color(saturation)),
11275 ImageFilterConfig::blur().sigma_x(4.0),
11276 ),
11277 BlendMode::SrcOver,
11278 true,
11279 None,
11280 Some(child.as_box()),
11281 );
11282 layout_with(
11283 &mut app,
11284 filter.as_box(),
11285 Some(BoxConstraints::tight(Size::new(100.0, 100.0))),
11286 AlignmentGeometry::CENTER,
11287 EnginePhase::Paint,
11288 );
11289 let ops = scene_ops(&mut app);
11290 let composed = valo::ImageFilter::compose(
11291 valo::ImageFilter::Color(saturation.to_valo()),
11292 valo::ImageFilter::blur(4.0, 0.0),
11293 );
11294 assert!(
11295 ops.iter().any(|op| matches!(
11296 op,
11297 Op::SaveLayer {
11298 backdrop: Some(backdrop),
11299 ..
11300 } if backdrop.filter == composed
11301 )),
11302 "the saturation and the blur reach the backdrop in their order: {ops:?}"
11303 );
11304 }
11305
11306 #[test]
11307 fn clip_oval_hit_tests_inside_the_inscribed_oval_and_clips_with_its_path() {
11308 let cell = AppCell::new();
11309 let mut app = cell.borrow_mut();
11310 let child = opaque_leaf(&mut app);
11311 let oval = RenderClipOval::new(&mut app, None, Clip::AntiAlias, Some(child.as_box()));
11312 layout_with(
11313 &mut app,
11314 oval.as_box(),
11315 Some(BoxConstraints::tight(Size::new(100.0, 100.0))),
11316 AlignmentGeometry::CENTER,
11317 EnginePhase::Paint,
11318 );
11319 let hit = |app: &mut App, x: f64, y: f64| {
11320 let mut result = HitTestResult::new();
11321 oval.as_box().hit_test(
11322 app,
11323 &mut BoxHitTestResult::wrap(&mut result),
11324 Offset::new(x, y),
11325 )
11326 };
11327 assert!(hit(&mut app, 50.0, 50.0), "the center is inside");
11328 assert!(!hit(&mut app, 2.0, 2.0), "a corner is outside the oval");
11329 assert!(
11330 picture_has_clip(&mut app, oval.as_object()),
11331 "an oval clips with a path"
11332 );
11333 }
11334
11335 #[test]
11336 fn clip_path_uses_its_clipper_for_hit_tests_and_the_rect_by_default() {
11337 struct Triangle;
11338 impl CustomClipper<Path> for Triangle {
11339 fn get_clip(&self, _app: &App, size: Size) -> Path {
11340 let mut path = PathBuilder::new();
11341 path.move_to(Point::new(0.0, 0.0));
11342 path.line_to(Point::new(size.width() as f32, 0.0));
11343 path.line_to(Point::new(0.0, size.height() as f32));
11344 path.close();
11345 path.build().into()
11346 }
11347
11348 fn should_reclip(&self, _app: &App, _old: &dyn CustomClipper<Path>) -> bool {
11349 false
11350 }
11351
11352 fn as_any(&self) -> &dyn Any {
11353 self
11354 }
11355 }
11356 let cell = AppCell::new();
11357 let mut app = cell.borrow_mut();
11358 let child = opaque_leaf(&mut app);
11359 let clip = RenderClipPath::new(
11360 &mut app,
11361 Some(Rc::new(Triangle)),
11362 Clip::AntiAlias,
11363 Some(child.as_box()),
11364 );
11365 layout_with(
11366 &mut app,
11367 clip.as_box(),
11368 Some(BoxConstraints::tight(Size::new(100.0, 100.0))),
11369 AlignmentGeometry::CENTER,
11370 EnginePhase::Paint,
11371 );
11372 let hit = |app: &mut App, x: f64, y: f64| {
11373 let mut result = HitTestResult::new();
11374 clip.as_box().hit_test(
11375 app,
11376 &mut BoxHitTestResult::wrap(&mut result),
11377 Offset::new(x, y),
11378 )
11379 };
11380 assert!(hit(&mut app, 10.0, 10.0), "inside the triangle");
11381 assert!(!hit(&mut app, 90.0, 90.0), "outside the triangle");
11382
11383 let plain = RenderClipPath::new(&mut app, None, Clip::HardEdge, None);
11384 plain.layout(
11385 &mut app,
11386 BoxConstraints::tight(Size::new(30.0, 20.0)),
11387 false,
11388 );
11389 assert!(
11390 plain.default_clip(&app).contains(Offset::new(29.0, 19.0)),
11391 "the default clip is the box's rect"
11392 );
11393 }
11394
11395 #[test]
11396 fn clip_path_clips_and_hit_tests_with_the_fill_type_of_its_path() {
11397 struct Ring;
11398 impl CustomClipper<Path> for Ring {
11399 fn get_clip(&self, _app: &App, size: Size) -> Path {
11400 let mut path = PathBuilder::new();
11401 path.rect((Offset::ZERO & size).into());
11402 path.rect(Rect::from_ltwh(25.0, 25.0, 50.0, 50.0).into());
11403 let mut path = Path::new(path.build());
11404 path.fill_type = waft_embedder::PathFillType::EvenOdd;
11405 path
11406 }
11407
11408 fn should_reclip(&self, _app: &App, _old: &dyn CustomClipper<Path>) -> bool {
11409 false
11410 }
11411
11412 fn as_any(&self) -> &dyn Any {
11413 self
11414 }
11415 }
11416 let cell = AppCell::new();
11417 let mut app = cell.borrow_mut();
11418 let child = opaque_leaf(&mut app);
11419 let clip = RenderClipPath::new(
11420 &mut app,
11421 Some(Rc::new(Ring)),
11422 Clip::AntiAlias,
11423 Some(child.as_box()),
11424 );
11425 layout_with(
11426 &mut app,
11427 clip.as_box(),
11428 Some(BoxConstraints::tight(Size::new(100.0, 100.0))),
11429 AlignmentGeometry::CENTER,
11430 EnginePhase::Paint,
11431 );
11432
11433 let ops = painted_ops(&mut app, clip.as_object());
11434 let fill_rule = ops
11435 .iter()
11436 .find_map(|op| match op {
11437 Op::ClipPath { fill_rule, .. } => Some(*fill_rule),
11438 _ => None,
11439 })
11440 .expect("the recording clips");
11441 assert_eq!(fill_rule, FillRule::EvenOdd);
11442 assert!(hit_test(&mut app, clip.as_box(), Offset::new(10.0, 10.0)).0);
11443 assert!(
11444 !hit_test(&mut app, clip.as_box(), Offset::new(50.0, 50.0)).0,
11445 "the hole the even-odd rule leaves"
11446 );
11447 }
11448
11449 #[test]
11450 fn clip_rsuperellipse_resolves_its_border_radius_and_clips_with_a_path() {
11451 let cell = AppCell::new();
11452 let mut app = cell.borrow_mut();
11453 let child = RenderConstrainedBox::new(&mut app, BoxConstraints::expand(None, None), None);
11454 let clip = RenderClipRSuperellipse::new(
11455 &mut app,
11456 BorderRadiusGeometry::circular(12.0),
11457 None,
11458 Clip::AntiAlias,
11459 Some(TextDirection::Ltr),
11460 Some(child.as_box()),
11461 );
11462 layout_with(
11463 &mut app,
11464 clip.as_box(),
11465 Some(BoxConstraints::tight(Size::new(100.0, 100.0))),
11466 AlignmentGeometry::CENTER,
11467 EnginePhase::Paint,
11468 );
11469 clip.update_clip(&mut app);
11470 assert_eq!(clip.clip(&app).tl_radius_x, 12.0);
11471 assert_eq!(
11472 clip.clip(&app).outer_rect(),
11473 Rect::from_ltwh(0.0, 0.0, 100.0, 100.0)
11474 );
11475 assert!(
11476 picture_has_clip(&mut app, clip.as_object()),
11477 "a superellipse clips with its path"
11478 );
11479 clip.set_border_radius(&mut app, BorderRadiusGeometry::circular(4.0));
11480 assert!(
11481 clip.custom_clip_data(&app).clip.is_none(),
11482 "a new radius marks the clip"
11483 );
11484 }
11485
11486 #[test]
11487 fn a_shape_border_clipper_clips_to_the_shape_and_reclips_when_it_changes() {
11488 let square: ShapeBorderRef =
11489 ShapeBorderRef::new(waft_painting::RoundedRectangleBorder::new(
11490 waft_painting::BorderSide::NONE,
11491 waft_painting::BorderRadiusGeometry::circular(10.0),
11492 ));
11493 let cell = AppCell::new();
11494 let app = cell.borrow();
11495 let clipper = ShapeBorderClipper::new(square.clone(), Some(TextDirection::Ltr));
11496 let clip = clipper.get_clip(&app, Size::new(40.0, 40.0));
11497 assert!(clip.contains(Offset::new(20.0, 20.0)));
11498 assert!(!clip.contains(Offset::new(0.5, 0.5)), "a rounded corner");
11499 let same = ShapeBorderClipper::new(square.clone(), Some(TextDirection::Ltr));
11500 assert!(!clipper.should_reclip(&app, &same));
11501 let other = ShapeBorderClipper::new(square, Some(TextDirection::Rtl));
11502 assert!(clipper.should_reclip(&app, &other));
11503 }
11504
11505 fn shadow_count(app: &mut App, render: AnyRenderObject) -> usize {
11507 count_calls(&painted_ops(app, render), CanvasMethod::DrawShadow)
11508 }
11509
11510 fn physical_model(
11511 app: &mut App,
11512 child: Option<AnyRenderBox>,
11513 clip_behavior: Clip,
11514 ) -> RenderHandle<RenderPhysicalModel> {
11515 RenderPhysicalModel::new(
11516 app,
11517 child,
11518 BoxShape::Rectangle,
11519 clip_behavior,
11520 None,
11521 0.0,
11522 Color::new(0xffff00ff),
11523 Color::new(0xFF000000),
11524 )
11525 }
11526
11527 #[test]
11529 fn a_physical_model_needs_no_compositing_at_any_elevation() {
11530 let cell = AppCell::new();
11531 let mut app = cell.borrow_mut();
11532 let model = physical_model(&mut app, None, Clip::None);
11533 layout_with(
11534 &mut app,
11535 model.as_box(),
11536 None,
11537 AlignmentGeometry::CENTER,
11538 EnginePhase::Paint,
11539 );
11540 assert!(!model.as_object().needs_compositing(&app));
11541
11542 model.set_elevation(&mut app, 1.0);
11543 pump_frame(&mut app, EnginePhase::Paint);
11544 assert!(!model.as_object().needs_compositing(&app));
11545
11546 model.set_elevation(&mut app, 0.0);
11547 pump_frame(&mut app, EnginePhase::Paint);
11548 assert!(!model.as_object().needs_compositing(&app));
11549 }
11550
11551 #[test]
11553 fn a_physical_model_paints_a_shadow_only_at_a_non_zero_elevation() {
11554 let cell = AppCell::new();
11555 let mut app = cell.borrow_mut();
11556 let child = sized_box(&mut app, Size::new(10.0, 10.0));
11557 let model = physical_model(&mut app, Some(child.as_box()), Clip::None);
11558 layout_with(
11559 &mut app,
11560 model.as_box(),
11561 None,
11562 AlignmentGeometry::CENTER,
11563 EnginePhase::Paint,
11564 );
11565 assert_eq!(shadow_count(&mut app, model.as_object()), 0);
11566
11567 model.set_elevation(&mut app, 1.0);
11568 pump_frame(&mut app, EnginePhase::Paint);
11569 assert_eq!(shadow_count(&mut app, model.as_object()), 1);
11570 }
11571
11572 struct TestPathClipper;
11574
11575 impl CustomClipper<Path> for TestPathClipper {
11576 fn get_clip(&self, _app: &App, _size: Size) -> Path {
11577 let mut path = PathBuilder::new();
11578 path.rect(Rect::from_ltwh(50.0, 50.0, 100.0, 100.0).into());
11579 path.build().into()
11580 }
11581
11582 fn should_reclip(&self, _app: &App, _old_clipper: &dyn CustomClipper<Path>) -> bool {
11583 false
11584 }
11585
11586 fn as_any(&self) -> &dyn Any {
11587 self
11588 }
11589 }
11590
11591 fn assert_reuses_its_clip_layer<L: 'static>(app: &mut App, clip: AnyRenderBox) {
11593 assert!(clip.as_object().layer_as::<L>(app).is_none());
11594 layout_with(
11595 app,
11596 clip,
11597 Some(BoxConstraints::tight(Size::new(10.0, 10.0))),
11598 AlignmentGeometry::CENTER,
11599 EnginePhase::Paint,
11600 );
11601 let layer = clip
11602 .as_object()
11603 .layer_as::<L>(app)
11604 .expect("the clip pushes its layer");
11605
11606 clip.as_object().mark_needs_paint(app);
11608 assert!(clip.as_object().debug_needs_paint(app));
11609 pump_frame(app, EnginePhase::Paint);
11610 assert!(!clip.as_object().debug_needs_paint(app));
11611 assert!(clip.as_object().layer_as::<L>(app) == Some(layer));
11612 }
11613
11614 #[test]
11615 fn a_physical_model_reuses_its_layer() {
11616 let cell = AppCell::new();
11617 let mut app = cell.borrow_mut();
11618 let leaf = sized_box(&mut app, Size::new(1.0, 1.0));
11619 let boundary = RenderRepaintBoundary::new(&mut app, Some(leaf.as_box()));
11620 let model = RenderPhysicalModel::new(
11621 &mut app,
11622 Some(boundary.as_box()),
11623 BoxShape::Rectangle,
11624 Clip::HardEdge,
11625 None,
11626 0.0,
11627 Color::from_rgbo(0, 0, 0, 1.0),
11628 Color::new(0xFF000000),
11629 );
11630 assert_reuses_its_clip_layer::<ClipRRectLayer>(&mut app, model.as_box());
11631 }
11632
11633 #[test]
11634 fn a_physical_shape_reuses_its_layer() {
11635 let cell = AppCell::new();
11636 let mut app = cell.borrow_mut();
11637 let leaf = sized_box(&mut app, Size::new(1.0, 1.0));
11638 let boundary = RenderRepaintBoundary::new(&mut app, Some(leaf.as_box()));
11639 let shape = RenderPhysicalShape::new(
11640 &mut app,
11641 Some(boundary.as_box()),
11642 Rc::new(TestPathClipper),
11643 Clip::HardEdge,
11644 0.0,
11645 Color::from_rgbo(0, 0, 0, 1.0),
11646 Color::new(0xFF000000),
11647 );
11648 assert_reuses_its_clip_layer::<ClipPathLayer>(&mut app, shape.as_box());
11649 }
11650
11651 #[test]
11652 fn a_physical_model_fills_its_shape_and_draws_its_shadow_below_it() {
11653 let cell = AppCell::new();
11654 let mut app = cell.borrow_mut();
11655 let child = sized_box(&mut app, Size::new(10.0, 10.0));
11656 let model = RenderPhysicalModel::new(
11657 &mut app,
11658 Some(child.as_box()),
11659 BoxShape::Rectangle,
11660 Clip::None,
11661 Some(BorderRadius::circular(2.0)),
11662 4.0,
11663 BLUE,
11664 Color::new(0xFF000000),
11665 );
11666 let _owner = first_frame_in_view(&mut app, model.as_box(), 3.0);
11667 let ops = painted_ops(&mut app, model.as_object());
11668 let shadow = ops
11669 .iter()
11670 .position(|op| {
11671 matches!(op, Op::DrawShadow { elevation, transparent_occluder, .. }
11672 if *elevation == 4.0 && !*transparent_occluder)
11673 })
11674 .expect("a shadow at elevation 4");
11675 let Op::DrawShadow {
11676 round_rect,
11677 device_pixel_ratio,
11678 ..
11679 } = &ops[shadow]
11680 else {
11681 unreachable!("found as a shadow");
11682 };
11683 assert_eq!(
11684 *round_rect,
11685 Some((
11686 valo::Rect::from(Rect::from_ltwh(0.0, 0.0, 100.0, 100.0)),
11687 2.0
11688 )),
11689 "a rounded rect the shadow fills in closed form"
11690 );
11691 assert_eq!(*device_pixel_ratio, 3.0);
11692 let fill = ops
11693 .iter()
11694 .position(|op| {
11695 matches!(op, Op::DrawPath { paint, .. }
11696 if paint.mask_blur.is_none() && paint.color == BLUE.into())
11697 })
11698 .expect("the rounded fill");
11699 assert!(shadow < fill, "the shadow is drawn under the fill");
11700 }
11701
11702 struct RoundedRectClipper;
11704
11705 impl CustomClipper<Path> for RoundedRectClipper {
11706 fn get_clip(&self, _app: &App, size: Size) -> Path {
11707 let rrect = RRect::from_rect_and_radius(
11708 Rect::from_ltwh(0.0, 0.0, size.width(), size.height()),
11709 waft_embedder::Radius::circular(4.0),
11710 );
11711 let mut path = PathBuilder::new();
11712 path.rrect_radii_elliptical(rrect.outer_rect(), rrect_radii_elliptical(rrect));
11713 path.build().into()
11714 }
11715
11716 fn should_reclip(&self, _app: &App, _old_clipper: &dyn CustomClipper<Path>) -> bool {
11717 false
11718 }
11719
11720 fn as_any(&self) -> &dyn Any {
11721 self
11722 }
11723 }
11724
11725 #[test]
11729 fn a_shifted_rounded_physical_shape_keeps_its_closed_form_shadow() {
11730 let cell = AppCell::new();
11731 let mut app = cell.borrow_mut();
11732 let child = sized_box(&mut app, Size::new(10.0, 10.0));
11733 let shape = RenderPhysicalShape::new(
11734 &mut app,
11735 Some(child.as_box()),
11736 Rc::new(RoundedRectClipper),
11737 Clip::None,
11738 4.0,
11739 BLUE,
11740 Color::new(0xFF000000),
11741 );
11742 let padding = crate::shifted_box::RenderPadding::new(
11743 &mut app,
11744 waft_painting::EdgeInsetsGeometry::all(20.0),
11745 None,
11746 Some(shape.as_box()),
11747 );
11748 layout_with(
11749 &mut app,
11750 padding.as_box(),
11751 Some(BoxConstraints::tight(Size::new(100.0, 100.0))),
11752 AlignmentGeometry::CENTER,
11753 EnginePhase::Paint,
11754 );
11755 let ops = painted_ops(&mut app, padding.as_object());
11756 let round_rect = ops
11757 .iter()
11758 .find_map(|op| match op {
11759 Op::DrawShadow { round_rect, .. } => Some(*round_rect),
11760 _ => None,
11761 })
11762 .expect("a shadow at elevation 4");
11763 assert_eq!(
11764 round_rect,
11765 Some((
11766 valo::Rect::from(Rect::from_ltwh(20.0, 20.0, 60.0, 60.0)),
11767 4.0
11768 )),
11769 "the shifted rounded rect the shadow fills in closed form"
11770 );
11771 }
11772
11773 fn first_frame_in_view(
11776 app: &mut App,
11777 child: AnyRenderBox,
11778 device_pixel_ratio: f64,
11779 ) -> Ref<PipelineOwner> {
11780 let constraints = BoxConstraints::tight(Size::new(100.0, 100.0));
11781 let view = RenderView::new(
11782 app,
11783 Some(child),
11784 Some(ViewConfiguration::new(
11785 constraints * device_pixel_ratio,
11786 constraints,
11787 device_pixel_ratio,
11788 )),
11789 Rc::new(waft_test::TestView::new(100.0, 100.0)),
11790 );
11791 let owner = PipelineOwner::new(app, None, None);
11792 owner.set_root_node(app, Some(view.as_object()));
11793 view.prepare_initial_frame(app);
11794 owner.flush_layout(app);
11795 owner.flush_compositing_bits(app);
11796 owner.flush_paint(app);
11797 owner
11798 }
11799
11800 fn fills_only_with_draw_paint_inside_a_save_layer(ops: &[Op], color: Color) -> bool {
11803 let filled = |paint: &valo::Paint| paint.color == color.into() && paint.mask_blur.is_none();
11804 let save_layer = ops.iter().position(|op| matches!(op, Op::SaveLayer { .. }));
11805 let draw_paint = ops
11806 .iter()
11807 .position(|op| matches!(op, Op::DrawPaint { paint, .. } if filled(paint)));
11808 let other_fill = ops.iter().any(|op| {
11809 matches!(op, Op::DrawPath { paint, .. } | Op::DrawRect { paint, .. } if filled(paint))
11810 });
11811 matches!((save_layer, draw_paint), (Some(layer), Some(paint)) if layer < paint)
11812 && !other_fill
11813 }
11814
11815 #[test]
11816 fn a_physical_model_clipping_with_a_save_layer_fills_with_draw_paint_inside_the_clip() {
11817 let cell = AppCell::new();
11818 let mut app = cell.borrow_mut();
11819 let child = sized_box(&mut app, Size::new(10.0, 10.0));
11820 let model = RenderPhysicalModel::new(
11821 &mut app,
11822 Some(child.as_box()),
11823 BoxShape::Rectangle,
11824 Clip::AntiAliasWithSaveLayer,
11825 Some(BorderRadius::circular(2.0)),
11826 0.0,
11827 BLUE,
11828 Color::new(0xFF000000),
11829 );
11830 layout_with(
11831 &mut app,
11832 model.as_box(),
11833 Some(BoxConstraints::tight(Size::new(100.0, 100.0))),
11834 AlignmentGeometry::CENTER,
11835 EnginePhase::Paint,
11836 );
11837 let ops = painted_ops(&mut app, model.as_object());
11838 assert!(
11839 fills_only_with_draw_paint_inside_a_save_layer(&ops, BLUE),
11840 "{ops:?}"
11841 );
11842 }
11843
11844 #[test]
11845 fn a_physical_shape_clipping_with_a_save_layer_fills_with_draw_paint_inside_the_clip() {
11846 let cell = AppCell::new();
11847 let mut app = cell.borrow_mut();
11848 let child = sized_box(&mut app, Size::new(10.0, 10.0));
11849 let shape = RenderPhysicalShape::new(
11850 &mut app,
11851 Some(child.as_box()),
11852 circle_clipper(),
11853 Clip::AntiAliasWithSaveLayer,
11854 0.0,
11855 BLUE,
11856 Color::new(0xFF000000),
11857 );
11858 layout_with(
11859 &mut app,
11860 shape.as_box(),
11861 Some(BoxConstraints::tight(Size::new(100.0, 100.0))),
11862 AlignmentGeometry::CENTER,
11863 EnginePhase::Paint,
11864 );
11865 let ops = painted_ops(&mut app, shape.as_object());
11866 assert!(
11867 fills_only_with_draw_paint_inside_a_save_layer(&ops, BLUE),
11868 "{ops:?}"
11869 );
11870 }
11871
11872 fn circle_clipper() -> Rc<dyn CustomClipper<Path>> {
11873 Rc::new(ShapeBorderClipper::new(
11874 ShapeBorderRef::new(waft_painting::CircleBorder::new(
11875 waft_painting::BorderSide::NONE,
11876 0.0,
11877 )),
11878 None,
11879 ))
11880 }
11881
11882 fn physical_shape(app: &mut App) -> RenderHandle<RenderPhysicalShape> {
11883 RenderPhysicalShape::new(
11884 app,
11885 None,
11886 circle_clipper(),
11887 Clip::None,
11888 0.0,
11889 Color::new(0xffff00ff),
11890 Color::new(0xFF000000),
11891 )
11892 }
11893
11894 #[test]
11896 fn a_physical_shape_repaints_only_for_a_different_shape() {
11897 let cell = AppCell::new();
11898 let mut app = cell.borrow_mut();
11899 let shape = physical_shape(&mut app);
11900 layout_with(
11901 &mut app,
11902 shape.as_box(),
11903 None,
11904 AlignmentGeometry::CENTER,
11905 EnginePhase::Paint,
11906 );
11907 assert!(!shape.as_object().debug_needs_paint(&app));
11908
11909 shape.set_clipper(&mut app, Some(circle_clipper()));
11911 assert!(!shape.as_object().debug_needs_paint(&app));
11912
11913 shape.set_clipper(
11915 &mut app,
11916 Some(Rc::new(ShapeBorderClipper::new(
11917 ShapeBorderRef::new(waft_painting::StadiumBorder::default()),
11918 None,
11919 ))),
11920 );
11921 assert!(shape.as_object().debug_needs_paint(&app));
11922 }
11923
11924 #[test]
11926 fn a_physical_shape_needs_no_compositing_at_any_elevation() {
11927 let cell = AppCell::new();
11928 let mut app = cell.borrow_mut();
11929 let shape = physical_shape(&mut app);
11930 layout_with(
11931 &mut app,
11932 shape.as_box(),
11933 None,
11934 AlignmentGeometry::CENTER,
11935 EnginePhase::Paint,
11936 );
11937 assert!(!shape.as_object().needs_compositing(&app));
11938 shape.set_elevation(&mut app, 1.0);
11939 pump_frame(&mut app, EnginePhase::Paint);
11940 assert!(!shape.as_object().needs_compositing(&app));
11941 shape.set_elevation(&mut app, 0.0);
11942 pump_frame(&mut app, EnginePhase::Paint);
11943 assert!(!shape.as_object().needs_compositing(&app));
11944 }
11945
11946 struct EveryHitBox {
11949 render_object: RenderObjectData,
11950 render_box: RenderBoxData,
11951 }
11952
11953 impl RenderObject for EveryHitBox {
11954 crate::render_object_accessors!();
11955
11956 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
11957 let size = self.constraints(app).biggest();
11958 self.set_size(app, size);
11959 }
11960 }
11961
11962 impl RenderBox for EveryHitBox {
11963 crate::render_box_accessors!();
11964
11965 fn hit_test(
11966 self: RenderHandle<Self>,
11967 _app: &mut App,
11968 result: &mut BoxHitTestResult<'_>,
11969 position: Offset,
11970 ) -> bool {
11971 result.add(BoxHitTestEntry::new(self.as_box(), position).into());
11972 true
11973 }
11974 }
11975
11976 use crate::semantics::AttributedString;
11977
11978 fn semantics_annotations(
11979 app: &mut App,
11980 properties: SemanticsProperties,
11981 child: Option<AnyRenderBox>,
11982 ) -> RenderHandle<RenderSemanticsAnnotations> {
11983 RenderSemanticsAnnotations::new(
11984 app,
11985 Rc::new(properties),
11986 false,
11987 false,
11988 false,
11989 false,
11990 None,
11991 None,
11992 child,
11993 )
11994 }
11995
11996 #[test]
11997 fn semantics_annotations_bound_the_hit_test_of_a_child_that_takes_hits_outside_itself() {
11998 let cell = AppCell::new();
11999 let mut app = cell.borrow_mut();
12000 let child = RenderHandle::new_box(
12001 &mut app,
12002 EveryHitBox {
12003 render_object: RenderObjectData::new(),
12004 render_box: RenderBoxData::new(),
12005 },
12006 );
12007 let semantics =
12008 semantics_annotations(&mut app, SemanticsProperties::new(), Some(child.as_box()));
12009 semantics.layout(
12010 &mut app,
12011 BoxConstraints::tight(Size::new(50.0, 50.0)),
12012 false,
12013 );
12014
12015 assert_eq!(
12016 hit_test(&mut app, child.as_box(), Offset::new(75.0, 75.0)),
12017 (true, 1),
12018 "the child alone takes a hit outside itself"
12019 );
12020 assert_eq!(
12021 hit_test(&mut app, semantics.as_box(), Offset::new(75.0, 75.0)),
12022 (false, 0)
12023 );
12024 assert_eq!(
12025 hit_test(&mut app, semantics.as_box(), Offset::new(25.0, 25.0)),
12026 (true, 2),
12027 "the child and the annotations"
12028 );
12029 }
12030
12031 struct NoBaselineBox {
12033 render_object: RenderObjectData,
12034 render_box: RenderBoxData,
12035 }
12036
12037 impl RenderObject for NoBaselineBox {
12038 crate::render_object_accessors!();
12039
12040 fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
12041 let size = self.constraints(app).constrain(Size::new(40.0, 20.0));
12042 self.set_size(app, size);
12043 }
12044 }
12045
12046 impl RenderBox for NoBaselineBox {
12047 crate::render_box_accessors!();
12048
12049 fn compute_dry_layout(
12050 self: RenderHandle<Self>,
12051 _app: &mut App,
12052 constraints: BoxConstraints,
12053 ) -> Size {
12054 constraints.constrain(Size::new(40.0, 20.0))
12055 }
12056
12057 fn compute_dry_baseline(
12058 self: RenderHandle<Self>,
12059 _app: &mut App,
12060 _constraints: BoxConstraints,
12061 _baseline: TextBaseline,
12062 ) -> Option<f64> {
12063 None
12064 }
12065 }
12066
12067 #[test]
12069 fn a_proxy_box_dry_baseline_is_none_when_the_child_has_no_baseline() {
12070 let cell = AppCell::new();
12071 let mut app = cell.borrow_mut();
12072 let child = RenderHandle::new_box(
12073 &mut app,
12074 NoBaselineBox {
12075 render_object: RenderObjectData::new(),
12076 render_box: RenderBoxData::new(),
12077 },
12078 );
12079 let proxy =
12080 semantics_annotations(&mut app, SemanticsProperties::new(), Some(child.as_box()));
12081 proxy.layout(&mut app, BoxConstraints::new(), false);
12082 assert_eq!(
12083 proxy.as_box().get_dry_baseline(
12084 &mut app,
12085 BoxConstraints::tight_for(Some(40.0), Some(20.0)),
12086 TextBaseline::Alphabetic,
12087 ),
12088 None
12089 );
12090 }
12091
12092 #[test]
12093 fn semantics_annotations_keep_what_they_are_given() {
12094 let cell = AppCell::new();
12095 let mut app = cell.borrow_mut();
12096 let properties = Rc::new(SemanticsProperties::new().label("label").hint("hint"));
12097 let semantics = RenderSemanticsAnnotations::new(
12098 &mut app,
12099 properties.clone(),
12100 true,
12101 false,
12102 false,
12103 true,
12104 Some(Locale::new("es")),
12105 Some(TextDirection::Rtl),
12106 None,
12107 );
12108 assert!(Rc::ptr_eq(&semantics.properties(&app), &properties));
12109 assert!(semantics.container(&app));
12110 assert!(!semantics.explicit_child_nodes(&app));
12111 assert!(!semantics.exclude_semantics(&app));
12112 assert!(semantics.block_user_actions(&app));
12113 assert_eq!(semantics.locale_for_subtree(&app), Some(Locale::new("es")));
12114 assert_eq!(semantics.text_direction(&app), Some(TextDirection::Rtl));
12115 assert_eq!(
12116 semantics.attributed_label(&app),
12117 Some(AttributedString::new("label"))
12118 );
12119 assert_eq!(
12120 semantics.attributed_hint(&app),
12121 Some(AttributedString::new("hint"))
12122 );
12123 assert_eq!(semantics.attributed_value(&app), None);
12124
12125 let attributed_value = AttributedString::new("value");
12126 semantics.set_properties(
12127 &mut app,
12128 Rc::new(
12129 SemanticsProperties::new()
12130 .attributed_value(attributed_value.clone())
12131 .decreased_value("less"),
12132 ),
12133 );
12134 assert_eq!(semantics.attributed_label(&app), None);
12135 assert_eq!(semantics.attributed_value(&app), Some(attributed_value));
12136 assert_eq!(
12137 semantics.attributed_decreased_value(&app),
12138 Some(AttributedString::new("less"))
12139 );
12140
12141 semantics.set_container(&mut app, false);
12142 semantics.set_explicit_child_nodes(&mut app, true);
12143 semantics.set_exclude_semantics(&mut app, true);
12144 semantics.set_block_user_actions(&mut app, false);
12145 semantics.set_locale_for_subtree(&mut app, None);
12146 semantics.set_text_direction(&mut app, None);
12147 assert!(!semantics.container(&app));
12148 assert!(semantics.explicit_child_nodes(&app));
12149 assert!(semantics.exclude_semantics(&app));
12150 assert!(!semantics.block_user_actions(&app));
12151 assert_eq!(semantics.locale_for_subtree(&app), None);
12152 assert_eq!(semantics.text_direction(&app), None);
12153 }
12154
12155 #[test]
12156 fn the_block_exclude_and_indexed_semantics_boxes_keep_their_values() {
12157 let cell = AppCell::new();
12158 let mut app = cell.borrow_mut();
12159 let block = RenderBlockSemantics::new(&mut app, true, None);
12160 block.set_blocking(&mut app, false);
12161 assert!(!block.blocking(&app));
12162 let exclude = RenderExcludeSemantics::new(&mut app, true, None);
12163 exclude.set_excluding(&mut app, false);
12164 assert!(!exclude.excluding(&app));
12165 let indexed = RenderIndexedSemantics::new(&mut app, 3, None);
12166 assert_eq!(indexed.index(&app), 3);
12167 indexed.set_index(&mut app, 4);
12168 assert_eq!(indexed.index(&app), 4);
12169 let merge = RenderMergeSemantics::new(&mut app, None);
12170 merge.layout(
12171 &mut app,
12172 BoxConstraints::tight(Size::new(10.0, 10.0)),
12173 false,
12174 );
12175 assert_eq!(merge.size(&app), Size::new(10.0, 10.0));
12176 }
12177}