1use core::cell::Cell;
4use core::time::Duration;
5
6use crate::arena::StrRef;
7use crate::paint::{
8 BackdropFilter, BlendMode, ColorMatrix, ColorStop, CornerRadii, DropShadow, ExtendMode,
9 GradientSpace, LayerFilter, Paint, PaintEffects, Transform2D,
10};
11use crate::pod::{ActionScope, CursorShape, DragEvent, FrameScope};
12use crate::style::{AlignItems, Color, Easing, Edges, LoopMode, Style, StyleRefinement, Styled};
13
14use super::div_node::{
15 duration_to_ms, pack_visual_flags, DivExtPtr, DivExtended, DivInteractivity, DivNode,
16 DivRareHandlers, DivStateStyles, DivVisual, EnterFrom, TransitionSpec, FOCUS_BORDER_NONE,
17 NO_FOCUS_BORDER_DIV_VISUAL,
18};
19use super::{Element, ElementNode, IntoElement};
20
21impl<'a> IntoElement<'a> for Div<'a> {
22 #[inline(always)]
23 fn into_element(mut self, cx: &'a FrameScope) -> Element<'a> {
24 let has_state_styles = self.text_color.is_some()
25 || self.text_size.is_some()
26 || self.hover_style.is_some()
27 || self.active_style.is_some()
28 || self.focus_style.is_some();
29 let has_effects = !self.effects.is_empty()
30 || self.external_texture.is_some()
31 || !self.layout_ext.is_empty();
32
33 let alloc_visual = |extended: DivExtPtr<'a>,
34 transition: Option<&'a TransitionSpec>|
35 -> &'a DivVisual<'a> {
36 let (pos_x, pos_y) = self.pos.unwrap_or((0, 0));
37 let (bg_grad_to, bg_grad_horiz) = self.bg_grad.unwrap_or((Color::TRANSPARENT, false));
38 let (focus_border_w, focus_border_color) = match self.focus_border {
39 Some((w, c)) => (w.min(254), c),
40 None => (FOCUS_BORDER_NONE, Color::TRANSPARENT),
41 };
42 let (shadow_blur, shadow_ox, shadow_oy, shadow_color) =
43 self.shadow.unwrap_or((0, 0, 0, Color::TRANSPARENT));
44 let extra_flags = pack_visual_flags(
45 self.pos.is_some(),
46 self.scrollable_max.is_some(),
47 self.bg_grad.is_some(),
48 bg_grad_horiz,
49 self.items_baseline,
50 self.align_self,
51 );
52 &*cx.arena().alloc_temp(DivVisual {
53 extended,
54 transition,
55 margin: self.margin,
56 extra_padding: self.extra_padding,
57 bg_grad_to,
58 focus_border_color,
59 shadow_color,
60 min_w: self.min_w,
61 max_w: self.max_w,
62 min_h: self.min_h,
63 max_h: self.max_h,
64 pos_x,
65 pos_y,
66 raw_scrollable_max: self.scrollable_max.unwrap_or(0),
67 extra_flags,
68 focus_border_w,
69 shadow_blur,
70 shadow_ox,
71 shadow_oy,
72 cursor: self.cursor,
73 })
74 };
75
76 let visual = if self.has_non_focus_visual_extra() {
77 let state_styles = if has_state_styles {
78 let hover_style = self.hover_style.map(|r| &*cx.arena().alloc_temp(r));
79 let active_style = self.active_style.map(|r| &*cx.arena().alloc_temp(r));
80 let focus_style = self.focus_style.map(|r| &*cx.arena().alloc_temp(r));
81 Some(&*cx.arena().alloc_temp(DivStateStyles {
82 hover_style,
83 active_style,
84 focus_style,
85 text_color: self.text_color.unwrap_or(Color::TRANSPARENT),
86 text_size: self.text_size.unwrap_or(0),
87 flags: if self.text_color.is_some() { 1 } else { 0 },
88 }))
89 } else {
90 None
91 };
92 let effects = if has_effects {
93 if let Some(ext_spec) = self.external_texture {
94 self.effects.external_texture = Some(&*cx.arena().alloc_temp(ext_spec));
95 }
96 if !self.layout_ext.is_empty() {
97 self.effects.layout_ext = Some(&*cx.arena().alloc_temp(self.layout_ext));
98 }
99 Some(&*cx.arena().alloc_temp(self.effects))
100 } else {
101 None
102 };
103 let extended = match (state_styles, effects) {
104 (None, None) => DivExtPtr::NONE,
105 (Some(s), None) => DivExtPtr::from_state_styles(s),
106 (None, Some(e)) => DivExtPtr::from_effects(e),
107 (Some(s), Some(e)) => DivExtPtr::from_both(&*cx.arena().alloc_temp(DivExtended {
108 state_styles: Some(s),
109 effects: Some(e),
110 })),
111 };
112 let transition = self.transition.map(|t| &*cx.arena().alloc_temp(t));
113 Some(alloc_visual(extended, transition))
114 } else if let Some((fw, fc)) = self.focus_border {
115 if fw == 0 && fc == Color::TRANSPARENT {
116 Some(&NO_FOCUS_BORDER_DIV_VISUAL)
117 } else {
118 Some(alloc_visual(DivExtPtr::NONE, None))
119 }
120 } else {
121 None
122 };
123
124 let interact = if self.has_interactivity() {
125 let rare = if self.has_rare_handlers() {
126 Some(&*cx.arena().alloc(DivRareHandlers {
127 on_long_press: self.on_long_press,
128 on_drag: self.on_drag,
129 on_hover: self.on_hover,
130 on_pointer_move: self.on_pointer_move,
131 on_wheel: self.on_wheel,
132 on_pinch: self.on_pinch,
133 on_swipe: self.on_swipe,
134 on_key_input: self.on_key_input,
135 on_key_nav: self.on_key_nav,
136 on_navigate_back: self.on_navigate_back,
137 on_secondary_click: self.on_secondary_click,
138 }))
139 } else {
140 None
141 };
142 Some(&*cx.arena().alloc(DivInteractivity {
143 on_click: self.on_click,
144 rare,
145 }))
146 } else {
147 None
148 };
149
150 let mut flags = 0u8;
151 if self.focusable {
152 flags |= 1 << 0;
153 }
154 if self.is_overlay {
155 flags |= 1 << 1;
156 }
157 if self.occlude_hit {
158 flags |= 1 << 2;
159 }
160 if self.auto_repeat {
161 flags |= 1 << 3;
162 }
163 if self.clip_children {
164 flags |= 1 << 4;
165 }
166 if self.id.is_some() {
167 flags |= 1 << 5;
168 }
169 if self.active_bg.is_some() {
170 flags |= 1 << 6;
171 }
172 if self.hover_bg.is_some() {
173 flags |= 1 << 7;
174 }
175
176 Element::Div(DivNode {
177 style: self.style,
178 first_child: self.first_child,
179 visual,
180 interact,
181 raw_id: self.id.unwrap_or(0),
182 raw_active_bg: self.active_bg.unwrap_or(Color::TRANSPARENT),
183 raw_hover_bg: self.hover_bg.unwrap_or(Color::TRANSPARENT),
184 opacity: self.opacity,
185 z_index: self.z_index,
186 grid_cols: self.grid_cols,
187 flags,
188 })
189 }
190}
191
192
193pub struct Div<'a> {
195 pub id: Option<u32>,
197 pub style: Style,
199 pub margin: Edges<i16>,
201 pub extra_padding: Edges<i16>,
203 pub min_w: i16,
205 pub max_w: i16,
207 pub min_h: i16,
209 pub max_h: i16,
211 pub opacity: u8,
213 pub active_bg: Option<Color>,
215 pub hover_bg: Option<Color>,
217 pub bg_grad: Option<(Color, bool)>,
219 pub focus_border: Option<(u8, Color)>,
221 pub focusable: bool,
223 pub is_overlay: bool,
225 pub occlude_hit: bool,
227 pub auto_repeat: bool,
229 pub scrollable_max: Option<i16>,
231 pub pos: Option<(i16, i16)>,
233 pub first_child: Option<&'a ElementNode<'a>>,
235 pub last_child: Option<&'a ElementNode<'a>>,
237 pub on_click: Option<&'a dyn Fn(&mut ActionScope)>,
239 pub on_long_press: Option<&'a dyn Fn(&mut ActionScope)>,
241 pub on_drag: Option<&'a dyn Fn(&mut ActionScope)>,
243 pub on_hover: Option<&'a dyn Fn(bool, &mut ActionScope)>,
245 pub on_pointer_move: Option<&'a dyn Fn(&mut ActionScope)>,
247 pub on_wheel: Option<&'a dyn Fn(crate::pod::WheelEvent, &mut ActionScope)>,
249 pub on_pinch: Option<&'a dyn Fn(crate::pod::PinchEvent, &mut ActionScope)>,
251 pub on_swipe: Option<&'a dyn Fn(crate::pod::SwipeDir, &mut ActionScope)>,
253 pub on_key_input: Option<&'a dyn Fn(crate::pod::KeyCode, &mut ActionScope)>,
255 pub on_key_nav: Option<&'a dyn Fn(crate::pod::KeyCode, &mut ActionScope)>,
257 pub on_navigate_back: Option<&'a dyn Fn(&mut ActionScope)>,
259 pub on_secondary_click: Option<&'a dyn Fn(&mut ActionScope)>,
261 pub z_index: i8,
263 pub shadow: Option<(u8, i8, i8, Color)>,
265 pub grid_cols: u8,
267 pub transition: Option<TransitionSpec>,
269 pub clip_children: bool,
271 pub align_self: Option<AlignItems>,
273 pub cursor: Option<CursorShape>,
275 pub text_color: Option<Color>,
277 pub text_size: Option<u8>,
279 pub hover_style: Option<StyleRefinement>,
281 pub active_style: Option<StyleRefinement>,
283 pub focus_style: Option<StyleRefinement>,
285 pub items_baseline: bool,
287 pub effects: PaintEffects<'a>,
289 pub external_texture: Option<crate::paint::ExternalTextureSpec>,
291 pub layout_ext: crate::paint::LayoutExtras<'a>,
293}
294
295#[inline(always)]
297pub fn div<'a>() -> Div<'a> {
298 Div {
299 id: None,
300 style: Style::default(),
301 margin: Edges::all(0),
302 extra_padding: Edges::all(0),
303 min_w: 0,
304 max_w: 0,
305 min_h: 0,
306 max_h: 0,
307 opacity: 255,
308 active_bg: None,
309 hover_bg: None,
310 bg_grad: None,
311 focus_border: None,
312 focusable: false,
313 is_overlay: false,
314 occlude_hit: false,
315 auto_repeat: false,
316 scrollable_max: None,
317 pos: None,
318 first_child: None,
319 last_child: None,
320 on_click: None,
321 on_long_press: None,
322 on_drag: None,
323 on_hover: None,
324 on_pointer_move: None,
325 on_wheel: None,
326 on_pinch: None,
327 on_swipe: None,
328 on_key_input: None,
329 on_key_nav: None,
330 on_navigate_back: None,
331 on_secondary_click: None,
332 z_index: 0,
333 shadow: None,
334 grid_cols: 0,
335 transition: None,
336 clip_children: false,
337 align_self: None,
338 cursor: None,
339 text_color: None,
340 text_size: None,
341 hover_style: None,
342 active_style: None,
343 focus_style: None,
344 items_baseline: false,
345 effects: PaintEffects::EMPTY,
346 external_texture: None,
347 layout_ext: crate::paint::LayoutExtras::EMPTY,
348 }
349}
350
351impl<'a> Styled for Div<'a> {
352 #[inline(always)]
353 fn style_mut(&mut self) -> &mut Style {
354 &mut self.style
355 }
356}
357
358impl<'a> Div<'a> {
359 #[inline(always)]
360 fn has_non_focus_visual_extra(&self) -> bool {
361 self.margin != Edges::all(0)
362 || self.extra_padding != Edges::all(0)
363 || self.min_w != 0
364 || self.max_w != 0
365 || self.min_h != 0
366 || self.max_h != 0
367 || self.bg_grad.is_some()
368 || self.scrollable_max.is_some()
369 || self.pos.is_some()
370 || self.shadow.is_some()
371 || self.transition.is_some()
372 || self.align_self.is_some()
373 || self.cursor.is_some()
374 || self.text_color.is_some()
375 || self.text_size.is_some()
376 || self.hover_style.is_some()
377 || self.active_style.is_some()
378 || self.focus_style.is_some()
379 || self.items_baseline
380 || !self.effects.is_empty()
381 || self.external_texture.is_some()
382 || !self.layout_ext.is_empty()
383 }
384
385 #[inline(always)]
386 fn has_interactivity(&self) -> bool {
387 self.on_click.is_some() || self.has_rare_handlers()
388 }
389
390 #[inline(always)]
391 fn has_rare_handlers(&self) -> bool {
392 self.on_long_press.is_some()
393 || self.on_drag.is_some()
394 || self.on_hover.is_some()
395 || self.on_pointer_move.is_some()
396 || self.on_wheel.is_some()
397 || self.on_pinch.is_some()
398 || self.on_swipe.is_some()
399 || self.on_key_input.is_some()
400 || self.on_key_nav.is_some()
401 || self.on_navigate_back.is_some()
402 || self.on_secondary_click.is_some()
403 }
404
405 #[inline(always)]
407 pub fn id(mut self, id: u32) -> Self {
408 self.id = Some(id);
409 self
410 }
411
412 #[inline(always)]
414 pub fn scoped_id(mut self, cx: &FrameScope, local_id: u32) -> Self {
415 self.id = Some(cx.scoped_id(local_id));
416 self
417 }
418
419 #[inline(always)]
421 pub fn pos(mut self, x: i16, y: i16) -> Self {
422 self.pos = Some((x, y));
423 self
424 }
425
426 #[inline(always)]
428 pub fn safe_area(mut self, cx: &FrameScope) -> Self {
429 let sa = cx.safe_area();
430 let kb = cx.keyboard_inset();
431 self.extra_padding.top = self.extra_padding.top.saturating_add(sa.top.max(0));
432 self.extra_padding.right = self.extra_padding.right.saturating_add(sa.right.max(0));
433 self.extra_padding.bottom = self
434 .extra_padding
435 .bottom
436 .saturating_add(sa.bottom.saturating_add(kb).max(0));
437 self.extra_padding.left = self.extra_padding.left.saturating_add(sa.left.max(0));
438 self
439 }
440
441 #[inline(always)]
443 pub fn pt_safe(mut self, cx: &FrameScope) -> Self {
444 let sa = cx.safe_area();
445 self.extra_padding.top = self.extra_padding.top.saturating_add(sa.top.max(0));
446 self
447 }
448
449 #[inline(always)]
451 pub fn pb_safe(mut self, cx: &FrameScope) -> Self {
452 let sa = cx.safe_area();
453 let kb = cx.keyboard_inset();
454 self.extra_padding.bottom = self
455 .extra_padding
456 .bottom
457 .saturating_add(sa.bottom.saturating_add(kb).max(0));
458 self
459 }
460
461 #[inline(always)]
463 pub fn mx(mut self, px: i16) -> Self {
464 self.margin.left = px;
465 self.margin.right = px;
466 self
467 }
468
469 #[inline(always)]
471 pub fn my(mut self, px: i16) -> Self {
472 self.margin.top = px;
473 self.margin.bottom = px;
474 self
475 }
476
477 #[inline(always)]
479 pub fn mt(mut self, px: i16) -> Self {
480 self.margin.top = px;
481 self
482 }
483
484 #[inline(always)]
486 pub fn mb(mut self, px: i16) -> Self {
487 self.margin.bottom = px;
488 self
489 }
490
491 #[inline(always)]
493 pub fn ml(mut self, px: i16) -> Self {
494 self.margin.left = px;
495 self
496 }
497
498 #[inline(always)]
500 pub fn mr(mut self, px: i16) -> Self {
501 self.margin.right = px;
502 self
503 }
504
505 #[inline(always)]
507 pub fn min_w(mut self, px: i16) -> Self {
508 self.min_w = px.max(0);
509 self
510 }
511
512 #[inline(always)]
514 pub fn max_w(mut self, px: i16) -> Self {
515 self.max_w = px.max(0);
516 self
517 }
518
519 #[inline(always)]
521 pub fn min_h(mut self, px: i16) -> Self {
522 self.min_h = px.max(0);
523 self
524 }
525
526 #[inline(always)]
528 pub fn max_h(mut self, px: i16) -> Self {
529 self.max_h = px.max(0);
530 self
531 }
532
533 #[inline(always)]
535 pub fn opacity(mut self, alpha: u8) -> Self {
536 self.opacity = alpha;
537 self
538 }
539
540 #[inline(always)]
542 pub fn active_bg(mut self, color: Color) -> Self {
543 self.active_bg = Some(color);
544 self
545 }
546
547 #[inline(always)]
549 pub fn hover_bg(mut self, color: Color) -> Self {
550 self.hover_bg = Some(color);
551 self
552 }
553
554 #[inline(always)]
558 pub fn hover(mut self, f: impl FnOnce(StyleRefinement) -> StyleRefinement) -> Self {
559 let base = self.hover_style.unwrap_or_else(|| {
560 let mut r = StyleRefinement::new();
561 r.bg = self.hover_bg;
562 r
563 });
564 let refined = f(base);
565 if refined.is_empty() {
566 return self;
567 }
568 if refined.is_bg_only() {
569 self.hover_bg = refined.bg;
570 self.hover_style = None;
571 } else {
572 if let Some(bg) = refined.bg {
573 self.hover_bg = Some(bg);
574 }
575 self.hover_style = Some(refined);
576 }
577 self
578 }
579
580 #[inline(always)]
582 pub fn active(mut self, f: impl FnOnce(StyleRefinement) -> StyleRefinement) -> Self {
583 let base = self.active_style.unwrap_or_else(|| {
584 let mut r = StyleRefinement::new();
585 r.bg = self.active_bg;
586 r
587 });
588 let refined = f(base);
589 if refined.is_empty() {
590 return self;
591 }
592 if refined.is_bg_only() {
593 self.active_bg = refined.bg;
594 self.active_style = None;
595 } else {
596 if let Some(bg) = refined.bg {
597 self.active_bg = Some(bg);
598 }
599 self.active_style = Some(refined);
600 }
601 self
602 }
603
604 #[inline(always)]
606 pub fn focus(mut self, f: impl FnOnce(StyleRefinement) -> StyleRefinement) -> Self {
607 self.focusable = true;
608 let refined = f(self.focus_style.unwrap_or_default());
609 if !refined.is_empty() {
610 self.focus_style = Some(refined);
611 }
612 self
613 }
614
615 #[inline(always)]
617 pub fn text_color(mut self, color: Color) -> Self {
618 self.text_color = Some(color);
619 self
620 }
621
622 #[inline(always)]
624 pub fn text_size(mut self, px: u8) -> Self {
625 self.text_size = Some(px);
626 self
627 }
628
629 #[inline(always)] pub fn text_xs(self) -> Self { self.text_size(11) }
631 #[inline(always)] pub fn text_sm(self) -> Self { self.text_size(12) }
632 #[inline(always)] pub fn text_base(self) -> Self { self.text_size(14) }
633 #[inline(always)] pub fn text_lg(self) -> Self { self.text_size(16) }
634 #[inline(always)] pub fn text_xl(self) -> Self { self.text_size(18) }
635 #[inline(always)] pub fn text_2xl(self) -> Self { self.text_size(22) }
636 #[inline(always)] pub fn text_3xl(self) -> Self { self.text_size(28) }
637
638 #[inline(always)]
640 pub fn opacity_f(mut self, alpha: f32) -> Self {
641 let c = if alpha <= 0.0 {
642 0.0
643 } else if alpha >= 1.0 {
644 1.0
645 } else {
646 alpha
647 };
648 self.opacity = (c * 255.0 + 0.5) as u8;
649 self
650 }
651
652 #[inline(always)] pub fn mx_0(self) -> Self { self.mx(0) }
654 #[inline(always)] pub fn mx_1(self) -> Self { self.mx(4) }
655 #[inline(always)] pub fn mx_2(self) -> Self { self.mx(8) }
656 #[inline(always)] pub fn mx_3(self) -> Self { self.mx(12) }
657 #[inline(always)] pub fn mx_4(self) -> Self { self.mx(16) }
658 #[inline(always)] pub fn my_0(self) -> Self { self.my(0) }
659 #[inline(always)] pub fn my_1(self) -> Self { self.my(4) }
660 #[inline(always)] pub fn my_2(self) -> Self { self.my(8) }
661 #[inline(always)] pub fn my_3(self) -> Self { self.my(12) }
662 #[inline(always)] pub fn my_4(self) -> Self { self.my(16) }
663 #[inline(always)] pub fn mt_1(self) -> Self { self.mt(4) }
664 #[inline(always)] pub fn mt_2(self) -> Self { self.mt(8) }
665 #[inline(always)] pub fn mt_3(self) -> Self { self.mt(12) }
666 #[inline(always)] pub fn mt_4(self) -> Self { self.mt(16) }
667 #[inline(always)] pub fn mb_1(self) -> Self { self.mb(4) }
668 #[inline(always)] pub fn mb_2(self) -> Self { self.mb(8) }
669 #[inline(always)] pub fn mb_3(self) -> Self { self.mb(12) }
670 #[inline(always)] pub fn mb_4(self) -> Self { self.mb(16) }
671 #[inline(always)] pub fn ml_1(self) -> Self { self.ml(4) }
672 #[inline(always)] pub fn ml_2(self) -> Self { self.ml(8) }
673 #[inline(always)] pub fn ml_3(self) -> Self { self.ml(12) }
674 #[inline(always)] pub fn ml_4(self) -> Self { self.ml(16) }
675 #[inline(always)] pub fn mr_1(self) -> Self { self.mr(4) }
676 #[inline(always)] pub fn mr_2(self) -> Self { self.mr(8) }
677 #[inline(always)] pub fn mr_3(self) -> Self { self.mr(12) }
678 #[inline(always)] pub fn mr_4(self) -> Self { self.mr(16) }
679
680 #[inline(always)] pub fn relative(self) -> Self { self }
683 #[inline(always)] pub fn block(self) -> Self { self.flex_col() }
685 #[inline(always)] pub fn inline_flex(self) -> Self { self.flex_row() }
687
688 #[inline(always)] pub fn cursor_pointer(self) -> Self { self.cursor(CursorShape::Pointer) }
689 #[inline(always)] pub fn cursor_default(self) -> Self { self.cursor(CursorShape::Default) }
690 #[inline(always)] pub fn cursor_text(self) -> Self { self.cursor(CursorShape::Text) }
691 #[inline(always)] pub fn cursor_not_allowed(self) -> Self { self.cursor(CursorShape::NotAllowed) }
692 #[inline(always)] pub fn cursor_grab(self) -> Self { self.cursor(CursorShape::Grab) }
693 #[inline(always)] pub fn cursor_grabbing(self) -> Self { self.cursor(CursorShape::Grabbing) }
694
695 #[inline(always)] pub fn shadow_none(mut self) -> Self { self.shadow = None; self }
696 #[inline(always)] pub fn shadow_sm(self) -> Self { self.shadow(4, 0, 1, Color::rgba(0, 0, 0, 48)) }
697 #[inline(always)] pub fn shadow_md(self) -> Self { self.shadow(10, 0, 3, Color::rgba(0, 0, 0, 72)) }
698 #[inline(always)] pub fn shadow_lg(self) -> Self { self.shadow(18, 0, 6, Color::rgba(0, 0, 0, 96)) }
699 #[inline(always)] pub fn shadow_xl(self) -> Self { self.shadow(28, 0, 10, Color::rgba(0, 0, 0, 120)) }
700
701 #[inline(always)]
703 pub fn bg_gradient(mut self, to_color: Color) -> Self {
704 self.bg_grad = Some((to_color, false));
705 self
706 }
707
708 #[inline(always)]
710 pub fn bg_gradient_x(mut self, to_color: Color) -> Self {
711 self.bg_grad = Some((to_color, true));
712 self
713 }
714
715 #[inline(always)]
717 pub fn overlay(mut self) -> Self {
718 self.is_overlay = true;
719 self
720 }
721
722 #[inline(always)]
724 pub fn occlude_hit(mut self) -> Self {
725 self.occlude_hit = true;
726 self
727 }
728
729 #[inline(always)]
731 pub fn auto_repeat(mut self) -> Self {
732 self.auto_repeat = true;
733 self
734 }
735
736 #[inline(always)]
738 pub fn on_long_press_raw(mut self, handler: &'a dyn Fn(&mut ActionScope)) -> Self {
739 self.on_long_press = Some(handler);
740 self.focusable = true;
741 self
742 }
743
744 #[inline(always)]
746 pub fn on_long_press(
747 mut self,
748 cx: &'a FrameScope,
749 handler: &'a dyn Fn(crate::pod::ClickEvent, &mut ActionScope),
750 ) -> Self {
751 let wrapped = cx.arena().alloc(move |acx: &mut ActionScope| {
752 let (x, y) = acx.click_position();
753 handler(crate::pod::ClickEvent { x, y }, acx);
754 });
755 self.on_long_press = Some(wrapped);
756 self.focusable = true;
757 self
758 }
759
760 #[inline(always)]
762 pub fn focus_border(mut self, width: u8, color: Color) -> Self {
763 self.focus_border = Some((width, color));
764 self.focusable = true;
765 self
766 }
767
768 #[inline(always)]
770 pub fn no_focus_border(mut self) -> Self {
771 self.focus_border = Some((0, Color::TRANSPARENT));
772 self
773 }
774
775 #[inline(always)]
777 pub fn cursor(mut self, cursor: CursorShape) -> Self {
778 self.cursor = Some(cursor);
779 self
780 }
781
782 #[inline(always)]
784 pub fn focusable(mut self) -> Self {
785 self.focusable = true;
786 self
787 }
788
789 #[inline(always)]
791 pub fn unfocusable(mut self) -> Self {
792 self.focusable = false;
793 self
794 }
795
796 #[inline(always)]
798 pub fn scrollable(mut self, max_scroll: i16) -> Self {
799 self.scrollable_max = Some(max_scroll.max(0));
800 self.clip_children = true;
801 self
802 }
803
804 #[inline(always)]
806 pub fn scrollable_auto(mut self) -> Self {
807 self.scrollable_max = Some(i16::MAX);
808 self.clip_children = true;
809 self
810 }
811
812 #[inline(always)]
814 pub fn align_self(mut self, align: AlignItems) -> Self {
815 self.align_self = Some(align);
816 self
817 }
818
819 #[inline(always)]
821 pub fn self_start(self) -> Self {
822 self.align_self(AlignItems::Start)
823 }
824
825 #[inline(always)]
827 pub fn self_center(self) -> Self {
828 self.align_self(AlignItems::Center)
829 }
830
831 #[inline(always)]
833 pub fn self_end(self) -> Self {
834 self.align_self(AlignItems::End)
835 }
836
837 #[inline(always)]
839 pub fn self_stretch(self) -> Self {
840 self.align_self(AlignItems::Stretch)
841 }
842
843 #[inline(always)]
845 pub fn items_baseline(mut self) -> Self {
846 self.items_baseline = true;
847 self
848 }
849
850 #[inline(always)]
852 pub fn overflow_hidden(mut self) -> Self {
853 self.clip_children = true;
854 self
855 }
856
857 #[inline(always)]
859 pub fn overflow_visible(mut self) -> Self {
860 self.clip_children = false;
861 self
862 }
863
864 #[inline(always)]
866 pub fn overflow_scroll(self) -> Self {
867 self.scrollable_auto()
868 }
869
870 #[inline(always)]
872 pub fn overflow_y_scroll(self) -> Self {
873 self.flex_col().scrollable_auto()
874 }
875
876 #[inline(always)]
878 pub fn overflow_x_scroll(self) -> Self {
879 self.flex_row().scrollable_auto()
880 }
881
882 #[inline(always)]
884 pub fn transition(self) -> Self {
885 self.animate_all(Duration::from_millis(150))
886 }
887
888 #[inline(always)]
890 pub fn transition_colors(self) -> Self {
891 self.animate_color(Duration::from_millis(150))
892 }
893
894 #[inline(always)]
896 pub fn transition_opacity(self) -> Self {
897 self.animate_opacity(Duration::from_millis(150))
898 }
899
900 #[inline(always)]
902 pub fn transition_all(self) -> Self {
903 self.animate_all(Duration::from_millis(150))
904 }
905
906 #[inline(always)]
908 pub fn transition_none(mut self) -> Self {
909 self.transition = None;
910 self
911 }
912
913 #[inline(always)] pub fn duration_75(self) -> Self { self.duration(Duration::from_millis(75)) }
914 #[inline(always)] pub fn duration_100(self) -> Self { self.duration(Duration::from_millis(100)) }
915 #[inline(always)] pub fn duration_150(self) -> Self { self.duration(Duration::from_millis(150)) }
916 #[inline(always)] pub fn duration_200(self) -> Self { self.duration(Duration::from_millis(200)) }
917 #[inline(always)] pub fn duration_300(self) -> Self { self.duration(Duration::from_millis(300)) }
918 #[inline(always)] pub fn duration_500(self) -> Self { self.duration(Duration::from_millis(500)) }
919
920 #[inline(always)] pub fn ease_linear(self) -> Self { self.ease(Easing::Linear) }
921 #[inline(always)] pub fn ease_in(self) -> Self { self.ease(Easing::EaseIn) }
922 #[inline(always)] pub fn ease_out(self) -> Self { self.ease(Easing::EaseOut) }
923 #[inline(always)] pub fn ease_in_out(self) -> Self { self.ease(Easing::EaseInOut) }
924 #[inline(always)] pub fn ease_spring(self) -> Self { self.ease(Easing::Spring) }
925
926 #[inline(always)]
928 pub fn animate_color(mut self, duration: Duration) -> Self {
929 let ms = duration.as_millis().min(u16::MAX as u128) as u16;
930 let mut spec = self.transition.unwrap_or(TransitionSpec {
931 duration_ms: ms,
932 ..TransitionSpec::default()
933 });
934 spec.duration_ms = ms;
935 spec.animate_color = true;
936 self.transition = Some(spec);
937 self
938 }
939
940 #[inline(always)]
942 pub fn animate_bg(self, duration: Duration) -> Self {
943 self.animate_color(duration)
944 }
945
946 #[inline(always)]
948 pub fn animate_bounds(mut self, duration: Duration) -> Self {
949 let ms = duration.as_millis().min(u16::MAX as u128) as u16;
950 let mut spec = self.transition.unwrap_or(TransitionSpec {
951 duration_ms: ms,
952 ..TransitionSpec::default()
953 });
954 spec.duration_ms = ms;
955 spec.animate_bounds = true;
956 self.transition = Some(spec);
957 self
958 }
959
960 #[inline(always)]
962 pub fn ease(mut self, easing: Easing) -> Self {
963 let mut spec = self.transition.unwrap_or_default();
964 spec.easing = easing;
965 self.transition = Some(spec);
966 self
967 }
968
969 #[inline(always)]
971 pub fn repeat_infinite(mut self) -> Self {
972 let mut spec = self.transition.unwrap_or_default();
973 spec.loop_mode = LoopMode::Infinite;
974 self.transition = Some(spec);
975 self
976 }
977
978 #[inline(always)]
980 pub fn repeat_ping_pong(mut self) -> Self {
981 let mut spec = self.transition.unwrap_or_default();
982 spec.loop_mode = LoopMode::PingPong;
983 self.transition = Some(spec);
984 self
985 }
986
987 #[inline(always)]
989 pub fn duration(mut self, duration: Duration) -> Self {
990 let mut spec = self.transition.unwrap_or_default();
991 spec.duration_ms = duration_to_ms(duration);
992 self.transition = Some(spec);
993 self
994 }
995
996 #[inline(always)]
998 pub fn delay(mut self, delay: Duration) -> Self {
999 let mut spec = self.transition.unwrap_or_default();
1000 spec.delay_ms = duration_to_ms(delay);
1001 self.transition = Some(spec);
1002 self
1003 }
1004
1005 #[inline(always)]
1007 pub fn animate_opacity(mut self, duration: Duration) -> Self {
1008 let mut spec = self.transition.unwrap_or_default();
1009 spec.duration_ms = duration_to_ms(duration);
1010 spec.animate_opacity = true;
1011 self.transition = Some(spec);
1012 self
1013 }
1014
1015 #[inline(always)]
1017 pub fn animate_all(mut self, duration: Duration) -> Self {
1018 let mut spec = self.transition.unwrap_or_default();
1019 spec.duration_ms = duration_to_ms(duration);
1020 spec.animate_color = true;
1021 spec.animate_bounds = true;
1022 spec.animate_opacity = true;
1023 self.transition = Some(spec);
1024 self
1025 }
1026
1027 #[inline(always)]
1029 pub fn enter_from(mut self, opacity: u8, dx: i16, dy: i16, duration: Duration) -> Self {
1030 let mut spec = self.transition.unwrap_or_default();
1031 spec.duration_ms = duration_to_ms(duration);
1032 spec.enter = Some(EnterFrom { opacity, dx, dy });
1033 self.transition = Some(spec);
1034 self
1035 }
1036
1037 #[inline(always)]
1039 pub fn fade_in(self, duration: Duration) -> Self {
1040 self.enter_from(0, 0, 0, duration)
1041 }
1042
1043 #[inline(always)]
1045 pub fn slide_in(self, dx: i16, dy: i16, duration: Duration) -> Self {
1046 self.enter_from(0, dx, dy, duration)
1047 }
1048
1049 #[inline(always)]
1051 pub fn ping_pong_bg(mut self, from_bg: Color, duration: Duration) -> Self {
1052 let ms = duration.as_millis().min(u16::MAX as u128) as u16;
1053 let mut spec = self.transition.unwrap_or_default();
1054 spec.duration_ms = ms;
1055 spec.animate_color = true;
1056 spec.loop_mode = LoopMode::PingPong;
1057 spec.easing = Easing::EaseInOut;
1058 spec.pulse_from_bg = Some(from_bg);
1059 self.transition = Some(spec);
1060 self
1061 }
1062
1063 #[inline(always)]
1065 pub fn on_click_raw(mut self, handler: &'a dyn Fn(&mut ActionScope)) -> Self {
1066 self.on_click = Some(handler);
1067 self.focusable = true;
1068 self
1069 }
1070
1071 #[inline(always)]
1073 pub fn on_click(
1074 mut self,
1075 cx: &'a FrameScope,
1076 handler: &'a dyn Fn(crate::pod::ClickEvent, &mut ActionScope),
1077 ) -> Self {
1078 let wrapped = cx.arena().alloc(move |acx: &mut ActionScope| {
1079 let (x, y) = acx.click_position();
1080 handler(crate::pod::ClickEvent { x, y }, acx);
1081 });
1082 self.on_click = Some(wrapped);
1083 self.focusable = true;
1084 self
1085 }
1086
1087 #[inline(always)]
1089 pub fn on_secondary_click_raw(mut self, handler: &'a dyn Fn(&mut ActionScope)) -> Self {
1090 self.on_secondary_click = Some(handler);
1091 self
1092 }
1093
1094 #[inline(always)]
1096 pub fn on_secondary_click(
1097 mut self,
1098 cx: &'a FrameScope,
1099 handler: &'a dyn Fn(crate::pod::ClickEvent, &mut ActionScope),
1100 ) -> Self {
1101 let wrapped = cx.arena().alloc(move |acx: &mut ActionScope| {
1102 let (x, y) = acx.click_position();
1103 handler(crate::pod::ClickEvent { x, y }, acx);
1104 });
1105 self.on_secondary_click = Some(wrapped);
1106 self
1107 }
1108
1109 #[inline(always)]
1111 pub fn on_drag_raw(mut self, handler: &'a dyn Fn(&mut ActionScope)) -> Self {
1112 self.on_drag = Some(handler);
1113 self
1114 }
1115
1116 #[inline(always)]
1118 pub fn on_drag(
1119 mut self,
1120 cx: &'a FrameScope,
1121 handler: &'a dyn Fn(DragEvent, &mut ActionScope),
1122 ) -> Self {
1123 let wrapped = cx.arena().alloc(move |acx: &mut ActionScope| {
1124 let ev = acx.drag_event();
1125 handler(ev, acx);
1126 });
1127 self.on_drag = Some(wrapped);
1128 self
1129 }
1130
1131 #[inline(always)]
1133 pub fn on_hover_raw(mut self, handler: &'a dyn Fn(bool, &mut ActionScope)) -> Self {
1134 self.on_hover = Some(handler);
1135 self
1136 }
1137
1138 #[inline(always)]
1140 pub fn on_hover(
1141 mut self,
1142 _cx: &'a FrameScope,
1143 handler: &'a dyn Fn(bool, &mut ActionScope),
1144 ) -> Self {
1145 self.on_hover = Some(handler);
1146 self
1147 }
1148
1149 #[inline(always)]
1151 pub fn on_pointer_move_raw(mut self, handler: &'a dyn Fn(&mut ActionScope)) -> Self {
1152 self.on_pointer_move = Some(handler);
1153 self
1154 }
1155
1156 #[inline(always)]
1158 pub fn on_pointer_move(
1159 mut self,
1160 cx: &'a FrameScope,
1161 handler: &'a dyn Fn(DragEvent, &mut ActionScope),
1162 ) -> Self {
1163 let wrapped = cx.arena().alloc(move |acx: &mut ActionScope| {
1164 let ev = acx.drag_event();
1165 handler(ev, acx);
1166 });
1167 self.on_pointer_move = Some(wrapped);
1168 self
1169 }
1170
1171 #[inline(always)]
1173 pub fn on_wheel_raw(
1174 mut self,
1175 handler: &'a dyn Fn(crate::pod::WheelEvent, &mut ActionScope),
1176 ) -> Self {
1177 self.on_wheel = Some(handler);
1178 self
1179 }
1180
1181 #[inline(always)]
1183 pub fn on_wheel(
1184 mut self,
1185 _cx: &'a FrameScope,
1186 handler: &'a dyn Fn(crate::pod::WheelEvent, &mut ActionScope),
1187 ) -> Self {
1188 self.on_wheel = Some(handler);
1189 self
1190 }
1191
1192 #[inline(always)]
1194 pub fn on_pinch_raw(
1195 mut self,
1196 handler: &'a dyn Fn(crate::pod::PinchEvent, &mut ActionScope),
1197 ) -> Self {
1198 self.on_pinch = Some(handler);
1199 self
1200 }
1201
1202 #[inline(always)]
1204 pub fn on_pinch(
1205 mut self,
1206 _cx: &'a FrameScope,
1207 handler: &'a dyn Fn(crate::pod::PinchEvent, &mut ActionScope),
1208 ) -> Self {
1209 self.on_pinch = Some(handler);
1210 self
1211 }
1212
1213 #[inline(always)]
1215 pub fn on_swipe(
1216 mut self,
1217 _cx: &'a FrameScope,
1218 handler: &'a dyn Fn(crate::pod::SwipeDir, &mut ActionScope),
1219 ) -> Self {
1220 self.on_swipe = Some(handler);
1221 self
1222 }
1223
1224 #[inline(always)]
1226 pub fn key(mut self, key: impl AsRef<[u8]>) -> Self {
1227 let mut h: u32 = 0x811c_9dc5;
1228 for &b in key.as_ref() {
1229 h ^= b as u32;
1230 h = h.wrapping_mul(0x0100_0193);
1231 }
1232 self.id = Some(h | 1);
1233 self
1234 }
1235
1236 #[inline(always)]
1238 pub fn z_index(mut self, z: i8) -> Self {
1239 self.z_index = z;
1240 self
1241 }
1242
1243 #[inline(always)]
1245 pub fn on_key_input(
1246 mut self,
1247 handler: &'a dyn Fn(crate::pod::KeyCode, &mut ActionScope),
1248 ) -> Self {
1249 self.on_key_input = Some(handler);
1250 self.focusable = true;
1251 self
1252 }
1253
1254 #[inline(always)]
1256 pub fn on_key_nav(
1257 mut self,
1258 handler: &'a dyn Fn(crate::pod::KeyCode, &mut ActionScope),
1259 ) -> Self {
1260 self.on_key_nav = Some(handler);
1261 self
1262 }
1263
1264 #[inline(always)]
1266 pub fn on_navigate_back(
1267 mut self,
1268 handler: &'a dyn Fn(&mut ActionScope),
1269 ) -> Self {
1270 self.on_navigate_back = Some(handler);
1271 self
1272 }
1273
1274 #[inline(always)]
1276 pub fn shadow(mut self, blur: u8, offset_x: i8, offset_y: i8, color: Color) -> Self {
1277 if blur > 0 && color.a() > 0 {
1278 self.shadow = Some((blur.min(64), offset_x, offset_y, color));
1279 }
1280 self
1281 }
1282
1283 #[inline(always)]
1285 pub fn grid(mut self, cols: u8) -> Self {
1286 self.grid_cols = cols.max(1);
1287 self
1288 }
1289
1290 pub fn child(mut self, cx: &'a FrameScope, child: impl IntoElement<'a>) -> Self {
1292 let elem = child.into_element(cx);
1293 let node: &'a ElementNode<'a> = cx.arena().alloc_temp(ElementNode {
1294 element: elem,
1295 next_sibling: Cell::new(None),
1296 });
1297 if let Some(last) = self.last_child {
1298 last.next_sibling.set(Some(node));
1299 } else {
1300 self.first_child = Some(node);
1301 }
1302 self.last_child = Some(node);
1303 self
1304 }
1305
1306 #[inline(always)]
1308 pub fn child_opt(self, cx: &'a FrameScope, child: Option<impl IntoElement<'a>>) -> Self {
1309 match child {
1310 Some(c) => self.child(cx, c),
1311 None => self,
1312 }
1313 }
1314
1315 pub fn children<I, E>(mut self, cx: &'a FrameScope, iter: I) -> Self
1317 where
1318 I: IntoIterator<Item = E>,
1319 E: IntoElement<'a>,
1320 {
1321 for item in iter {
1322 self = self.child(cx, item);
1323 }
1324 self
1325 }
1326
1327 #[inline(always)]
1329 pub fn justify_start_localized(mut self, cx: &FrameScope) -> Self {
1330 if cx.is_rtl() {
1331 self.style.set_justify(crate::style::Justify::End);
1332 } else {
1333 self.style.set_justify(crate::style::Justify::Start);
1334 }
1335 self
1336 }
1337
1338 #[inline(always)]
1340 pub fn justify_end_localized(mut self, cx: &FrameScope) -> Self {
1341 if cx.is_rtl() {
1342 self.style.set_justify(crate::style::Justify::Start);
1343 } else {
1344 self.style.set_justify(crate::style::Justify::End);
1345 }
1346 self
1347 }
1348
1349 #[inline(always)]
1351 pub fn ps(self, cx: &FrameScope, px: i8) -> Self {
1352 if cx.is_rtl() {
1353 self.pr(px)
1354 } else {
1355 self.pl(px)
1356 }
1357 }
1358
1359 #[inline(always)]
1361 pub fn pe(self, cx: &FrameScope, px: i8) -> Self {
1362 if cx.is_rtl() {
1363 self.pl(px)
1364 } else {
1365 self.pr(px)
1366 }
1367 }
1368
1369 #[inline(always)]
1371 pub fn ms(self, cx: &FrameScope, px: i16) -> Self {
1372 if cx.is_rtl() {
1373 self.mr(px)
1374 } else {
1375 self.ml(px)
1376 }
1377 }
1378
1379 #[inline(always)]
1381 pub fn me(self, cx: &FrameScope, px: i16) -> Self {
1382 if cx.is_rtl() {
1383 self.ml(px)
1384 } else {
1385 self.mr(px)
1386 }
1387 }
1388
1389 #[inline(always)]
1395 pub fn rounded_corners(mut self, radii: CornerRadii) -> Self {
1396 self.effects.corner_radii = Some(radii);
1397 self
1398 }
1399
1400 #[inline(always)]
1402 pub fn rounded_t(self, r: u8) -> Self {
1403 self.rounded_corners(CornerRadii::top(r))
1404 }
1405
1406 #[inline(always)]
1408 pub fn rounded_b(self, r: u8) -> Self {
1409 self.rounded_corners(CornerRadii::bottom(r))
1410 }
1411
1412 #[inline(always)]
1414 pub fn rounded_l(self, r: u8) -> Self {
1415 self.rounded_corners(CornerRadii::left(r))
1416 }
1417
1418 #[inline(always)]
1420 pub fn rounded_r(self, r: u8) -> Self {
1421 self.rounded_corners(CornerRadii::right(r))
1422 }
1423
1424 #[inline(always)]
1426 pub fn bg_paint(mut self, paint: Paint<'a>) -> Self {
1427 self.effects.bg_paint = Some(paint);
1428 self
1429 }
1430
1431 #[inline]
1433 pub fn bg_linear_gradient(
1434 mut self,
1435 cx: &'a FrameScope,
1436 angle_deg: f32,
1437 stops: &[ColorStop],
1438 ) -> Self {
1439 let arena_stops = cx.arena().alloc_iter(stops.iter().copied());
1440 self.effects.bg_paint = Some(Paint::linear_angle(angle_deg, arena_stops));
1441 self
1442 }
1443
1444 #[inline]
1446 pub fn bg_radial_gradient(mut self, cx: &'a FrameScope, stops: &[ColorStop]) -> Self {
1447 let arena_stops = cx.arena().alloc_iter(stops.iter().copied());
1448 self.effects.bg_paint = Some(Paint::radial(arena_stops));
1449 self
1450 }
1451
1452 #[inline]
1454 pub fn bg_radial_focal_gradient(
1455 mut self,
1456 cx: &'a FrameScope,
1457 center: [f32; 2],
1458 radius: f32,
1459 focal: [f32; 2],
1460 focal_radius: f32,
1461 stops: &[ColorStop],
1462 ) -> Self {
1463 let arena_stops = cx.arena().alloc_iter(stops.iter().copied());
1464 self.effects.bg_paint = Some(Paint::radial_focal(
1465 center,
1466 radius,
1467 focal,
1468 focal_radius,
1469 arena_stops,
1470 ));
1471 self
1472 }
1473
1474 #[inline]
1476 pub fn bg_conic_gradient(
1477 mut self,
1478 cx: &'a FrameScope,
1479 start_angle_deg: f32,
1480 stops: &[ColorStop],
1481 ) -> Self {
1482 let arena_stops = cx.arena().alloc_iter(stops.iter().copied());
1483 self.effects.bg_paint = Some(Paint::conic(start_angle_deg, arena_stops));
1484 self
1485 }
1486
1487 #[inline]
1489 pub fn bg_gradient_extend(mut self, mode: ExtendMode) -> Self {
1490 if let Some(p) = self.effects.bg_paint {
1491 self.effects.bg_paint = Some(p.with_extend(mode));
1492 }
1493 self
1494 }
1495
1496 #[inline]
1498 pub fn bg_gradient_space(mut self, space: GradientSpace) -> Self {
1499 if let Some(p) = self.effects.bg_paint {
1500 self.effects.bg_paint = Some(p.with_space(space));
1501 }
1502 self
1503 }
1504
1505 #[inline(always)]
1507 pub fn blend_mode(mut self, mode: BlendMode) -> Self {
1508 self.effects.blend_mode = mode;
1509 self
1510 }
1511
1512 #[inline(always)]
1514 pub fn isolate(mut self) -> Self {
1515 self.effects.isolate = true;
1516 self
1517 }
1518
1519 #[inline(always)]
1521 pub fn filter(mut self, filter: LayerFilter) -> Self {
1522 self.effects.filter = filter;
1523 self
1524 }
1525
1526 #[inline(always)]
1528 pub fn blur(mut self, radius: u8) -> Self {
1529 self.effects.filter.blur_radius = radius;
1530 self
1531 }
1532
1533 #[inline]
1535 pub fn color_matrix(mut self, matrix: ColorMatrix) -> Self {
1536 self.effects.filter.color_matrix = Some(match self.effects.filter.color_matrix {
1537 Some(prev) => prev.then(matrix),
1538 None => matrix,
1539 });
1540 self
1541 }
1542
1543 #[inline]
1545 pub fn grayscale(self, amount: f32) -> Self {
1546 self.color_matrix(ColorMatrix::grayscale(amount))
1547 }
1548
1549 #[inline]
1551 pub fn sepia(self, amount: f32) -> Self {
1552 self.color_matrix(ColorMatrix::sepia(amount))
1553 }
1554
1555 #[inline]
1557 pub fn saturate(self, amount: f32) -> Self {
1558 self.color_matrix(ColorMatrix::saturate(amount))
1559 }
1560
1561 #[inline]
1563 pub fn brightness(self, amount: f32) -> Self {
1564 self.color_matrix(ColorMatrix::brightness(amount))
1565 }
1566
1567 #[inline]
1569 pub fn contrast(self, amount: f32) -> Self {
1570 self.color_matrix(ColorMatrix::contrast(amount))
1571 }
1572
1573 #[inline]
1575 pub fn hue_rotate(self, deg: f32) -> Self {
1576 self.color_matrix(ColorMatrix::hue_rotate(deg))
1577 }
1578
1579 #[inline]
1581 pub fn invert(self, amount: f32) -> Self {
1582 self.color_matrix(ColorMatrix::invert(amount))
1583 }
1584
1585 #[inline(always)]
1587 pub fn drop_shadow(mut self, blur: u8, offset_x: i8, offset_y: i8, color: Color) -> Self {
1588 self.effects.filter.drop_shadow = Some(DropShadow::new(blur, offset_x, offset_y, color));
1589 self
1590 }
1591
1592 #[inline(always)]
1594 pub fn backdrop_filter(mut self, filter: BackdropFilter) -> Self {
1595 self.effects.backdrop_filter = filter;
1596 self
1597 }
1598
1599 #[inline(always)]
1601 pub fn backdrop_blur(mut self, radius: u8) -> Self {
1602 self.effects.backdrop_filter.blur_radius = radius;
1603 self
1604 }
1605
1606 #[inline]
1608 pub fn backdrop_acrylic(mut self, blur_radius: u8, tint: Color) -> Self {
1609 self.effects.backdrop_filter = BackdropFilter::acrylic(blur_radius, tint);
1610 self
1611 }
1612
1613 #[inline]
1615 pub fn transform(mut self, t: Transform2D) -> Self {
1616 self.effects.transform = Some(match self.effects.transform {
1617 Some(prev) => prev.concat(t),
1618 None => t,
1619 });
1620 self
1621 }
1622
1623 #[inline]
1625 pub fn rotate_deg(self, deg: f32) -> Self {
1626 self.transform(Transform2D::rotate(deg))
1627 }
1628
1629 #[inline]
1631 pub fn scale(self, sx: f32, sy: f32) -> Self {
1632 self.transform(Transform2D::scale(sx, sy))
1633 }
1634
1635 #[inline]
1637 pub fn translate(self, tx: f32, ty: f32) -> Self {
1638 self.transform(Transform2D::translate(tx, ty))
1639 }
1640
1641 #[inline]
1643 pub fn skew(self, ax_deg: f32, ay_deg: f32) -> Self {
1644 let mut s = self;
1645 if ax_deg != 0.0 {
1646 s = s.transform(Transform2D::skew_x(ax_deg));
1647 }
1648 if ay_deg != 0.0 {
1649 s = s.transform(Transform2D::skew_y(ay_deg));
1650 }
1651 s
1652 }
1653
1654 #[inline(always)]
1656 pub fn clip_path(mut self, path_d: &'static str) -> Self {
1657 self.effects.clip_path = Some(StrRef::Static(path_d));
1658 self
1659 }
1660
1661 #[inline]
1663 pub fn clip_path_str(mut self, cx: &'a FrameScope, path_d: &str) -> Self {
1664 let buf = cx.arena().alloc_bytes(path_d.len());
1665 buf.copy_from_slice(path_d.as_bytes());
1666 let s = unsafe { core::str::from_utf8_unchecked(buf) };
1668 self.effects.clip_path = Some(StrRef::Scratch(s));
1669 self
1670 }
1671
1672 #[inline(always)]
1677 pub fn external_texture(mut self, id: crate::paint::ExternalTextureId) -> Self {
1678 self.external_texture = Some(crate::paint::ExternalTextureSpec::new(id));
1679 self
1680 }
1681
1682 #[inline(always)]
1684 pub fn external_texture_spec(mut self, spec: crate::paint::ExternalTextureSpec) -> Self {
1685 self.external_texture = Some(spec);
1686 self
1687 }
1688
1689 #[inline(always)]
1691 pub fn external_texture_uv(mut self, uv_rect: [f32; 4]) -> Self {
1692 if let Some(ext) = &mut self.external_texture {
1693 ext.uv_rect = uv_rect;
1694 }
1695 self
1696 }
1697
1698 #[inline(always)]
1700 pub fn external_texture_revision(mut self, revision: u64) -> Self {
1701 if let Some(ext) = &mut self.external_texture {
1702 ext.content_revision = revision;
1703 }
1704 self
1705 }
1706
1707 #[inline(always)]
1709 pub fn external_texture_format(mut self, premultiplied: bool, fallback_bg: Color) -> Self {
1710 if let Some(ext) = &mut self.external_texture {
1711 ext.premultiplied = premultiplied;
1712 ext.fallback_bg = fallback_bg;
1713 }
1714 self
1715 }
1716
1717 #[inline(always)]
1719 pub fn aspect_ratio(mut self, ratio: f32) -> Self {
1720 self.layout_ext.aspect_ratio = ratio.max(0.0);
1721 self
1722 }
1723
1724 #[inline(always)]
1726 pub fn grid_col_span(mut self, span: u8) -> Self {
1727 self.layout_ext.grid_col_span = span.max(1);
1728 self
1729 }
1730
1731 #[inline]
1733 pub fn grid_template_fr(mut self, cx: &'a FrameScope, weights: &[u16]) -> Self {
1734 if !weights.is_empty() {
1735 self.grid_cols = weights.len().min(u8::MAX as usize) as u8;
1736 self.layout_ext.grid_template_fr = cx.arena().alloc_iter(weights.iter().copied());
1737 }
1738 self
1739 }
1740
1741 #[inline(always)]
1743 pub fn sticky_top(mut self, offset: i16) -> Self {
1744 self.layout_ext.sticky_top = Some(offset);
1745 self
1746 }
1747
1748 #[inline(always)]
1750 pub fn rtl(mut self, rtl: bool) -> Self {
1751 self.layout_ext.rtl = rtl;
1752 self
1753 }
1754
1755 #[inline(always)]
1757 pub fn rtl_auto(mut self, cx: &FrameScope) -> Self {
1758 self.layout_ext.rtl = cx.is_rtl();
1759 self
1760 }
1761
1762 #[inline(always)]
1764 pub fn overflow_auto(mut self) -> Self {
1765 self.scrollable_max = Some(i16::MAX);
1766 self.clip_children = true;
1767 self
1768 }
1769
1770 #[inline(always)]
1772 pub fn scroll_chaining(mut self, enable: bool) -> Self {
1773 self.layout_ext.scroll_chaining = enable;
1774 self
1775 }
1776}
1777