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_swipe: self.on_swipe,
132 on_key_input: self.on_key_input,
133 on_key_nav: self.on_key_nav,
134 on_navigate_back: self.on_navigate_back,
135 on_secondary_click: self.on_secondary_click,
136 }))
137 } else {
138 None
139 };
140 Some(&*cx.arena().alloc(DivInteractivity {
141 on_click: self.on_click,
142 rare,
143 }))
144 } else {
145 None
146 };
147
148 let mut flags = 0u8;
149 if self.focusable {
150 flags |= 1 << 0;
151 }
152 if self.is_overlay {
153 flags |= 1 << 1;
154 }
155 if self.occlude_hit {
156 flags |= 1 << 2;
157 }
158 if self.auto_repeat {
159 flags |= 1 << 3;
160 }
161 if self.clip_children {
162 flags |= 1 << 4;
163 }
164 if self.id.is_some() {
165 flags |= 1 << 5;
166 }
167 if self.active_bg.is_some() {
168 flags |= 1 << 6;
169 }
170 if self.hover_bg.is_some() {
171 flags |= 1 << 7;
172 }
173
174 Element::Div(DivNode {
175 style: self.style,
176 first_child: self.first_child,
177 visual,
178 interact,
179 raw_id: self.id.unwrap_or(0),
180 raw_active_bg: self.active_bg.unwrap_or(Color::TRANSPARENT),
181 raw_hover_bg: self.hover_bg.unwrap_or(Color::TRANSPARENT),
182 opacity: self.opacity,
183 z_index: self.z_index,
184 grid_cols: self.grid_cols,
185 flags,
186 })
187 }
188}
189
190
191pub struct Div<'a> {
193 pub id: Option<u32>,
195 pub style: Style,
197 pub margin: Edges<i16>,
199 pub extra_padding: Edges<i16>,
201 pub min_w: i16,
203 pub max_w: i16,
205 pub min_h: i16,
207 pub max_h: i16,
209 pub opacity: u8,
211 pub active_bg: Option<Color>,
213 pub hover_bg: Option<Color>,
215 pub bg_grad: Option<(Color, bool)>,
217 pub focus_border: Option<(u8, Color)>,
219 pub focusable: bool,
221 pub is_overlay: bool,
223 pub occlude_hit: bool,
225 pub auto_repeat: bool,
227 pub scrollable_max: Option<i16>,
229 pub pos: Option<(i16, i16)>,
231 pub first_child: Option<&'a ElementNode<'a>>,
233 pub last_child: Option<&'a ElementNode<'a>>,
235 pub on_click: Option<&'a dyn Fn(&mut ActionScope)>,
237 pub on_long_press: Option<&'a dyn Fn(&mut ActionScope)>,
239 pub on_drag: Option<&'a dyn Fn(&mut ActionScope)>,
241 pub on_hover: Option<&'a dyn Fn(bool, &mut ActionScope)>,
243 pub on_pointer_move: Option<&'a dyn Fn(&mut ActionScope)>,
245 pub on_swipe: Option<&'a dyn Fn(crate::pod::SwipeDir, &mut ActionScope)>,
247 pub on_key_input: Option<&'a dyn Fn(crate::pod::KeyCode, &mut ActionScope)>,
249 pub on_key_nav: Option<&'a dyn Fn(crate::pod::KeyCode, &mut ActionScope)>,
251 pub on_navigate_back: Option<&'a dyn Fn(&mut ActionScope)>,
253 pub on_secondary_click: Option<&'a dyn Fn(&mut ActionScope)>,
255 pub z_index: i8,
257 pub shadow: Option<(u8, i8, i8, Color)>,
259 pub grid_cols: u8,
261 pub transition: Option<TransitionSpec>,
263 pub clip_children: bool,
265 pub align_self: Option<AlignItems>,
267 pub cursor: Option<CursorShape>,
269 pub text_color: Option<Color>,
271 pub text_size: Option<u8>,
273 pub hover_style: Option<StyleRefinement>,
275 pub active_style: Option<StyleRefinement>,
277 pub focus_style: Option<StyleRefinement>,
279 pub items_baseline: bool,
281 pub effects: PaintEffects<'a>,
283 pub external_texture: Option<crate::paint::ExternalTextureSpec>,
285 pub layout_ext: crate::paint::LayoutExtras<'a>,
287}
288
289#[inline(always)]
291pub fn div<'a>() -> Div<'a> {
292 Div {
293 id: None,
294 style: Style::default(),
295 margin: Edges::all(0),
296 extra_padding: Edges::all(0),
297 min_w: 0,
298 max_w: 0,
299 min_h: 0,
300 max_h: 0,
301 opacity: 255,
302 active_bg: None,
303 hover_bg: None,
304 bg_grad: None,
305 focus_border: None,
306 focusable: false,
307 is_overlay: false,
308 occlude_hit: false,
309 auto_repeat: false,
310 scrollable_max: None,
311 pos: None,
312 first_child: None,
313 last_child: None,
314 on_click: None,
315 on_long_press: None,
316 on_drag: None,
317 on_hover: None,
318 on_pointer_move: None,
319 on_swipe: None,
320 on_key_input: None,
321 on_key_nav: None,
322 on_navigate_back: None,
323 on_secondary_click: None,
324 z_index: 0,
325 shadow: None,
326 grid_cols: 0,
327 transition: None,
328 clip_children: false,
329 align_self: None,
330 cursor: None,
331 text_color: None,
332 text_size: None,
333 hover_style: None,
334 active_style: None,
335 focus_style: None,
336 items_baseline: false,
337 effects: PaintEffects::EMPTY,
338 external_texture: None,
339 layout_ext: crate::paint::LayoutExtras::EMPTY,
340 }
341}
342
343impl<'a> Styled for Div<'a> {
344 #[inline(always)]
345 fn style_mut(&mut self) -> &mut Style {
346 &mut self.style
347 }
348}
349
350impl<'a> Div<'a> {
351 #[inline(always)]
352 fn has_non_focus_visual_extra(&self) -> bool {
353 self.margin != Edges::all(0)
354 || self.extra_padding != Edges::all(0)
355 || self.min_w != 0
356 || self.max_w != 0
357 || self.min_h != 0
358 || self.max_h != 0
359 || self.bg_grad.is_some()
360 || self.scrollable_max.is_some()
361 || self.pos.is_some()
362 || self.shadow.is_some()
363 || self.transition.is_some()
364 || self.align_self.is_some()
365 || self.cursor.is_some()
366 || self.text_color.is_some()
367 || self.text_size.is_some()
368 || self.hover_style.is_some()
369 || self.active_style.is_some()
370 || self.focus_style.is_some()
371 || self.items_baseline
372 || !self.effects.is_empty()
373 || self.external_texture.is_some()
374 || !self.layout_ext.is_empty()
375 }
376
377 #[inline(always)]
378 fn has_interactivity(&self) -> bool {
379 self.on_click.is_some() || self.has_rare_handlers()
380 }
381
382 #[inline(always)]
383 fn has_rare_handlers(&self) -> bool {
384 self.on_long_press.is_some()
385 || self.on_drag.is_some()
386 || self.on_hover.is_some()
387 || self.on_pointer_move.is_some()
388 || self.on_swipe.is_some()
389 || self.on_key_input.is_some()
390 || self.on_key_nav.is_some()
391 || self.on_navigate_back.is_some()
392 || self.on_secondary_click.is_some()
393 }
394
395 #[inline(always)]
397 pub fn id(mut self, id: u32) -> Self {
398 self.id = Some(id);
399 self
400 }
401
402 #[inline(always)]
404 pub fn scoped_id(mut self, cx: &FrameScope, local_id: u32) -> Self {
405 self.id = Some(cx.scoped_id(local_id));
406 self
407 }
408
409 #[inline(always)]
411 pub fn pos(mut self, x: i16, y: i16) -> Self {
412 self.pos = Some((x, y));
413 self
414 }
415
416 #[inline(always)]
418 pub fn safe_area(mut self, cx: &FrameScope) -> Self {
419 let sa = cx.safe_area();
420 let kb = cx.keyboard_inset();
421 self.extra_padding.top = self.extra_padding.top.saturating_add(sa.top.max(0));
422 self.extra_padding.right = self.extra_padding.right.saturating_add(sa.right.max(0));
423 self.extra_padding.bottom = self
424 .extra_padding
425 .bottom
426 .saturating_add(sa.bottom.saturating_add(kb).max(0));
427 self.extra_padding.left = self.extra_padding.left.saturating_add(sa.left.max(0));
428 self
429 }
430
431 #[inline(always)]
433 pub fn pt_safe(mut self, cx: &FrameScope) -> Self {
434 let sa = cx.safe_area();
435 self.extra_padding.top = self.extra_padding.top.saturating_add(sa.top.max(0));
436 self
437 }
438
439 #[inline(always)]
441 pub fn pb_safe(mut self, cx: &FrameScope) -> Self {
442 let sa = cx.safe_area();
443 let kb = cx.keyboard_inset();
444 self.extra_padding.bottom = self
445 .extra_padding
446 .bottom
447 .saturating_add(sa.bottom.saturating_add(kb).max(0));
448 self
449 }
450
451 #[inline(always)]
453 pub fn mx(mut self, px: i16) -> Self {
454 self.margin.left = px;
455 self.margin.right = px;
456 self
457 }
458
459 #[inline(always)]
461 pub fn my(mut self, px: i16) -> Self {
462 self.margin.top = px;
463 self.margin.bottom = px;
464 self
465 }
466
467 #[inline(always)]
469 pub fn mt(mut self, px: i16) -> Self {
470 self.margin.top = px;
471 self
472 }
473
474 #[inline(always)]
476 pub fn mb(mut self, px: i16) -> Self {
477 self.margin.bottom = px;
478 self
479 }
480
481 #[inline(always)]
483 pub fn ml(mut self, px: i16) -> Self {
484 self.margin.left = px;
485 self
486 }
487
488 #[inline(always)]
490 pub fn mr(mut self, px: i16) -> Self {
491 self.margin.right = px;
492 self
493 }
494
495 #[inline(always)]
497 pub fn min_w(mut self, px: i16) -> Self {
498 self.min_w = px.max(0);
499 self
500 }
501
502 #[inline(always)]
504 pub fn max_w(mut self, px: i16) -> Self {
505 self.max_w = px.max(0);
506 self
507 }
508
509 #[inline(always)]
511 pub fn min_h(mut self, px: i16) -> Self {
512 self.min_h = px.max(0);
513 self
514 }
515
516 #[inline(always)]
518 pub fn max_h(mut self, px: i16) -> Self {
519 self.max_h = px.max(0);
520 self
521 }
522
523 #[inline(always)]
525 pub fn opacity(mut self, alpha: u8) -> Self {
526 self.opacity = alpha;
527 self
528 }
529
530 #[inline(always)]
532 pub fn active_bg(mut self, color: Color) -> Self {
533 self.active_bg = Some(color);
534 self
535 }
536
537 #[inline(always)]
539 pub fn hover_bg(mut self, color: Color) -> Self {
540 self.hover_bg = Some(color);
541 self
542 }
543
544 #[inline(always)]
548 pub fn hover(mut self, f: impl FnOnce(StyleRefinement) -> StyleRefinement) -> Self {
549 let base = self.hover_style.unwrap_or_else(|| {
550 let mut r = StyleRefinement::new();
551 r.bg = self.hover_bg;
552 r
553 });
554 let refined = f(base);
555 if refined.is_empty() {
556 return self;
557 }
558 if refined.is_bg_only() {
559 self.hover_bg = refined.bg;
560 self.hover_style = None;
561 } else {
562 if let Some(bg) = refined.bg {
563 self.hover_bg = Some(bg);
564 }
565 self.hover_style = Some(refined);
566 }
567 self
568 }
569
570 #[inline(always)]
572 pub fn active(mut self, f: impl FnOnce(StyleRefinement) -> StyleRefinement) -> Self {
573 let base = self.active_style.unwrap_or_else(|| {
574 let mut r = StyleRefinement::new();
575 r.bg = self.active_bg;
576 r
577 });
578 let refined = f(base);
579 if refined.is_empty() {
580 return self;
581 }
582 if refined.is_bg_only() {
583 self.active_bg = refined.bg;
584 self.active_style = None;
585 } else {
586 if let Some(bg) = refined.bg {
587 self.active_bg = Some(bg);
588 }
589 self.active_style = Some(refined);
590 }
591 self
592 }
593
594 #[inline(always)]
596 pub fn focus(mut self, f: impl FnOnce(StyleRefinement) -> StyleRefinement) -> Self {
597 self.focusable = true;
598 let refined = f(self.focus_style.unwrap_or_default());
599 if !refined.is_empty() {
600 self.focus_style = Some(refined);
601 }
602 self
603 }
604
605 #[inline(always)]
607 pub fn text_color(mut self, color: Color) -> Self {
608 self.text_color = Some(color);
609 self
610 }
611
612 #[inline(always)]
614 pub fn text_size(mut self, px: u8) -> Self {
615 self.text_size = Some(px);
616 self
617 }
618
619 #[inline(always)] pub fn text_xs(self) -> Self { self.text_size(11) }
621 #[inline(always)] pub fn text_sm(self) -> Self { self.text_size(12) }
622 #[inline(always)] pub fn text_base(self) -> Self { self.text_size(14) }
623 #[inline(always)] pub fn text_lg(self) -> Self { self.text_size(16) }
624 #[inline(always)] pub fn text_xl(self) -> Self { self.text_size(18) }
625 #[inline(always)] pub fn text_2xl(self) -> Self { self.text_size(22) }
626 #[inline(always)] pub fn text_3xl(self) -> Self { self.text_size(28) }
627
628 #[inline(always)]
630 pub fn opacity_f(mut self, alpha: f32) -> Self {
631 let c = if alpha <= 0.0 {
632 0.0
633 } else if alpha >= 1.0 {
634 1.0
635 } else {
636 alpha
637 };
638 self.opacity = (c * 255.0 + 0.5) as u8;
639 self
640 }
641
642 #[inline(always)] pub fn mx_0(self) -> Self { self.mx(0) }
644 #[inline(always)] pub fn mx_1(self) -> Self { self.mx(4) }
645 #[inline(always)] pub fn mx_2(self) -> Self { self.mx(8) }
646 #[inline(always)] pub fn mx_3(self) -> Self { self.mx(12) }
647 #[inline(always)] pub fn mx_4(self) -> Self { self.mx(16) }
648 #[inline(always)] pub fn my_0(self) -> Self { self.my(0) }
649 #[inline(always)] pub fn my_1(self) -> Self { self.my(4) }
650 #[inline(always)] pub fn my_2(self) -> Self { self.my(8) }
651 #[inline(always)] pub fn my_3(self) -> Self { self.my(12) }
652 #[inline(always)] pub fn my_4(self) -> Self { self.my(16) }
653 #[inline(always)] pub fn mt_1(self) -> Self { self.mt(4) }
654 #[inline(always)] pub fn mt_2(self) -> Self { self.mt(8) }
655 #[inline(always)] pub fn mt_3(self) -> Self { self.mt(12) }
656 #[inline(always)] pub fn mt_4(self) -> Self { self.mt(16) }
657 #[inline(always)] pub fn mb_1(self) -> Self { self.mb(4) }
658 #[inline(always)] pub fn mb_2(self) -> Self { self.mb(8) }
659 #[inline(always)] pub fn mb_3(self) -> Self { self.mb(12) }
660 #[inline(always)] pub fn mb_4(self) -> Self { self.mb(16) }
661 #[inline(always)] pub fn ml_1(self) -> Self { self.ml(4) }
662 #[inline(always)] pub fn ml_2(self) -> Self { self.ml(8) }
663 #[inline(always)] pub fn ml_3(self) -> Self { self.ml(12) }
664 #[inline(always)] pub fn ml_4(self) -> Self { self.ml(16) }
665 #[inline(always)] pub fn mr_1(self) -> Self { self.mr(4) }
666 #[inline(always)] pub fn mr_2(self) -> Self { self.mr(8) }
667 #[inline(always)] pub fn mr_3(self) -> Self { self.mr(12) }
668 #[inline(always)] pub fn mr_4(self) -> Self { self.mr(16) }
669
670 #[inline(always)] pub fn relative(self) -> Self { self }
673 #[inline(always)] pub fn block(self) -> Self { self.flex_col() }
675 #[inline(always)] pub fn inline_flex(self) -> Self { self.flex_row() }
677
678 #[inline(always)] pub fn cursor_pointer(self) -> Self { self.cursor(CursorShape::Pointer) }
679 #[inline(always)] pub fn cursor_default(self) -> Self { self.cursor(CursorShape::Default) }
680 #[inline(always)] pub fn cursor_text(self) -> Self { self.cursor(CursorShape::Text) }
681 #[inline(always)] pub fn cursor_not_allowed(self) -> Self { self.cursor(CursorShape::NotAllowed) }
682 #[inline(always)] pub fn cursor_grab(self) -> Self { self.cursor(CursorShape::Grab) }
683 #[inline(always)] pub fn cursor_grabbing(self) -> Self { self.cursor(CursorShape::Grabbing) }
684
685 #[inline(always)] pub fn shadow_none(mut self) -> Self { self.shadow = None; self }
686 #[inline(always)] pub fn shadow_sm(self) -> Self { self.shadow(4, 0, 1, Color::rgba(0, 0, 0, 48)) }
687 #[inline(always)] pub fn shadow_md(self) -> Self { self.shadow(10, 0, 3, Color::rgba(0, 0, 0, 72)) }
688 #[inline(always)] pub fn shadow_lg(self) -> Self { self.shadow(18, 0, 6, Color::rgba(0, 0, 0, 96)) }
689 #[inline(always)] pub fn shadow_xl(self) -> Self { self.shadow(28, 0, 10, Color::rgba(0, 0, 0, 120)) }
690
691 #[inline(always)]
693 pub fn bg_gradient(mut self, to_color: Color) -> Self {
694 self.bg_grad = Some((to_color, false));
695 self
696 }
697
698 #[inline(always)]
700 pub fn bg_gradient_x(mut self, to_color: Color) -> Self {
701 self.bg_grad = Some((to_color, true));
702 self
703 }
704
705 #[inline(always)]
707 pub fn overlay(mut self) -> Self {
708 self.is_overlay = true;
709 self
710 }
711
712 #[inline(always)]
714 pub fn occlude_hit(mut self) -> Self {
715 self.occlude_hit = true;
716 self
717 }
718
719 #[inline(always)]
721 pub fn auto_repeat(mut self) -> Self {
722 self.auto_repeat = true;
723 self
724 }
725
726 #[inline(always)]
728 pub fn on_long_press_raw(mut self, handler: &'a dyn Fn(&mut ActionScope)) -> Self {
729 self.on_long_press = Some(handler);
730 self.focusable = true;
731 self
732 }
733
734 #[inline(always)]
736 pub fn on_long_press(
737 mut self,
738 cx: &'a FrameScope,
739 handler: &'a dyn Fn(crate::pod::ClickEvent, &mut ActionScope),
740 ) -> Self {
741 let wrapped = cx.arena().alloc(move |acx: &mut ActionScope| {
742 let (x, y) = acx.click_position();
743 handler(crate::pod::ClickEvent { x, y }, acx);
744 });
745 self.on_long_press = Some(wrapped);
746 self.focusable = true;
747 self
748 }
749
750 #[inline(always)]
752 pub fn focus_border(mut self, width: u8, color: Color) -> Self {
753 self.focus_border = Some((width, color));
754 self.focusable = true;
755 self
756 }
757
758 #[inline(always)]
760 pub fn no_focus_border(mut self) -> Self {
761 self.focus_border = Some((0, Color::TRANSPARENT));
762 self
763 }
764
765 #[inline(always)]
767 pub fn cursor(mut self, cursor: CursorShape) -> Self {
768 self.cursor = Some(cursor);
769 self
770 }
771
772 #[inline(always)]
774 pub fn focusable(mut self) -> Self {
775 self.focusable = true;
776 self
777 }
778
779 #[inline(always)]
781 pub fn unfocusable(mut self) -> Self {
782 self.focusable = false;
783 self
784 }
785
786 #[inline(always)]
788 pub fn scrollable(mut self, max_scroll: i16) -> Self {
789 self.scrollable_max = Some(max_scroll.max(0));
790 self.clip_children = true;
791 self
792 }
793
794 #[inline(always)]
796 pub fn scrollable_auto(mut self) -> Self {
797 self.scrollable_max = Some(i16::MAX);
798 self.clip_children = true;
799 self
800 }
801
802 #[inline(always)]
804 pub fn align_self(mut self, align: AlignItems) -> Self {
805 self.align_self = Some(align);
806 self
807 }
808
809 #[inline(always)]
811 pub fn self_start(self) -> Self {
812 self.align_self(AlignItems::Start)
813 }
814
815 #[inline(always)]
817 pub fn self_center(self) -> Self {
818 self.align_self(AlignItems::Center)
819 }
820
821 #[inline(always)]
823 pub fn self_end(self) -> Self {
824 self.align_self(AlignItems::End)
825 }
826
827 #[inline(always)]
829 pub fn self_stretch(self) -> Self {
830 self.align_self(AlignItems::Stretch)
831 }
832
833 #[inline(always)]
835 pub fn items_baseline(mut self) -> Self {
836 self.items_baseline = true;
837 self
838 }
839
840 #[inline(always)]
842 pub fn overflow_hidden(mut self) -> Self {
843 self.clip_children = true;
844 self
845 }
846
847 #[inline(always)]
849 pub fn overflow_visible(mut self) -> Self {
850 self.clip_children = false;
851 self
852 }
853
854 #[inline(always)]
856 pub fn overflow_scroll(self) -> Self {
857 self.scrollable_auto()
858 }
859
860 #[inline(always)]
862 pub fn overflow_y_scroll(self) -> Self {
863 self.flex_col().scrollable_auto()
864 }
865
866 #[inline(always)]
868 pub fn overflow_x_scroll(self) -> Self {
869 self.flex_row().scrollable_auto()
870 }
871
872 #[inline(always)]
874 pub fn transition(self) -> Self {
875 self.animate_all(Duration::from_millis(150))
876 }
877
878 #[inline(always)]
880 pub fn transition_colors(self) -> Self {
881 self.animate_color(Duration::from_millis(150))
882 }
883
884 #[inline(always)]
886 pub fn transition_opacity(self) -> Self {
887 self.animate_opacity(Duration::from_millis(150))
888 }
889
890 #[inline(always)]
892 pub fn transition_all(self) -> Self {
893 self.animate_all(Duration::from_millis(150))
894 }
895
896 #[inline(always)]
898 pub fn transition_none(mut self) -> Self {
899 self.transition = None;
900 self
901 }
902
903 #[inline(always)] pub fn duration_75(self) -> Self { self.duration(Duration::from_millis(75)) }
904 #[inline(always)] pub fn duration_100(self) -> Self { self.duration(Duration::from_millis(100)) }
905 #[inline(always)] pub fn duration_150(self) -> Self { self.duration(Duration::from_millis(150)) }
906 #[inline(always)] pub fn duration_200(self) -> Self { self.duration(Duration::from_millis(200)) }
907 #[inline(always)] pub fn duration_300(self) -> Self { self.duration(Duration::from_millis(300)) }
908 #[inline(always)] pub fn duration_500(self) -> Self { self.duration(Duration::from_millis(500)) }
909
910 #[inline(always)] pub fn ease_linear(self) -> Self { self.ease(Easing::Linear) }
911 #[inline(always)] pub fn ease_in(self) -> Self { self.ease(Easing::EaseIn) }
912 #[inline(always)] pub fn ease_out(self) -> Self { self.ease(Easing::EaseOut) }
913 #[inline(always)] pub fn ease_in_out(self) -> Self { self.ease(Easing::EaseInOut) }
914 #[inline(always)] pub fn ease_spring(self) -> Self { self.ease(Easing::Spring) }
915
916 #[inline(always)]
918 pub fn animate_color(mut self, duration: Duration) -> Self {
919 let ms = duration.as_millis().min(u16::MAX as u128) as u16;
920 let mut spec = self.transition.unwrap_or(TransitionSpec {
921 duration_ms: ms,
922 ..TransitionSpec::default()
923 });
924 spec.duration_ms = ms;
925 spec.animate_color = true;
926 self.transition = Some(spec);
927 self
928 }
929
930 #[inline(always)]
932 pub fn animate_bg(self, duration: Duration) -> Self {
933 self.animate_color(duration)
934 }
935
936 #[inline(always)]
938 pub fn animate_bounds(mut self, duration: Duration) -> Self {
939 let ms = duration.as_millis().min(u16::MAX as u128) as u16;
940 let mut spec = self.transition.unwrap_or(TransitionSpec {
941 duration_ms: ms,
942 ..TransitionSpec::default()
943 });
944 spec.duration_ms = ms;
945 spec.animate_bounds = true;
946 self.transition = Some(spec);
947 self
948 }
949
950 #[inline(always)]
952 pub fn ease(mut self, easing: Easing) -> Self {
953 let mut spec = self.transition.unwrap_or_default();
954 spec.easing = easing;
955 self.transition = Some(spec);
956 self
957 }
958
959 #[inline(always)]
961 pub fn repeat_infinite(mut self) -> Self {
962 let mut spec = self.transition.unwrap_or_default();
963 spec.loop_mode = LoopMode::Infinite;
964 self.transition = Some(spec);
965 self
966 }
967
968 #[inline(always)]
970 pub fn repeat_ping_pong(mut self) -> Self {
971 let mut spec = self.transition.unwrap_or_default();
972 spec.loop_mode = LoopMode::PingPong;
973 self.transition = Some(spec);
974 self
975 }
976
977 #[inline(always)]
979 pub fn duration(mut self, duration: Duration) -> Self {
980 let mut spec = self.transition.unwrap_or_default();
981 spec.duration_ms = duration_to_ms(duration);
982 self.transition = Some(spec);
983 self
984 }
985
986 #[inline(always)]
988 pub fn delay(mut self, delay: Duration) -> Self {
989 let mut spec = self.transition.unwrap_or_default();
990 spec.delay_ms = duration_to_ms(delay);
991 self.transition = Some(spec);
992 self
993 }
994
995 #[inline(always)]
997 pub fn animate_opacity(mut self, duration: Duration) -> Self {
998 let mut spec = self.transition.unwrap_or_default();
999 spec.duration_ms = duration_to_ms(duration);
1000 spec.animate_opacity = true;
1001 self.transition = Some(spec);
1002 self
1003 }
1004
1005 #[inline(always)]
1007 pub fn animate_all(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_color = true;
1011 spec.animate_bounds = true;
1012 spec.animate_opacity = true;
1013 self.transition = Some(spec);
1014 self
1015 }
1016
1017 #[inline(always)]
1019 pub fn enter_from(mut self, opacity: u8, dx: i16, dy: i16, duration: Duration) -> Self {
1020 let mut spec = self.transition.unwrap_or_default();
1021 spec.duration_ms = duration_to_ms(duration);
1022 spec.enter = Some(EnterFrom { opacity, dx, dy });
1023 self.transition = Some(spec);
1024 self
1025 }
1026
1027 #[inline(always)]
1029 pub fn fade_in(self, duration: Duration) -> Self {
1030 self.enter_from(0, 0, 0, duration)
1031 }
1032
1033 #[inline(always)]
1035 pub fn slide_in(self, dx: i16, dy: i16, duration: Duration) -> Self {
1036 self.enter_from(0, dx, dy, duration)
1037 }
1038
1039 #[inline(always)]
1041 pub fn ping_pong_bg(mut self, from_bg: Color, duration: Duration) -> Self {
1042 let ms = duration.as_millis().min(u16::MAX as u128) as u16;
1043 let mut spec = self.transition.unwrap_or_default();
1044 spec.duration_ms = ms;
1045 spec.animate_color = true;
1046 spec.loop_mode = LoopMode::PingPong;
1047 spec.easing = Easing::EaseInOut;
1048 spec.pulse_from_bg = Some(from_bg);
1049 self.transition = Some(spec);
1050 self
1051 }
1052
1053 #[inline(always)]
1055 pub fn on_click_raw(mut self, handler: &'a dyn Fn(&mut ActionScope)) -> Self {
1056 self.on_click = Some(handler);
1057 self.focusable = true;
1058 self
1059 }
1060
1061 #[inline(always)]
1063 pub fn on_click(
1064 mut self,
1065 cx: &'a FrameScope,
1066 handler: &'a dyn Fn(crate::pod::ClickEvent, &mut ActionScope),
1067 ) -> Self {
1068 let wrapped = cx.arena().alloc(move |acx: &mut ActionScope| {
1069 let (x, y) = acx.click_position();
1070 handler(crate::pod::ClickEvent { x, y }, acx);
1071 });
1072 self.on_click = Some(wrapped);
1073 self.focusable = true;
1074 self
1075 }
1076
1077 #[inline(always)]
1079 pub fn on_secondary_click_raw(mut self, handler: &'a dyn Fn(&mut ActionScope)) -> Self {
1080 self.on_secondary_click = Some(handler);
1081 self
1082 }
1083
1084 #[inline(always)]
1086 pub fn on_secondary_click(
1087 mut self,
1088 cx: &'a FrameScope,
1089 handler: &'a dyn Fn(crate::pod::ClickEvent, &mut ActionScope),
1090 ) -> Self {
1091 let wrapped = cx.arena().alloc(move |acx: &mut ActionScope| {
1092 let (x, y) = acx.click_position();
1093 handler(crate::pod::ClickEvent { x, y }, acx);
1094 });
1095 self.on_secondary_click = Some(wrapped);
1096 self
1097 }
1098
1099 #[inline(always)]
1101 pub fn on_drag_raw(mut self, handler: &'a dyn Fn(&mut ActionScope)) -> Self {
1102 self.on_drag = Some(handler);
1103 self
1104 }
1105
1106 #[inline(always)]
1108 pub fn on_drag(
1109 mut self,
1110 cx: &'a FrameScope,
1111 handler: &'a dyn Fn(DragEvent, &mut ActionScope),
1112 ) -> Self {
1113 let wrapped = cx.arena().alloc(move |acx: &mut ActionScope| {
1114 let ev = acx.drag_event();
1115 handler(ev, acx);
1116 });
1117 self.on_drag = Some(wrapped);
1118 self
1119 }
1120
1121 #[inline(always)]
1123 pub fn on_hover_raw(mut self, handler: &'a dyn Fn(bool, &mut ActionScope)) -> Self {
1124 self.on_hover = Some(handler);
1125 self
1126 }
1127
1128 #[inline(always)]
1130 pub fn on_hover(
1131 mut self,
1132 _cx: &'a FrameScope,
1133 handler: &'a dyn Fn(bool, &mut ActionScope),
1134 ) -> Self {
1135 self.on_hover = Some(handler);
1136 self
1137 }
1138
1139 #[inline(always)]
1141 pub fn on_pointer_move_raw(mut self, handler: &'a dyn Fn(&mut ActionScope)) -> Self {
1142 self.on_pointer_move = Some(handler);
1143 self
1144 }
1145
1146 #[inline(always)]
1148 pub fn on_pointer_move(
1149 mut self,
1150 cx: &'a FrameScope,
1151 handler: &'a dyn Fn(DragEvent, &mut ActionScope),
1152 ) -> Self {
1153 let wrapped = cx.arena().alloc(move |acx: &mut ActionScope| {
1154 let ev = acx.drag_event();
1155 handler(ev, acx);
1156 });
1157 self.on_pointer_move = Some(wrapped);
1158 self
1159 }
1160
1161 #[inline(always)]
1163 pub fn on_swipe(
1164 mut self,
1165 _cx: &'a FrameScope,
1166 handler: &'a dyn Fn(crate::pod::SwipeDir, &mut ActionScope),
1167 ) -> Self {
1168 self.on_swipe = Some(handler);
1169 self
1170 }
1171
1172 #[inline(always)]
1174 pub fn key(mut self, key: impl AsRef<[u8]>) -> Self {
1175 let mut h: u32 = 0x811c_9dc5;
1176 for &b in key.as_ref() {
1177 h ^= b as u32;
1178 h = h.wrapping_mul(0x0100_0193);
1179 }
1180 self.id = Some(h | 1);
1181 self
1182 }
1183
1184 #[inline(always)]
1186 pub fn z_index(mut self, z: i8) -> Self {
1187 self.z_index = z;
1188 self
1189 }
1190
1191 #[inline(always)]
1193 pub fn on_key_input(
1194 mut self,
1195 handler: &'a dyn Fn(crate::pod::KeyCode, &mut ActionScope),
1196 ) -> Self {
1197 self.on_key_input = Some(handler);
1198 self.focusable = true;
1199 self
1200 }
1201
1202 #[inline(always)]
1204 pub fn on_key_nav(
1205 mut self,
1206 handler: &'a dyn Fn(crate::pod::KeyCode, &mut ActionScope),
1207 ) -> Self {
1208 self.on_key_nav = Some(handler);
1209 self
1210 }
1211
1212 #[inline(always)]
1214 pub fn on_navigate_back(
1215 mut self,
1216 handler: &'a dyn Fn(&mut ActionScope),
1217 ) -> Self {
1218 self.on_navigate_back = Some(handler);
1219 self
1220 }
1221
1222 #[inline(always)]
1224 pub fn shadow(mut self, blur: u8, offset_x: i8, offset_y: i8, color: Color) -> Self {
1225 if blur > 0 && color.a() > 0 {
1226 self.shadow = Some((blur.min(64), offset_x, offset_y, color));
1227 }
1228 self
1229 }
1230
1231 #[inline(always)]
1233 pub fn grid(mut self, cols: u8) -> Self {
1234 self.grid_cols = cols.max(1);
1235 self
1236 }
1237
1238 pub fn child(mut self, cx: &'a FrameScope, child: impl IntoElement<'a>) -> Self {
1240 let elem = child.into_element(cx);
1241 let node: &'a ElementNode<'a> = cx.arena().alloc_temp(ElementNode {
1242 element: elem,
1243 next_sibling: Cell::new(None),
1244 });
1245 if let Some(last) = self.last_child {
1246 last.next_sibling.set(Some(node));
1247 } else {
1248 self.first_child = Some(node);
1249 }
1250 self.last_child = Some(node);
1251 self
1252 }
1253
1254 #[inline(always)]
1256 pub fn child_opt(self, cx: &'a FrameScope, child: Option<impl IntoElement<'a>>) -> Self {
1257 match child {
1258 Some(c) => self.child(cx, c),
1259 None => self,
1260 }
1261 }
1262
1263 pub fn children<I, E>(mut self, cx: &'a FrameScope, iter: I) -> Self
1265 where
1266 I: IntoIterator<Item = E>,
1267 E: IntoElement<'a>,
1268 {
1269 for item in iter {
1270 self = self.child(cx, item);
1271 }
1272 self
1273 }
1274
1275 #[inline(always)]
1277 pub fn justify_start_localized(mut self, cx: &FrameScope) -> Self {
1278 if cx.is_rtl() {
1279 self.style.set_justify(crate::style::Justify::End);
1280 } else {
1281 self.style.set_justify(crate::style::Justify::Start);
1282 }
1283 self
1284 }
1285
1286 #[inline(always)]
1288 pub fn justify_end_localized(mut self, cx: &FrameScope) -> Self {
1289 if cx.is_rtl() {
1290 self.style.set_justify(crate::style::Justify::Start);
1291 } else {
1292 self.style.set_justify(crate::style::Justify::End);
1293 }
1294 self
1295 }
1296
1297 #[inline(always)]
1299 pub fn ps(self, cx: &FrameScope, px: i8) -> Self {
1300 if cx.is_rtl() {
1301 self.pr(px)
1302 } else {
1303 self.pl(px)
1304 }
1305 }
1306
1307 #[inline(always)]
1309 pub fn pe(self, cx: &FrameScope, px: i8) -> Self {
1310 if cx.is_rtl() {
1311 self.pl(px)
1312 } else {
1313 self.pr(px)
1314 }
1315 }
1316
1317 #[inline(always)]
1319 pub fn ms(self, cx: &FrameScope, px: i16) -> Self {
1320 if cx.is_rtl() {
1321 self.mr(px)
1322 } else {
1323 self.ml(px)
1324 }
1325 }
1326
1327 #[inline(always)]
1329 pub fn me(self, cx: &FrameScope, px: i16) -> Self {
1330 if cx.is_rtl() {
1331 self.ml(px)
1332 } else {
1333 self.mr(px)
1334 }
1335 }
1336
1337 #[inline(always)]
1343 pub fn rounded_corners(mut self, radii: CornerRadii) -> Self {
1344 self.effects.corner_radii = Some(radii);
1345 self
1346 }
1347
1348 #[inline(always)]
1350 pub fn rounded_t(self, r: u8) -> Self {
1351 self.rounded_corners(CornerRadii::top(r))
1352 }
1353
1354 #[inline(always)]
1356 pub fn rounded_b(self, r: u8) -> Self {
1357 self.rounded_corners(CornerRadii::bottom(r))
1358 }
1359
1360 #[inline(always)]
1362 pub fn rounded_l(self, r: u8) -> Self {
1363 self.rounded_corners(CornerRadii::left(r))
1364 }
1365
1366 #[inline(always)]
1368 pub fn rounded_r(self, r: u8) -> Self {
1369 self.rounded_corners(CornerRadii::right(r))
1370 }
1371
1372 #[inline(always)]
1374 pub fn bg_paint(mut self, paint: Paint<'a>) -> Self {
1375 self.effects.bg_paint = Some(paint);
1376 self
1377 }
1378
1379 #[inline]
1381 pub fn bg_linear_gradient(
1382 mut self,
1383 cx: &'a FrameScope,
1384 angle_deg: f32,
1385 stops: &[ColorStop],
1386 ) -> Self {
1387 let arena_stops = cx.arena().alloc_iter(stops.iter().copied());
1388 self.effects.bg_paint = Some(Paint::linear_angle(angle_deg, arena_stops));
1389 self
1390 }
1391
1392 #[inline]
1394 pub fn bg_radial_gradient(mut self, cx: &'a FrameScope, stops: &[ColorStop]) -> Self {
1395 let arena_stops = cx.arena().alloc_iter(stops.iter().copied());
1396 self.effects.bg_paint = Some(Paint::radial(arena_stops));
1397 self
1398 }
1399
1400 #[inline]
1402 pub fn bg_radial_focal_gradient(
1403 mut self,
1404 cx: &'a FrameScope,
1405 center: [f32; 2],
1406 radius: f32,
1407 focal: [f32; 2],
1408 focal_radius: f32,
1409 stops: &[ColorStop],
1410 ) -> Self {
1411 let arena_stops = cx.arena().alloc_iter(stops.iter().copied());
1412 self.effects.bg_paint = Some(Paint::radial_focal(
1413 center,
1414 radius,
1415 focal,
1416 focal_radius,
1417 arena_stops,
1418 ));
1419 self
1420 }
1421
1422 #[inline]
1424 pub fn bg_conic_gradient(
1425 mut self,
1426 cx: &'a FrameScope,
1427 start_angle_deg: f32,
1428 stops: &[ColorStop],
1429 ) -> Self {
1430 let arena_stops = cx.arena().alloc_iter(stops.iter().copied());
1431 self.effects.bg_paint = Some(Paint::conic(start_angle_deg, arena_stops));
1432 self
1433 }
1434
1435 #[inline]
1437 pub fn bg_gradient_extend(mut self, mode: ExtendMode) -> Self {
1438 if let Some(p) = self.effects.bg_paint {
1439 self.effects.bg_paint = Some(p.with_extend(mode));
1440 }
1441 self
1442 }
1443
1444 #[inline]
1446 pub fn bg_gradient_space(mut self, space: GradientSpace) -> Self {
1447 if let Some(p) = self.effects.bg_paint {
1448 self.effects.bg_paint = Some(p.with_space(space));
1449 }
1450 self
1451 }
1452
1453 #[inline(always)]
1455 pub fn blend_mode(mut self, mode: BlendMode) -> Self {
1456 self.effects.blend_mode = mode;
1457 self
1458 }
1459
1460 #[inline(always)]
1462 pub fn isolate(mut self) -> Self {
1463 self.effects.isolate = true;
1464 self
1465 }
1466
1467 #[inline(always)]
1469 pub fn filter(mut self, filter: LayerFilter) -> Self {
1470 self.effects.filter = filter;
1471 self
1472 }
1473
1474 #[inline(always)]
1476 pub fn blur(mut self, radius: u8) -> Self {
1477 self.effects.filter.blur_radius = radius;
1478 self
1479 }
1480
1481 #[inline]
1483 pub fn color_matrix(mut self, matrix: ColorMatrix) -> Self {
1484 self.effects.filter.color_matrix = Some(match self.effects.filter.color_matrix {
1485 Some(prev) => prev.then(matrix),
1486 None => matrix,
1487 });
1488 self
1489 }
1490
1491 #[inline]
1493 pub fn grayscale(self, amount: f32) -> Self {
1494 self.color_matrix(ColorMatrix::grayscale(amount))
1495 }
1496
1497 #[inline]
1499 pub fn sepia(self, amount: f32) -> Self {
1500 self.color_matrix(ColorMatrix::sepia(amount))
1501 }
1502
1503 #[inline]
1505 pub fn saturate(self, amount: f32) -> Self {
1506 self.color_matrix(ColorMatrix::saturate(amount))
1507 }
1508
1509 #[inline]
1511 pub fn brightness(self, amount: f32) -> Self {
1512 self.color_matrix(ColorMatrix::brightness(amount))
1513 }
1514
1515 #[inline]
1517 pub fn contrast(self, amount: f32) -> Self {
1518 self.color_matrix(ColorMatrix::contrast(amount))
1519 }
1520
1521 #[inline]
1523 pub fn hue_rotate(self, deg: f32) -> Self {
1524 self.color_matrix(ColorMatrix::hue_rotate(deg))
1525 }
1526
1527 #[inline]
1529 pub fn invert(self, amount: f32) -> Self {
1530 self.color_matrix(ColorMatrix::invert(amount))
1531 }
1532
1533 #[inline(always)]
1535 pub fn drop_shadow(mut self, blur: u8, offset_x: i8, offset_y: i8, color: Color) -> Self {
1536 self.effects.filter.drop_shadow = Some(DropShadow::new(blur, offset_x, offset_y, color));
1537 self
1538 }
1539
1540 #[inline(always)]
1542 pub fn backdrop_filter(mut self, filter: BackdropFilter) -> Self {
1543 self.effects.backdrop_filter = filter;
1544 self
1545 }
1546
1547 #[inline(always)]
1549 pub fn backdrop_blur(mut self, radius: u8) -> Self {
1550 self.effects.backdrop_filter.blur_radius = radius;
1551 self
1552 }
1553
1554 #[inline]
1556 pub fn backdrop_acrylic(mut self, blur_radius: u8, tint: Color) -> Self {
1557 self.effects.backdrop_filter = BackdropFilter::acrylic(blur_radius, tint);
1558 self
1559 }
1560
1561 #[inline]
1563 pub fn transform(mut self, t: Transform2D) -> Self {
1564 self.effects.transform = Some(match self.effects.transform {
1565 Some(prev) => prev.concat(t),
1566 None => t,
1567 });
1568 self
1569 }
1570
1571 #[inline]
1573 pub fn rotate_deg(self, deg: f32) -> Self {
1574 self.transform(Transform2D::rotate(deg))
1575 }
1576
1577 #[inline]
1579 pub fn scale(self, sx: f32, sy: f32) -> Self {
1580 self.transform(Transform2D::scale(sx, sy))
1581 }
1582
1583 #[inline]
1585 pub fn translate(self, tx: f32, ty: f32) -> Self {
1586 self.transform(Transform2D::translate(tx, ty))
1587 }
1588
1589 #[inline]
1591 pub fn skew(self, ax_deg: f32, ay_deg: f32) -> Self {
1592 let mut s = self;
1593 if ax_deg != 0.0 {
1594 s = s.transform(Transform2D::skew_x(ax_deg));
1595 }
1596 if ay_deg != 0.0 {
1597 s = s.transform(Transform2D::skew_y(ay_deg));
1598 }
1599 s
1600 }
1601
1602 #[inline(always)]
1604 pub fn clip_path(mut self, path_d: &'static str) -> Self {
1605 self.effects.clip_path = Some(StrRef::Static(path_d));
1606 self
1607 }
1608
1609 #[inline]
1611 pub fn clip_path_str(mut self, cx: &'a FrameScope, path_d: &str) -> Self {
1612 let buf = cx.arena().alloc_bytes(path_d.len());
1613 buf.copy_from_slice(path_d.as_bytes());
1614 let s = unsafe { core::str::from_utf8_unchecked(buf) };
1616 self.effects.clip_path = Some(StrRef::Scratch(s));
1617 self
1618 }
1619
1620 #[inline(always)]
1625 pub fn external_texture(mut self, id: crate::paint::ExternalTextureId) -> Self {
1626 self.external_texture = Some(crate::paint::ExternalTextureSpec::new(id));
1627 self
1628 }
1629
1630 #[inline(always)]
1632 pub fn external_texture_spec(mut self, spec: crate::paint::ExternalTextureSpec) -> Self {
1633 self.external_texture = Some(spec);
1634 self
1635 }
1636
1637 #[inline(always)]
1639 pub fn external_texture_uv(mut self, uv_rect: [f32; 4]) -> Self {
1640 if let Some(ext) = &mut self.external_texture {
1641 ext.uv_rect = uv_rect;
1642 }
1643 self
1644 }
1645
1646 #[inline(always)]
1648 pub fn external_texture_revision(mut self, revision: u64) -> Self {
1649 if let Some(ext) = &mut self.external_texture {
1650 ext.content_revision = revision;
1651 }
1652 self
1653 }
1654
1655 #[inline(always)]
1657 pub fn external_texture_format(mut self, premultiplied: bool, fallback_bg: Color) -> Self {
1658 if let Some(ext) = &mut self.external_texture {
1659 ext.premultiplied = premultiplied;
1660 ext.fallback_bg = fallback_bg;
1661 }
1662 self
1663 }
1664
1665 #[inline(always)]
1667 pub fn aspect_ratio(mut self, ratio: f32) -> Self {
1668 self.layout_ext.aspect_ratio = ratio.max(0.0);
1669 self
1670 }
1671
1672 #[inline(always)]
1674 pub fn grid_col_span(mut self, span: u8) -> Self {
1675 self.layout_ext.grid_col_span = span.max(1);
1676 self
1677 }
1678
1679 #[inline]
1681 pub fn grid_template_fr(mut self, cx: &'a FrameScope, weights: &[u16]) -> Self {
1682 if !weights.is_empty() {
1683 self.grid_cols = weights.len().min(u8::MAX as usize) as u8;
1684 self.layout_ext.grid_template_fr = cx.arena().alloc_iter(weights.iter().copied());
1685 }
1686 self
1687 }
1688
1689 #[inline(always)]
1691 pub fn sticky_top(mut self, offset: i16) -> Self {
1692 self.layout_ext.sticky_top = Some(offset);
1693 self
1694 }
1695
1696 #[inline(always)]
1698 pub fn rtl(mut self, rtl: bool) -> Self {
1699 self.layout_ext.rtl = rtl;
1700 self
1701 }
1702
1703 #[inline(always)]
1705 pub fn rtl_auto(mut self, cx: &FrameScope) -> Self {
1706 self.layout_ext.rtl = cx.is_rtl();
1707 self
1708 }
1709
1710 #[inline(always)]
1712 pub fn overflow_auto(mut self) -> Self {
1713 self.scrollable_max = Some(i16::MAX);
1714 self.clip_children = true;
1715 self
1716 }
1717
1718 #[inline(always)]
1720 pub fn scroll_chaining(mut self, enable: bool) -> Self {
1721 self.layout_ext.scroll_chaining = enable;
1722 self
1723 }
1724}
1725