1use std::sync::Arc;
9
10use super::{
11 Accessible, AnyElement, Interactive, IntoReactive,
12 builder::{ElNode, Element, IntoElement, IntoListener, Listener, ParentElement},
13 events::{
14 self, CaretEvent, Composition, NativeEvent, OverlayPosition, Selection, VideoInfo,
15 VideoProgress, WebNavigation,
16 },
17};
18use crate::{
19 AudioSession, AutoCapitalize, AutoFill, Color, EventKind, HeaderSlot, Hsla, JsonValue,
20 KeyboardAppearance, KeyboardType, ModalAnimation, ModalPresentation, ModalProp, NativeProp,
21 OverlayProp, PasteBehavior, PasteEvent, Points, Prop, ResizeMode, ReturnKeyType, Rgba,
22 ScreenAnimation, ScreenProp, ScrollProp, Size, StatusBarSetting, SubmitBehavior, Tag,
23 WebSource,
24 canvas::{
25 CanvasFont, CanvasGradient, CanvasImage, CanvasOp, CanvasTextAlign, CanvasTextBaseline,
26 Composite, Drawing, FillRule, LineCap, LineJoin, Num, Paint, Path, PathOp, ViewPaint,
27 },
28 geometry::{Bounds, Corners, Percentage, Point, Radians, ScaledPixels},
29 js::host::HostProps,
30 overlay::{Align, OverlayAnchor, Placement},
31 style::SvgPaint,
32};
33
34pub(crate) fn same_kind(a: &Prop, b: &Prop) -> bool {
36 match (a, b) {
37 (Prop::ComponentProp(a, _), Prop::ComponentProp(b, _)) => a == b,
38 (Prop::ComponentPropBinding(a, _), Prop::ComponentPropBinding(b, _)) => a == b,
39 (Prop::RustProp(a, _), Prop::RustProp(b, _)) => a == b,
40 _ => HostProps::same_kind(a, b),
41 }
42}
43
44pub(crate) fn reset(prop: &Prop) -> Option<Prop> {
47 match prop {
48 Prop::ComponentProp(name, _) => Some(Prop::ComponentProp(name.clone(), None)),
49 Prop::ComponentPropBinding(name, _) => Some(Prop::ComponentPropBinding(name.clone(), None)),
50 Prop::RustProp(name, _) => Some(Prop::RustProp(name, None)),
51 _ => HostProps::reset(prop),
52 }
53}
54
55pub(crate) fn set(node: &mut ElNode, prop: Prop) {
57 set_in(&mut node.attrs.props, prop);
58}
59
60crate::static_reactive!(Color: Color);
61crate::static_reactive!(Hsla: Hsla, Rgba, Color);
62crate::static_reactive!(crate::AccessibilityRole: crate::AccessibilityRole);
63crate::static_reactive!(AutoCapitalize: AutoCapitalize);
64crate::static_reactive!(AutoFill: AutoFill);
65crate::static_reactive!(crate::HeaderSystemItem: crate::HeaderSystemItem);
66crate::static_reactive!(KeyboardAppearance: KeyboardAppearance);
67crate::static_reactive!(KeyboardType: KeyboardType);
68crate::static_reactive!(ModalAnimation: ModalAnimation);
69crate::static_reactive!(ModalPresentation: ModalPresentation);
70crate::static_reactive!(ResizeMode: ResizeMode);
71crate::static_reactive!(ReturnKeyType: ReturnKeyType);
72crate::static_reactive!(SubmitBehavior: SubmitBehavior);
73crate::static_reactive!(PasteBehavior: PasteBehavior);
74crate::static_reactive!(crate::EllipsizeMode: crate::EllipsizeMode);
75crate::static_reactive!(JsonValue: JsonValue);
76crate::static_reactive!(StatusBarSetting: StatusBarSetting, crate::StatusBarStyle);
77crate::static_reactive!(Placement: Placement);
78crate::static_reactive!(Align: Align);
79
80pub(crate) fn set_in(props: &mut Vec<Prop>, prop: Prop) {
82 match props.iter_mut().find(|p| same_kind(p, &prop)) {
83 Some(p) => *p = prop,
84 None => props.push(prop),
85 }
86}
87
88pub(crate) fn bind_prop<T: 'static>(
91 node: &mut ElNode,
92 value: impl IntoReactive<T>,
93 prop: impl Fn(T) -> Prop + 'static,
94) {
95 node.bind_attr(value, move |attrs, v| set_in(&mut attrs.props, prop(v)));
96}
97
98fn listen<T: ?Sized + ToOwned + 'static>(
100 node: &mut ElNode,
101 kind: EventKind,
102 listener: Listener<T>,
103 decode: events::Decode<T>,
104) {
105 node.handlers.push((kind, events::typed(listener, decode)));
106}
107
108macro_rules! host_element {
109 ($(#[$doc:meta])* $name:ident) => {
110 $(#[$doc])*
111 #[derive(Clone)]
112 pub struct $name(ElNode);
113
114 impl Element for $name {
115 fn node(&mut self) -> &mut ElNode {
116 &mut self.0
117 }
118 }
119
120 impl IntoElement for $name {
121 fn into_element(self) -> AnyElement {
122 AnyElement(self.0)
123 }
124 }
125
126 impl Accessible for $name {}
127 impl Interactive for $name {}
128
129 impl super::builder::IntoTooltip for $name {
130 fn apply_tooltip(self, node: &mut ElNode) {
131 self.into_element().apply_tooltip(node);
132 }
133 }
134
135 #[allow(dead_code)]
137 impl $name {
138 fn set(mut self, prop: Prop) -> Self {
139 set(&mut self.0, prop);
140 self
141 }
142
143 fn bind_prop<T: 'static>(
144 mut self,
145 value: impl IntoReactive<T>,
146 prop: impl Fn(T) -> Prop + 'static,
147 ) -> Self {
148 bind_prop(&mut self.0, value, prop);
149 self
150 }
151
152 fn listen<T: ?Sized + ToOwned + 'static>(
153 mut self,
154 kind: EventKind,
155 listener: Listener<T>,
156 decode: events::Decode<T>,
157 ) -> Self {
158 listen(&mut self.0, kind, listener, decode);
159 self
160 }
161 }
162 };
163}
164
165host_element! {
166 Input
169}
170
171host_element! {
172 Scroll
175}
176
177host_element! {
178 Stack
184}
185
186host_element! {
187 Screen
191}
192
193host_element! {
194 Modal
198}
199
200host_element! {
201 InputAccessoryView
205}
206
207host_element! {
208 CanvasView
210}
211
212host_element! {
213 Svg
215}
216
217host_element! {
218 ShaderView
221}
222
223host_element! {
224 WebView
226}
227
228host_element! {
229 Video
231}
232
233host_element! {
234 NativeView
237}
238
239host_element! {
240 Overlay
245}
246
247impl ParentElement for Overlay {}
248impl ParentElement for ShaderView {}
249impl ParentElement for Scroll {}
250impl ParentElement for Stack {}
251impl ParentElement for Screen {}
252impl ParentElement for Modal {}
253
254impl ParentElement for InputAccessoryView {
256 fn child<M>(mut self, child: impl super::IntoChild<M>) -> Self {
257 if !cfg!(target_os = "android") {
258 child.__push_into(&mut self.0.children);
259 }
260 self
261 }
262
263 fn children(mut self, children: impl IntoIterator<Item = impl IntoElement>) -> Self {
264 if !cfg!(target_os = "android") {
265 self.0
266 .children
267 .extend(children.into_iter().map(|c| c.into_element().0));
268 }
269 self
270 }
271}
272
273pub fn overlay() -> Overlay {
281 Overlay(ElNode::new(Tag::Overlay))
282}
283
284pub fn input() -> Input {
286 Input(ElNode::new(Tag::Input))
287}
288
289pub fn scroll() -> Scroll {
291 Scroll(ElNode::new(Tag::Scroll))
292}
293
294#[doc(hidden)]
300pub fn stack() -> Stack {
301 Stack(ElNode::new(Tag::Stack))
302}
303
304#[doc(hidden)]
309pub fn screen() -> Screen {
310 let mut node = ElNode::new(Tag::Screen);
311 node.handlers.push((EventKind::Insets, Listener::noop()));
313 Screen(node)
314}
315
316#[doc(hidden)]
321pub fn modal() -> Modal {
322 let mut node = ElNode::new(Tag::Modal);
323 node.handlers.push((EventKind::Insets, Listener::noop()));
325 Modal(node)
326}
327
328pub fn input_accessory_view(native_id: &str) -> InputAccessoryView {
334 let tag = if cfg!(target_os = "android") {
335 Tag::View
336 } else {
337 Tag::InputAccessory
338 };
339 let mut node = ElNode::new(tag);
340 if cfg!(target_os = "android") {
341 node.style.value(
342 crate::StyleKey::Display,
343 crate::PropertyValue::Display(taffy::Display::None),
344 );
345 } else {
346 set(&mut node, Prop::NativeId(Some(native_id.into())));
347 }
348 InputAccessoryView(node)
349}
350
351pub fn canvas(painter: impl IntoReactive<Painter>) -> CanvasView {
356 let mut node = ElNode::new(Tag::Canvas);
357 node.bind_attr(painter, |attrs, painter: Painter| {
358 attrs.drawing = Some(Arc::new(painter.drawing));
359 attrs.bound = painter.nodes;
360 });
361 CanvasView(node)
362}
363
364crate::static_reactive!(Painter: Painter, Drawing);
365
366pub fn svg(src: impl IntoReactive<super::ImageSrc>) -> Svg {
386 #[cfg(all(feature = "svg", not(target_arch = "wasm32")))]
387 {
388 let mut node = ElNode::new(Tag::Canvas);
389 let shown = svg_drawing(src);
390 node.bind_attr(
391 move || shown.get(),
392 |attrs, drawing| attrs.drawing = drawing,
393 );
394 Svg(node)
395 }
396 #[cfg(not(all(feature = "svg", not(target_arch = "wasm32"))))]
397 {
398 let mut node = ElNode::new(Tag::Image);
399 node.style.value(
400 crate::StyleKey::ObjectFit,
401 crate::PropertyValue::ObjectFit(Some(ResizeMode::Contain)),
402 );
403 node.bind_attr(src, |attrs, src| attrs.src = Some(src));
404 Svg(node)
405 }
406}
407
408#[cfg(all(feature = "svg", not(target_arch = "wasm32")))]
413fn svg_drawing(
414 src: impl IntoReactive<super::ImageSrc>,
415) -> super::reactive::Signal<Option<Arc<Drawing>>> {
416 use super::reactive::{SignalEquals, render_effect, signal_with, stored, untracked};
417 let src = src.into_reactive();
418 let shown = signal_with(None::<Arc<Drawing>>, SignalEquals::Never);
419 let lease = stored(crate::image::Lease::none());
420 let task = stored(None::<super::Spawned<()>>);
421 render_effect(move || {
422 let src = match &src {
423 super::Reactive::Static(src) => src.clone(),
424 super::Reactive::Bound(f) => f(),
425 };
426 untracked(|| {
427 drop(task.replace(None));
428 let context = crate::image::loader::context();
429 let source = crate::ImageSource {
430 uri: src.uri.as_str().into(),
431 size: None,
432 scales: crate::ImageScales::NONE,
433 data: None,
434 }
435 .inline();
436 let Some(location) = context.locate(&source) else {
437 log::warn!("svg: unsupported source `{}`", source.uri);
438 shown.set(None);
439 lease.replace(crate::image::Lease::none());
440 return;
441 };
442 if let Some((drawing, held)) = crate::svg::drawings::now(&location) {
443 shown.set(Some(drawing));
444 lease.replace(held);
445 return;
446 }
447 let load = crate::svg::drawings::load(location, context);
448 task.replace(Some(super::spawn(async move {
449 let (drawing, held) = load.await;
450 shown.set(Some(drawing));
451 lease.replace(held);
452 })));
453 });
454 });
455 shown
456}
457
458pub fn shader() -> ShaderView {
462 ShaderView(ElNode::new(Tag::Shader))
463}
464
465pub fn shader_effect() -> ShaderView {
469 ShaderView(ElNode::new(Tag::ShaderEffect))
470}
471
472pub fn shader_transition() -> ShaderView {
477 ShaderView(ElNode::new(Tag::ShaderTransition))
478}
479
480pub fn screen_effect() -> ShaderView {
483 ShaderView(ElNode::new(Tag::ScreenEffect))
484}
485
486pub fn screen_transition() -> ShaderView {
490 ShaderView(ElNode::new(Tag::ScreenTransition))
491}
492
493crate::static_reactive!(crate::shader::Shader: crate::shader::Shader);
494
495pub struct Uniform(UniformSource);
497
498enum UniformSource {
499 Value(super::Reactive<crate::shader::UniformValue>),
500 Animated(super::AnimatedNode),
501}
502
503pub trait IntoUniform {
506 fn into_uniform(self) -> Uniform;
508}
509
510impl<T: IntoReactive<crate::shader::UniformValue>> IntoUniform for T {
511 fn into_uniform(self) -> Uniform {
512 Uniform(UniformSource::Value(self.into_reactive()))
513 }
514}
515
516impl IntoUniform for &super::AnimatedValue {
517 fn into_uniform(self) -> Uniform {
518 Uniform(UniformSource::Animated(super::Animated::animated_node(
519 self,
520 )))
521 }
522}
523
524impl IntoUniform for &super::AnimatedNode {
525 fn into_uniform(self) -> Uniform {
526 Uniform(UniformSource::Animated(*self))
527 }
528}
529crate::static_reactive!(
530 crate::shader::UniformValue: crate::shader::UniformValue,
531 f32,
532 i32,
533 Color,
534 Hsla,
535 [f32; 2],
536 [f32; 3],
537 [f32; 4],
538 Vec<crate::shader::UniformValue>
539);
540
541impl ShaderView {
542 pub fn source(self, shader: impl IntoReactive<crate::shader::Shader>) -> Self {
546 self.bind_prop(shader, |s| Prop::Shader(Some(s)))
547 }
548
549 pub fn uniform(mut self, name: &str, value: impl IntoUniform) -> Self {
556 let name: Arc<str> = name.into();
557 let value = match value.into_uniform().0 {
558 UniformSource::Value(value) => value,
559 UniformSource::Animated(node) => {
560 let value = match node.live() {
561 Some(node) => {
562 let id = node.id();
563 self.0.attrs.bound.push(node);
564 crate::shader::UniformValue::Animated(id)
565 }
566 None => crate::shader::UniformValue::Number(0.0),
567 };
568 super::Reactive::Static(value)
569 }
570 };
571 self.0.bind_attr(value, move |attrs, value| {
572 let mut uniforms = attrs
573 .props
574 .iter()
575 .find_map(|p| match p {
576 Prop::Uniforms(u) => Some(u.clone()),
577 _ => None,
578 })
579 .unwrap_or_default();
580 match uniforms.0.iter_mut().find(|(n, _)| *n == name) {
581 Some(entry) => entry.1 = value,
582 None => uniforms.0.push((name.clone(), value)),
583 }
584 set_in(&mut attrs.props, Prop::Uniforms(uniforms));
585 });
586 self
587 }
588
589 pub fn paused(self, paused: impl IntoReactive<bool>) -> Self {
591 self.bind_prop(paused, Prop::ShaderPaused)
592 }
593
594 pub fn progress(self, progress: impl IntoReactive<Percentage>) -> Self {
597 self.bind_prop(progress, |p| {
598 Prop::ShaderProgress(crate::shader::ShaderProgress::Number(p))
599 })
600 }
601
602 pub fn animated_progress(mut self, value: &impl super::Animated) -> Self {
605 let progress = match value.animated_node().live() {
606 Some(node) => {
607 let id = node.id();
608 self.0.attrs.bound.push(node);
609 crate::shader::ShaderProgress::Animated(id)
610 }
611 None => crate::shader::ShaderProgress::Number(Percentage(0.0)),
612 };
613 self.set(Prop::ShaderProgress(progress))
614 }
615
616 pub fn max_sample_offset(self, offset: Points) -> Self {
619 self.set(Prop::MaxSampleOffset(offset))
620 }
621
622 pub fn value(self, value: impl IntoReactive<crate::shader::TransitionKey>) -> Self {
625 self.bind_prop(value, |v| Prop::TransitionValue(Some(v)))
626 }
627
628 pub fn duration(self, duration: std::time::Duration) -> Self {
630 self.set(Prop::TransitionDuration(Some(
631 duration.as_secs_f32() * 1000.0,
632 )))
633 }
634
635 pub fn fallback(self, fallback: crate::TransitionFallback) -> Self {
638 self.set(Prop::TransitionFallback(fallback))
639 }
640}
641
642crate::static_reactive!(crate::shader::TransitionKey: crate::shader::TransitionKey);
643
644pub fn web_view(url: impl IntoReactive<String>) -> WebView {
646 WebView(ElNode::new(Tag::WebView)).bind_prop(url, |url: String| {
647 Prop::Native(NativeProp::Source(WebSource::Uri(url.into())))
648 })
649}
650
651pub fn web_view_html(html: impl IntoReactive<String>, base_url: Option<&str>) -> WebView {
654 WebView(ElNode::new(Tag::WebView)).html(html, base_url)
655}
656
657pub fn video(url: impl IntoReactive<String>) -> Video {
660 Video(ElNode::new(Tag::Video)).bind_prop(url, |url: String| {
661 Prop::Native(NativeProp::Source(WebSource::Uri(url.into())))
662 })
663}
664
665pub fn native(name: &str) -> NativeView {
667 NativeView(ElNode::new(Tag::Native)).set(Prop::Component(name.into()))
668}
669
670impl Input {
671 pub fn value(self, text: impl IntoReactive<String>) -> Self {
674 self.bind_prop(text, |text: String| Prop::Value(text))
675 }
676
677 pub fn default_value(self, text: impl IntoReactive<String>) -> Self {
679 self.bind_prop(text, |text: String| Prop::DefaultValue(text))
680 }
681
682 pub fn placeholder(self, text: impl IntoReactive<String>) -> Self {
684 self.bind_prop(text, |text: String| Prop::Placeholder(text))
685 }
686
687 pub fn placeholder_color(self, color: impl IntoReactive<Hsla>) -> Self {
689 self.bind_prop(color, |color: Hsla| {
690 Prop::PlaceholderColor(Some(color.into()))
691 })
692 }
693
694 pub fn selection_color(self, color: impl IntoReactive<Hsla>) -> Self {
697 self.bind_prop(color, |color: Hsla| {
698 Prop::SelectionColor(Some(color.into()))
699 })
700 }
701
702 pub fn caret_color(self, color: impl IntoReactive<Hsla>) -> Self {
704 self.bind_prop(color, |color: Hsla| Prop::CaretColor(Some(color.into())))
705 }
706
707 pub fn masked(self, secure: impl IntoReactive<bool>) -> Self {
709 self.bind_prop(secure, |secure: bool| Prop::Secure(secure))
710 }
711
712 pub fn keyboard_type(self, kind: impl IntoReactive<KeyboardType>) -> Self {
714 self.bind_prop(kind, |kind: KeyboardType| Prop::KeyboardType(kind))
715 }
716
717 pub fn keyboard_appearance(self, appearance: impl IntoReactive<KeyboardAppearance>) -> Self {
720 self.bind_prop(appearance, |appearance: KeyboardAppearance| {
721 Prop::KeyboardAppearance(appearance)
722 })
723 }
724
725 pub fn return_key_type(self, kind: impl IntoReactive<ReturnKeyType>) -> Self {
727 self.bind_prop(kind, |kind: ReturnKeyType| Prop::ReturnKeyType(kind))
728 }
729
730 pub fn auto_capitalize(self, mode: impl IntoReactive<AutoCapitalize>) -> Self {
732 self.bind_prop(mode, |mode: AutoCapitalize| Prop::AutoCapitalize(mode))
733 }
734
735 pub fn auto_correct(self, on: impl IntoReactive<bool>) -> Self {
737 self.bind_prop(on, |on: bool| Prop::AutoCorrect(on))
738 }
739
740 pub fn auto_fill(self, kind: impl IntoReactive<AutoFill>) -> Self {
742 self.bind_prop(kind, |kind: AutoFill| Prop::AutoFill(kind))
743 }
744
745 pub fn multiline(self, multiline: impl IntoReactive<bool>) -> Self {
747 self.bind_prop(multiline, |multiline: bool| Prop::Multiline(multiline))
748 }
749
750 pub fn scrollbar(self, shows: impl IntoReactive<bool>) -> Self {
753 self.bind_prop(shows, |shows: bool| Prop::Scrollbar(shows.into()))
754 }
755
756 pub fn max_length(self, length: impl IntoReactive<u32>) -> Self {
758 self.bind_prop(length, |length: u32| Prop::MaxLength(Some(length)))
759 }
760
761 pub fn readonly(self, readonly: impl IntoReactive<bool>) -> Self {
763 self.bind_prop(readonly, |readonly: bool| Prop::Readonly(readonly))
764 }
765
766 pub fn submit_behavior(self, behavior: impl IntoReactive<SubmitBehavior>) -> Self {
769 self.bind_prop(behavior, |behavior: SubmitBehavior| {
770 Prop::SubmitBehavior(Some(behavior))
771 })
772 }
773
774 pub fn paste_behavior(self, behavior: impl IntoReactive<PasteBehavior>) -> Self {
777 self.bind_prop(behavior, Prop::PasteBehavior)
778 }
779
780 pub fn on_paste<M>(self, listener: impl IntoListener<PasteEvent, M>) -> Self {
784 self.listen(EventKind::Paste, listener.into_listener(), events::paste)
785 }
786
787 pub fn auto_focus(self, focus: impl IntoReactive<bool>) -> Self {
789 self.bind_prop(focus, |focus: bool| Prop::AutoFocus(focus))
790 }
791
792 pub fn caret(self, caret: impl IntoReactive<bool>) -> Self {
794 self.bind_prop(caret, |caret: bool| Prop::Caret(caret))
795 }
796
797 pub fn input_accessory(self, native_id: impl IntoReactive<String>) -> Self {
800 self.bind_prop(native_id, |id: String| {
801 Prop::InputAccessoryViewId(Some(id.into()))
802 })
803 }
804
805 pub fn selected_range(self, range: impl IntoReactive<(u32, u32)>) -> Self {
810 self.bind_prop(range, |(start, end): (u32, u32)| {
811 Prop::Selection(start, end)
812 })
813 }
814
815 pub fn on_change<M>(self, listener: impl IntoListener<str, M>) -> Self {
817 self.listen(
818 EventKind::ChangeText,
819 listener.into_listener(),
820 events::text,
821 )
822 }
823
824 pub fn on_submit<M>(self, listener: impl IntoListener<str, M>) -> Self {
826 self.listen(
827 EventKind::SubmitEditing,
828 listener.into_listener(),
829 events::text,
830 )
831 }
832
833 pub fn on_selection_change<M>(self, listener: impl IntoListener<Selection, M>) -> Self {
835 self.listen(
836 EventKind::SelectionChange,
837 listener.into_listener(),
838 events::selection,
839 )
840 }
841
842 pub fn on_caret_move<M>(self, listener: impl IntoListener<CaretEvent, M>) -> Self {
846 self.listen(
847 EventKind::CaretMove,
848 listener.into_listener(),
849 events::caret,
850 )
851 }
852
853 pub fn on_key_press<M>(self, listener: impl IntoListener<str, M>) -> Self {
855 self.listen(EventKind::KeyPress, listener.into_listener(), events::key)
856 }
857
858 pub fn on_composition_change<M>(self, listener: impl IntoListener<Composition, M>) -> Self {
862 self.listen(
863 EventKind::CompositionChange,
864 listener.into_listener(),
865 events::composition,
866 )
867 }
868
869 pub fn on_content_size_change<M>(self, listener: impl IntoListener<Size<Points>, M>) -> Self {
871 self.listen(
872 EventKind::ContentSizeChange,
873 listener.into_listener(),
874 events::size,
875 )
876 }
877}
878
879impl Scroll {
880 pub fn horizontal(self) -> Self {
882 self.set(Prop::Horizontal(true))
883 }
884
885 pub fn scrollbar(self, shows: impl IntoReactive<bool>) -> Self {
887 self.bind_prop(shows, |shows: bool| Prop::Scrollbar(shows.into()))
888 }
889
890 pub fn zoom_range(self, min: f32, max: f32) -> Self {
892 self.set(Prop::Scroll(ScrollProp::MinZoom(min)))
893 .set(Prop::Scroll(ScrollProp::MaxZoom(max)))
894 }
895
896 pub fn zoom(self, scale: impl IntoReactive<f32>) -> Self {
898 self.bind_prop(scale, |scale: f32| Prop::Scroll(ScrollProp::Zoom(scale)))
899 }
900
901 pub fn bounces_zoom(self, bounces: impl IntoReactive<bool>) -> Self {
904 self.bind_prop(bounces, |bounces: bool| {
905 Prop::Scroll(ScrollProp::BouncesZoom(bounces))
906 })
907 }
908
909 pub fn zoomable(self, enabled: impl IntoReactive<bool>) -> Self {
911 self.bind_prop(enabled, |enabled: bool| {
912 Prop::Scroll(ScrollProp::Pinch(enabled))
913 })
914 }
915
916 pub fn center_content(self, center: impl IntoReactive<bool>) -> Self {
918 self.bind_prop(center, |center: bool| {
919 Prop::Scroll(ScrollProp::CenterContent(center))
920 })
921 }
922}
923
924impl super::Scrollable for Scroll {}
925
926impl Screen {
927 fn header_item(mut self, slot: HeaderSlot, key: &'static str, item: impl IntoElement) -> Self {
928 let mut node = ElNode::new(Tag::HeaderItem);
929 node.key = Some(key.into());
930 set(&mut node, Prop::HeaderSlot(slot));
931 node.children.push(item.into_element().0);
932 self.0.children.push(node);
933 self
934 }
935
936 pub fn title(self, title: impl IntoReactive<super::SharedString>) -> Self {
938 self.bind_prop(title, |t| {
939 Prop::Screen(ScreenProp::Title(Some(Arc::from(t.as_str()))))
940 })
941 }
942
943 pub fn header_visible(self, shown: impl IntoReactive<bool>) -> Self {
945 self.bind_prop(shown, |v| Prop::Screen(ScreenProp::HeaderVisible(v)))
946 }
947
948 pub fn hides_bottom_bar_when_pushed(self, hides: impl IntoReactive<bool>) -> Self {
951 self.bind_prop(hides, |v| {
952 Prop::Screen(ScreenProp::HidesBottomBarWhenPushed(v))
953 })
954 }
955
956 pub fn header_large_title(self, large: impl IntoReactive<bool>) -> Self {
958 self.bind_prop(large, |v| Prop::Screen(ScreenProp::HeaderLargeTitle(v)))
959 }
960
961 pub fn header_transparent(self, transparent: impl IntoReactive<bool>) -> Self {
963 self.bind_prop(transparent, |v| {
964 Prop::Screen(ScreenProp::HeaderTransparent(v))
965 })
966 }
967
968 pub fn header_style(mut self, style: impl IntoReactive<super::Style>) -> Self {
973 let style = match style.into_reactive() {
974 super::Reactive::Static(s) if s.1.is_bound() => {
976 super::Reactive::Bound(std::rc::Rc::new(move || s.clone()))
977 }
978 style => style,
979 };
980 self.0.bind_attr(style, |a, s: super::Style| {
981 set_in(&mut a.props, Prop::HeaderStyle(s.0));
982 if !s.1.is_empty() {
983 let typed = s.1.resolved();
984 let list = (!typed.is_empty()).then(|| std::rc::Rc::new(typed.lower()));
985 set_in(&mut a.props, Prop::HeaderClassList(list));
986 }
987 });
988 self
989 }
990
991 pub fn header_style_with(
998 self,
999 f: impl Fn(super::StyleRefinement) -> super::StyleRefinement + 'static,
1000 ) -> Self {
1001 let list = move || {
1002 let style = f(super::StyleRefinement::default()).resolved();
1003 (!style.is_empty()).then(|| std::rc::Rc::new(style.lower()))
1004 };
1005 self.bind_prop(super::Reactive::Bound(std::rc::Rc::new(list)), |list| {
1006 Prop::HeaderClassList(list)
1007 })
1008 }
1009
1010 pub fn header_back_title(self, title: impl IntoReactive<super::SharedString>) -> Self {
1012 self.bind_prop(title, |t| {
1013 Prop::Screen(ScreenProp::HeaderBackTitle(Some(Arc::from(t.as_str()))))
1014 })
1015 }
1016
1017 pub fn header_right_system_item(
1021 self,
1022 item: impl IntoReactive<crate::HeaderSystemItem>,
1023 ) -> Self {
1024 self.bind_prop(item, |item| {
1025 Prop::Screen(ScreenProp::HeaderRightSystemItem(Some(item)))
1026 })
1027 }
1028
1029 pub fn header_left_system_item(self, item: impl IntoReactive<crate::HeaderSystemItem>) -> Self {
1033 self.bind_prop(item, |item| {
1034 Prop::Screen(ScreenProp::HeaderLeftSystemItem(Some(item)))
1035 })
1036 }
1037
1038 pub fn header_right_symbol(self, name: impl IntoReactive<super::SharedString>) -> Self {
1042 self.bind_prop(name, |n| {
1043 Prop::Screen(ScreenProp::HeaderRightSymbol(Some(Arc::from(n.as_str()))))
1044 })
1045 }
1046
1047 pub fn header_left_symbol(self, name: impl IntoReactive<super::SharedString>) -> Self {
1051 self.bind_prop(name, |n| {
1052 Prop::Screen(ScreenProp::HeaderLeftSymbol(Some(Arc::from(n.as_str()))))
1053 })
1054 }
1055
1056 pub fn header_back_visible(self, visible: impl IntoReactive<bool>) -> Self {
1058 self.bind_prop(visible, |v| Prop::Screen(ScreenProp::HeaderBackVisible(v)))
1059 }
1060
1061 pub fn pop_on_swipe(self, enabled: impl IntoReactive<bool>) -> Self {
1064 self.bind_prop(enabled, |v| Prop::Screen(ScreenProp::PopOnSwipe(v)))
1065 }
1066
1067 pub fn pop_on_back(self, pop: impl IntoReactive<bool>) -> Self {
1071 self.bind_prop(pop, |v| Prop::Screen(ScreenProp::PopOnBack(v)))
1072 }
1073
1074 pub fn animation(self, animation: impl IntoReactive<ScreenAnimation>) -> Self {
1076 self.bind_prop(animation, |a| Prop::Screen(ScreenProp::Animation(a)))
1077 }
1078
1079 pub fn transition_shader(
1083 self,
1084 shader: impl IntoReactive<Option<crate::shader::TransitionShader>>,
1085 ) -> Self {
1086 self.bind_prop(shader, |s: Option<crate::shader::TransitionShader>| {
1087 Prop::TransitionShader(s.map(Into::into))
1088 })
1089 }
1090
1091 pub fn status_bar(self, setting: impl IntoReactive<StatusBarSetting>) -> Self {
1095 self.bind_prop(setting, |s| Prop::Screen(ScreenProp::StatusBar(Some(s))))
1096 }
1097
1098 pub fn header_left(self, item: impl IntoElement) -> Self {
1100 self.header_item(HeaderSlot::Left, "header-left", item)
1101 }
1102
1103 pub fn header_right(self, item: impl IntoElement) -> Self {
1105 self.header_item(HeaderSlot::Right, "header-right", item)
1106 }
1107
1108 pub fn header_title(self, item: impl IntoElement) -> Self {
1110 self.header_item(HeaderSlot::Title, "header-title", item)
1111 }
1112
1113 pub fn header(self, item: impl IntoElement) -> Self {
1117 self.header_item(HeaderSlot::Header, "header", item)
1118 }
1119
1120 pub fn on_dismiss<M>(self, listener: impl IntoListener<(), M>) -> Self {
1123 self.listen(EventKind::Dismiss, listener.into_listener(), events::unit)
1124 }
1125
1126 pub fn on_back_press<M>(self, listener: impl IntoListener<(), M>) -> Self {
1129 self.listen(
1130 EventKind::BackRequest,
1131 listener.into_listener(),
1132 events::unit,
1133 )
1134 }
1135}
1136
1137impl Overlay {
1138 pub fn anchor(self, anchor: &super::ElementRef) -> Self {
1142 let anchor = *anchor;
1143 self.bind_prop(
1144 move || match anchor.node() {
1145 Some(id) => OverlayAnchor::Node(id),
1146 None => OverlayAnchor::None,
1147 },
1148 |a| Prop::Overlay(OverlayProp::Anchor(a)),
1149 )
1150 }
1151
1152 pub fn cover(self, cover: &super::ElementRef, shown: impl Fn() -> bool + 'static) -> Self {
1158 let cover = *cover;
1159 self.bind_prop(
1160 move || if shown() { cover.node() } else { None },
1161 |id| Prop::Overlay(OverlayProp::Cover(id)),
1162 )
1163 }
1164
1165 pub fn anchor_beside(self, anchor: &super::ElementRef, edges: &super::ElementRef) -> Self {
1169 let (anchor, edges) = (*anchor, *edges);
1170 self.bind_prop(
1171 move || match (anchor.node(), edges.node()) {
1172 (Some(node), Some(edges)) => OverlayAnchor::Beside { node, edges },
1173 (Some(id), None) => OverlayAnchor::Node(id),
1174 _ => OverlayAnchor::None,
1175 },
1176 |a| Prop::Overlay(OverlayProp::Anchor(a)),
1177 )
1178 }
1179
1180 pub fn anchor_content(self, anchor: &super::ElementRef) -> Self {
1186 let anchor = *anchor;
1187 self.bind_prop(
1188 move || match anchor.node() {
1189 Some(id) => OverlayAnchor::Content(id),
1190 None => OverlayAnchor::None,
1191 },
1192 |a| Prop::Overlay(OverlayProp::Anchor(a)),
1193 )
1194 }
1195
1196 pub fn anchor_point(self, point: impl IntoReactive<Point<Points>>) -> Self {
1199 self.bind_prop(point, |p| {
1200 Prop::Overlay(OverlayProp::Anchor(OverlayAnchor::Point(p)))
1201 })
1202 }
1203
1204 pub fn anchor_bounds(self, bounds: impl IntoReactive<Bounds<Points>>) -> Self {
1208 self.bind_prop(bounds, |b| {
1209 Prop::Overlay(OverlayProp::Anchor(OverlayAnchor::Bounds(b)))
1210 })
1211 }
1212
1213 pub fn placement(self, placement: impl IntoReactive<Placement>) -> Self {
1215 self.bind_prop(placement, |p| Prop::Overlay(OverlayProp::Placement(p)))
1216 }
1217
1218 pub fn align(self, align: impl IntoReactive<Align>) -> Self {
1220 self.bind_prop(align, |a| Prop::Overlay(OverlayProp::Align(a)))
1221 }
1222
1223 pub fn offset(self, offset: impl IntoReactive<Points>) -> Self {
1225 self.bind_prop(offset, |o| Prop::Overlay(OverlayProp::Offset(o)))
1226 }
1227
1228 pub fn margin(self, margin: impl IntoReactive<Points>) -> Self {
1230 self.bind_prop(margin, |m| Prop::Overlay(OverlayProp::Margin(m)))
1231 }
1232
1233 pub fn on_press_outside<M>(self, listener: impl IntoListener<Point<Points>, M>) -> Self {
1237 self.listen(
1238 EventKind::PressOutside,
1239 listener.into_listener(),
1240 events::page_point,
1241 )
1242 }
1243
1244 pub fn on_cancel<M>(self, listener: impl IntoListener<(), M>) -> Self {
1248 self.listen(EventKind::Cancel, listener.into_listener(), events::unit)
1249 }
1250
1251 pub fn hint(self, delay: impl IntoReactive<std::time::Duration>) -> Self {
1258 self.bind_prop(delay, |d| Prop::Overlay(OverlayProp::Hint(Some(d))))
1259 }
1260
1261 pub fn hint_open(self, open: impl IntoReactive<Option<bool>>) -> Self {
1266 self.bind_prop(open, |o| Prop::Overlay(OverlayProp::Open(o)))
1267 }
1268
1269 pub fn on_hint_show<M>(self, listener: impl IntoListener<(), M>) -> Self {
1272 self.listen(EventKind::Show, listener.into_listener(), events::unit)
1273 }
1274
1275 pub fn on_hint_hide<M>(self, listener: impl IntoListener<(), M>) -> Self {
1278 self.listen(EventKind::Dismiss, listener.into_listener(), events::unit)
1279 }
1280
1281 pub fn on_position<M>(self, listener: impl IntoListener<OverlayPosition, M>) -> Self {
1284 self.listen(
1285 EventKind::Position,
1286 listener.into_listener(),
1287 events::overlay_position,
1288 )
1289 }
1290}
1291
1292impl Modal {
1293 pub fn animation(self, animation: impl IntoReactive<ModalAnimation>) -> Self {
1295 self.bind_prop(animation, |animation: ModalAnimation| {
1296 Prop::Modal(ModalProp::Animation(animation))
1297 })
1298 }
1299
1300 pub fn transition_shader(
1304 self,
1305 shader: impl IntoReactive<Option<crate::shader::TransitionShader>>,
1306 ) -> Self {
1307 self.bind_prop(shader, |s: Option<crate::shader::TransitionShader>| {
1308 Prop::TransitionShader(s.map(Into::into))
1309 })
1310 }
1311
1312 pub fn presentation(self, presentation: impl IntoReactive<ModalPresentation>) -> Self {
1314 self.bind_prop(presentation, |presentation: ModalPresentation| {
1315 Prop::Modal(ModalProp::Presentation(presentation))
1316 })
1317 }
1318
1319 pub fn status_bar(self, setting: impl IntoReactive<StatusBarSetting>) -> Self {
1322 self.bind_prop(setting, |s| Prop::Screen(ScreenProp::StatusBar(Some(s))))
1323 }
1324
1325 pub fn status_bar_translucent(self, translucent: impl IntoReactive<bool>) -> Self {
1327 self.bind_prop(translucent, |translucent: bool| {
1328 Prop::Modal(ModalProp::StatusBarTranslucent(translucent))
1329 })
1330 }
1331
1332 pub fn supported_orientations(
1335 self,
1336 orientations: impl IntoIterator<Item = Orientation>,
1337 ) -> Self {
1338 let bits = orientations.into_iter().fold(0, |bits, o| bits | o.bits());
1339 self.set(Prop::Modal(ModalProp::Orientations(bits)))
1340 }
1341
1342 pub fn close_on_escape(self, close: impl IntoReactive<bool>) -> Self {
1345 self.bind_prop(close, |v: bool| Prop::Modal(ModalProp::CloseOnEscape(v)))
1346 }
1347
1348 pub fn close_on_backdrop_press(self, close: impl IntoReactive<bool>) -> Self {
1352 self.bind_prop(close, |v: bool| {
1353 Prop::Modal(ModalProp::CloseOnBackdropPress(v))
1354 })
1355 }
1356
1357 pub fn close_on_swipe(self, close: impl IntoReactive<bool>) -> Self {
1359 self.bind_prop(close, |v: bool| Prop::Modal(ModalProp::CloseOnSwipe(v)))
1360 }
1361
1362 pub fn on_cancel<M>(self, listener: impl IntoListener<(), M>) -> Self {
1366 self.listen(
1367 EventKind::RequestClose,
1368 listener.into_listener(),
1369 events::unit,
1370 )
1371 }
1372
1373 pub fn on_open<M>(self, listener: impl IntoListener<(), M>) -> Self {
1375 self.listen(EventKind::Show, listener.into_listener(), events::unit)
1376 }
1377
1378 pub fn on_close<M>(self, listener: impl IntoListener<(), M>) -> Self {
1380 self.listen(EventKind::Dismiss, listener.into_listener(), events::unit)
1381 }
1382}
1383
1384#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1386pub enum Orientation {
1387 Portrait,
1389 PortraitUpsideDown,
1391 Landscape,
1393 LandscapeLeft,
1395 LandscapeRight,
1397}
1398
1399impl Orientation {
1400 fn bits(self) -> u8 {
1401 use crate::ModalConfig as M;
1402 match self {
1403 Orientation::Portrait => M::PORTRAIT,
1404 Orientation::PortraitUpsideDown => M::PORTRAIT_UPSIDE_DOWN,
1405 Orientation::Landscape => M::LANDSCAPE_LEFT | M::LANDSCAPE_RIGHT,
1406 Orientation::LandscapeLeft => M::LANDSCAPE_LEFT,
1407 Orientation::LandscapeRight => M::LANDSCAPE_RIGHT,
1408 }
1409 }
1410}
1411
1412impl WebView {
1413 pub fn html(self, html: impl IntoReactive<String>, base_url: Option<&str>) -> Self {
1416 let base_url: Option<Arc<str>> = base_url.map(Into::into);
1417 self.bind_prop(html, move |html: String| {
1418 Prop::Native(NativeProp::Source(WebSource::Html {
1419 html: html.into(),
1420 base_url: base_url.clone(),
1421 }))
1422 })
1423 }
1424
1425 pub fn injected_java_script(self, script: impl IntoReactive<String>) -> Self {
1427 self.bind_prop(script, |script: String| {
1428 Prop::Native(NativeProp::InjectedJavaScript(Some(script.into())))
1429 })
1430 }
1431
1432 pub fn injected_java_script_before_content(self, script: impl IntoReactive<String>) -> Self {
1434 self.bind_prop(script, |script: String| {
1435 Prop::Native(NativeProp::InjectedJavaScriptBefore(Some(script.into())))
1436 })
1437 }
1438
1439 pub fn user_agent(self, agent: impl IntoReactive<String>) -> Self {
1441 self.bind_prop(agent, |agent: String| {
1442 Prop::Native(NativeProp::UserAgent(Some(agent.into())))
1443 })
1444 }
1445
1446 pub fn scrollable(self, enabled: impl IntoReactive<bool>) -> Self {
1448 self.bind_prop(enabled, |enabled: bool| {
1449 Prop::Native(NativeProp::Scrollable(enabled))
1450 })
1451 }
1452
1453 pub fn java_script_enabled(self, enabled: impl IntoReactive<bool>) -> Self {
1455 self.bind_prop(enabled, |enabled: bool| {
1456 Prop::Native(NativeProp::JavaScriptEnabled(enabled))
1457 })
1458 }
1459
1460 pub fn back_forward_gestures(self, enabled: impl IntoReactive<bool>) -> Self {
1462 self.bind_prop(enabled, |enabled: bool| {
1463 Prop::Native(NativeProp::BackForwardGestures(enabled))
1464 })
1465 }
1466
1467 pub fn on_load_start<M>(self, listener: impl IntoListener<WebNavigation, M>) -> Self {
1469 self.listen(
1470 EventKind::LoadStart,
1471 listener.into_listener(),
1472 events::navigation,
1473 )
1474 }
1475
1476 pub fn on_load<M>(self, listener: impl IntoListener<WebNavigation, M>) -> Self {
1478 self.listen(
1479 EventKind::Load,
1480 listener.into_listener(),
1481 events::navigation,
1482 )
1483 }
1484
1485 pub fn on_error<M>(self, listener: impl IntoListener<str, M>) -> Self {
1487 self.listen(EventKind::Error, listener.into_listener(), events::message)
1488 }
1489
1490 pub fn on_message<M>(self, listener: impl IntoListener<str, M>) -> Self {
1492 self.listen(EventKind::Message, listener.into_listener(), events::data)
1493 }
1494
1495 pub fn on_navigation_state_change<M>(
1497 self,
1498 listener: impl IntoListener<WebNavigation, M>,
1499 ) -> Self {
1500 self.listen(
1501 EventKind::NavigationStateChange,
1502 listener.into_listener(),
1503 events::navigation,
1504 )
1505 }
1506}
1507
1508impl Video {
1509 pub fn paused(self, paused: impl IntoReactive<bool>) -> Self {
1511 self.bind_prop(paused, |paused: bool| {
1512 Prop::Native(NativeProp::Paused(paused))
1513 })
1514 }
1515
1516 pub fn muted(self, muted: impl IntoReactive<bool>) -> Self {
1518 self.bind_prop(muted, |muted: bool| Prop::Native(NativeProp::Muted(muted)))
1519 }
1520
1521 pub fn volume(self, volume: impl IntoReactive<f32>) -> Self {
1523 self.bind_prop(volume, |volume: f32| {
1524 Prop::Native(NativeProp::Volume(volume))
1525 })
1526 }
1527
1528 pub fn rate(self, rate: impl IntoReactive<f32>) -> Self {
1530 self.bind_prop(rate, |rate: f32| Prop::Native(NativeProp::Rate(rate)))
1531 }
1532
1533 pub fn repeat(self, repeat: impl IntoReactive<bool>) -> Self {
1535 self.bind_prop(repeat, |repeat: bool| {
1536 Prop::Native(NativeProp::Repeat(repeat))
1537 })
1538 }
1539
1540 pub fn controls(self, controls: impl IntoReactive<bool>) -> Self {
1542 self.bind_prop(controls, |controls: bool| {
1543 Prop::Native(NativeProp::Controls(controls))
1544 })
1545 }
1546
1547 pub fn progress_interval(self, ms: impl IntoReactive<f32>) -> Self {
1549 self.bind_prop(ms, |ms: f32| Prop::Native(NativeProp::ProgressInterval(ms)))
1550 }
1551
1552 pub fn audio_session(self, session: impl IntoReactive<AudioSession>) -> Self {
1555 self.bind_prop(session, |session: AudioSession| {
1556 Prop::Native(NativeProp::AudioSession(session))
1557 })
1558 }
1559
1560 pub fn on_load_start<M>(self, listener: impl IntoListener<(), M>) -> Self {
1562 self.listen(EventKind::LoadStart, listener.into_listener(), events::unit)
1563 }
1564
1565 pub fn on_load<M>(self, listener: impl IntoListener<VideoInfo, M>) -> Self {
1567 self.listen(EventKind::Load, listener.into_listener(), events::video)
1568 }
1569
1570 pub fn on_progress<M>(self, listener: impl IntoListener<VideoProgress, M>) -> Self {
1572 self.listen(
1573 EventKind::Progress,
1574 listener.into_listener(),
1575 events::progress,
1576 )
1577 }
1578
1579 pub fn on_end<M>(self, listener: impl IntoListener<(), M>) -> Self {
1581 self.listen(EventKind::End, listener.into_listener(), events::unit)
1582 }
1583
1584 pub fn on_buffer<M>(self, listener: impl IntoListener<bool, M>) -> Self {
1586 self.listen(
1587 EventKind::Buffer,
1588 listener.into_listener(),
1589 events::buffering,
1590 )
1591 }
1592
1593 pub fn on_error<M>(self, listener: impl IntoListener<str, M>) -> Self {
1595 self.listen(EventKind::Error, listener.into_listener(), events::message)
1596 }
1597}
1598
1599impl NativeView {
1600 pub fn prop(self, name: &str, value: impl IntoReactive<JsonValue>) -> Self {
1603 let name: Arc<str> = name.into();
1604 self.bind_prop(value, move |value| {
1605 Prop::ComponentProp(name.clone(), Some(value))
1606 })
1607 }
1608
1609 pub fn bind_animated_prop(mut self, name: &str, value: &impl super::Animated) -> Self {
1615 if let Some(node) = value.animated_node().live() {
1616 set(
1617 &mut self.0,
1618 Prop::ComponentPropBinding(name.into(), Some(node.id())),
1619 );
1620 self.0.attrs.bound.push(node);
1621 }
1622 self
1623 }
1624
1625 pub fn on_native_event<M>(self, listener: impl IntoListener<NativeEvent, M>) -> Self {
1627 self.listen(
1628 EventKind::NativeEvent,
1629 listener.into_listener(),
1630 events::native,
1631 )
1632 }
1633}
1634
1635#[derive(Debug, Clone, PartialEq)]
1638pub struct CanvasArg(pub(crate) CanvasArgKind);
1639
1640#[derive(Debug, Clone, PartialEq)]
1641pub(crate) enum CanvasArgKind {
1642 Const(f32),
1643 Node(super::LiveNode),
1644}
1645
1646impl From<f32> for CanvasArg {
1647 fn from(n: f32) -> Self {
1648 Self(CanvasArgKind::Const(n))
1649 }
1650}
1651
1652impl From<Points> for CanvasArg {
1654 fn from(n: Points) -> Self {
1655 Self(CanvasArgKind::Const(n.0))
1656 }
1657}
1658
1659impl From<Radians> for CanvasArg {
1661 fn from(n: Radians) -> Self {
1662 Self(CanvasArgKind::Const(n.0))
1663 }
1664}
1665
1666impl<A: super::Animated> From<&A> for CanvasArg {
1668 fn from(a: &A) -> Self {
1669 Self(match a.animated_node().live() {
1670 Some(node) => CanvasArgKind::Node(node),
1671 None => CanvasArgKind::Const(0.0),
1672 })
1673 }
1674}
1675
1676#[derive(Debug, Clone, PartialEq)]
1681pub struct CanvasPaint(CanvasPaintKind);
1682
1683#[derive(Debug, Clone, PartialEq)]
1684enum CanvasPaintKind {
1685 Color(Color),
1686 Gradient(Arc<CanvasGradient>),
1687 Node(super::LiveNode),
1688}
1689
1690impl From<Color> for CanvasPaint {
1691 fn from(color: Color) -> Self {
1692 Self(CanvasPaintKind::Color(color))
1693 }
1694}
1695
1696impl From<Hsla> for CanvasPaint {
1697 fn from(color: Hsla) -> Self {
1698 Color::from(color).into()
1699 }
1700}
1701
1702impl From<Rgba> for CanvasPaint {
1703 fn from(color: Rgba) -> Self {
1704 Color::from(color).into()
1705 }
1706}
1707
1708impl From<CanvasGradient> for CanvasPaint {
1709 fn from(gradient: CanvasGradient) -> Self {
1710 Self(CanvasPaintKind::Gradient(Arc::new(gradient)))
1711 }
1712}
1713
1714impl From<Arc<CanvasGradient>> for CanvasPaint {
1715 fn from(gradient: Arc<CanvasGradient>) -> Self {
1716 Self(CanvasPaintKind::Gradient(gradient))
1717 }
1718}
1719
1720impl<A: super::Animated> From<&A> for CanvasPaint {
1722 fn from(a: &A) -> Self {
1723 Self(match a.animated_node().live() {
1724 Some(node) => CanvasPaintKind::Node(node),
1725 None => CanvasPaintKind::Color(Color::TRANSPARENT),
1726 })
1727 }
1728}
1729
1730#[derive(Debug, Clone, Default)]
1738pub struct Painter {
1739 drawing: Drawing,
1740 nodes: Vec<super::LiveNode>,
1742}
1743
1744impl Painter {
1745 pub fn new() -> Self {
1747 Self::default()
1748 }
1749
1750 pub fn finish(self) -> Drawing {
1752 self.drawing
1753 }
1754
1755 pub fn num(&mut self, value: impl Into<CanvasArg>) -> Num {
1759 match value.into().0 {
1760 CanvasArgKind::Const(n) => Num::Const(n),
1761 CanvasArgKind::Node(node) => Num::Slot(self.slot(node)),
1762 }
1763 }
1764
1765 pub fn paint(&mut self, paint: impl Into<CanvasPaint>) -> Paint {
1768 match paint.into().0 {
1769 CanvasPaintKind::Color(color) => Paint::Color(color),
1770 CanvasPaintKind::Gradient(gradient) => Paint::Gradient(gradient),
1771 CanvasPaintKind::Node(node) => Paint::Slot(self.slot(node)),
1772 }
1773 }
1774
1775 fn slot(&mut self, node: super::LiveNode) -> u16 {
1776 let slot = self.drawing.slot(node.id());
1777 self.nodes.push(node);
1778 slot
1779 }
1780
1781 pub fn node(mut self, node: crate::canvas::CanvasNode) -> Self {
1784 self.drawing.nodes.push(node);
1785 self
1786 }
1787
1788 pub fn op(mut self, op: CanvasOp) -> Self {
1791 self.drawing.ops.push(op);
1792 self
1793 }
1794
1795 fn path(self, op: PathOp) -> Self {
1796 self.op(CanvasOp::Path(op))
1797 }
1798
1799 pub fn is_point_in_path(&self, point: Point<Points>, rule: FillRule) -> bool {
1806 crate::canvas::point_in_path(&self.drawing.ops, None, rule, point, |_| 0.0)
1807 }
1808
1809 pub fn is_point_in_stroke(&self, point: Point<Points>) -> bool {
1813 crate::canvas::point_in_stroke(&self.drawing.ops, None, point, |_| 0.0)
1814 }
1815
1816 pub fn path_contains(&self, path: &Path, point: Point<Points>, rule: FillRule) -> bool {
1821 crate::canvas::point_in_path(&self.drawing.ops, Some(path), rule, point, |_| 0.0)
1822 }
1823
1824 pub fn stroke_contains(&self, path: &Path, point: Point<Points>) -> bool {
1828 crate::canvas::point_in_stroke(&self.drawing.ops, Some(path), point, |_| 0.0)
1829 }
1830
1831 pub fn save(self) -> Self {
1833 self.op(CanvasOp::Save)
1834 }
1835
1836 pub fn restore(self) -> Self {
1838 self.op(CanvasOp::Restore)
1839 }
1840
1841 pub fn translate(mut self, x: impl Into<CanvasArg>, y: impl Into<CanvasArg>) -> Self {
1843 let (x, y) = (self.num(x), self.num(y));
1844 self.op(CanvasOp::Translate(x, y))
1845 }
1846
1847 pub fn scale(mut self, x: impl Into<CanvasArg>, y: impl Into<CanvasArg>) -> Self {
1849 let (x, y) = (self.num(x), self.num(y));
1850 self.op(CanvasOp::Scale(x, y))
1851 }
1852
1853 pub fn rotate(mut self, angle: impl Into<CanvasArg>) -> Self {
1856 let a = self.num(angle);
1857 self.op(CanvasOp::Rotate(a))
1858 }
1859
1860 pub fn transform(mut self, m: [impl Into<CanvasArg>; 6]) -> Self {
1863 let m = m.map(|n| self.num(n));
1864 self.op(CanvasOp::Transform(m))
1865 }
1866
1867 pub fn set_transform(mut self, m: [impl Into<CanvasArg>; 6]) -> Self {
1870 let m = m.map(|n| self.num(n));
1871 self.op(CanvasOp::SetTransform(m))
1872 }
1873
1874 pub fn reset_transform(self) -> Self {
1876 self.set_transform([1.0, 0.0, 0.0, 1.0, 0.0, 0.0])
1877 }
1878
1879 pub fn begin_path(self) -> Self {
1881 self.op(CanvasOp::BeginPath)
1882 }
1883
1884 pub fn move_to(mut self, x: impl Into<CanvasArg>, y: impl Into<CanvasArg>) -> Self {
1886 let (x, y) = (self.num(x), self.num(y));
1887 self.path(PathOp::MoveTo(x, y))
1888 }
1889
1890 pub fn line_to(mut self, x: impl Into<CanvasArg>, y: impl Into<CanvasArg>) -> Self {
1892 let (x, y) = (self.num(x), self.num(y));
1893 self.path(PathOp::LineTo(x, y))
1894 }
1895
1896 pub fn quadratic_curve_to(self, control: Point<Points>, to: Point<Points>) -> Self {
1898 let c = |v: Points| Num::Const(v.0);
1899 self.path(PathOp::QuadTo([
1900 c(control.x),
1901 c(control.y),
1902 c(to.x),
1903 c(to.y),
1904 ]))
1905 }
1906
1907 pub fn bezier_curve_to(self, c1: Point<Points>, c2: Point<Points>, to: Point<Points>) -> Self {
1909 let c = |v: Points| Num::Const(v.0);
1910 self.path(PathOp::CubicTo([
1911 c(c1.x),
1912 c(c1.y),
1913 c(c2.x),
1914 c(c2.y),
1915 c(to.x),
1916 c(to.y),
1917 ]))
1918 }
1919
1920 pub fn arc(
1923 self,
1924 x: impl Into<CanvasArg>,
1925 y: impl Into<CanvasArg>,
1926 radius: impl Into<CanvasArg>,
1927 start: impl Into<CanvasArg>,
1928 end: impl Into<CanvasArg>,
1929 ) -> Self {
1930 self.arc_in(x, y, radius, start, end, false)
1931 }
1932
1933 pub fn arc_counterclockwise(
1935 self,
1936 x: impl Into<CanvasArg>,
1937 y: impl Into<CanvasArg>,
1938 radius: impl Into<CanvasArg>,
1939 start: impl Into<CanvasArg>,
1940 end: impl Into<CanvasArg>,
1941 ) -> Self {
1942 self.arc_in(x, y, radius, start, end, true)
1943 }
1944
1945 fn arc_in(
1946 mut self,
1947 x: impl Into<CanvasArg>,
1948 y: impl Into<CanvasArg>,
1949 radius: impl Into<CanvasArg>,
1950 start: impl Into<CanvasArg>,
1951 end: impl Into<CanvasArg>,
1952 ccw: bool,
1953 ) -> Self {
1954 let (x, y, radius, start, end) = (
1955 self.num(x),
1956 self.num(y),
1957 self.num(radius),
1958 self.num(start),
1959 self.num(end),
1960 );
1961 self.path(PathOp::Arc {
1962 x,
1963 y,
1964 radius,
1965 start,
1966 end,
1967 ccw,
1968 })
1969 }
1970
1971 pub fn arc_to(self, p1: Point<Points>, p2: Point<Points>, radius: Points) -> Self {
1974 let c = |v: Points| Num::Const(v.0);
1975 self.path(PathOp::ArcTo([
1976 c(p1.x),
1977 c(p1.y),
1978 c(p2.x),
1979 c(p2.y),
1980 c(radius),
1981 ]))
1982 }
1983
1984 pub fn ellipse(
1988 self,
1989 center: Point<Points>,
1990 radii: Size<Points>,
1991 rotation: Radians,
1992 start: Radians,
1993 end: Radians,
1994 counterclockwise: bool,
1995 ) -> Self {
1996 let c = Num::Const;
1997 self.path(PathOp::Ellipse {
1998 geometry: [
1999 c(center.x.0),
2000 c(center.y.0),
2001 c(radii.width.0),
2002 c(radii.height.0),
2003 c(rotation.0),
2004 ],
2005 start: c(start.0),
2006 end: c(end.0),
2007 ccw: counterclockwise,
2008 })
2009 }
2010
2011 pub fn rect(self, rect: Bounds<Points>) -> Self {
2013 self.path(PathOp::Rect(nums(rect)))
2014 }
2015
2016 pub fn round_rect(self, rect: Bounds<Points>, radius: Points) -> Self {
2018 self.round_rect_corners(rect, Corners::all(radius))
2019 }
2020
2021 pub fn round_rect_corners(self, rect: Bounds<Points>, radii: Corners<Points>) -> Self {
2023 let c = |v: Points| Num::Const(v.0);
2024 self.path(PathOp::RoundRect(
2025 nums(rect),
2026 [
2027 c(radii.top_left),
2028 c(radii.top_right),
2029 c(radii.bottom_right),
2030 c(radii.bottom_left),
2031 ],
2032 ))
2033 }
2034
2035 pub fn close_path(self) -> Self {
2037 self.path(PathOp::Close)
2038 }
2039
2040 pub fn fill(self) -> Self {
2042 self.fill_with(FillRule::NonZero)
2043 }
2044
2045 pub fn fill_with(self, rule: FillRule) -> Self {
2047 self.op(CanvasOp::Fill(None, rule))
2048 }
2049
2050 pub fn fill_path(self, path: &Path, rule: FillRule) -> Self {
2053 self.op(CanvasOp::Fill(Some(path.clone()), rule))
2054 }
2055
2056 pub fn fill_svg(self, data: &str) -> Self {
2059 self.fill_path(&crate::canvas::svg_path(data), FillRule::NonZero)
2060 }
2061
2062 pub fn stroke(self) -> Self {
2064 self.op(CanvasOp::Stroke(None))
2065 }
2066
2067 pub fn stroke_path(self, path: &Path) -> Self {
2069 self.op(CanvasOp::Stroke(Some(path.clone())))
2070 }
2071
2072 pub fn stroke_svg(self, data: &str) -> Self {
2074 self.stroke_path(&crate::canvas::svg_path(data))
2075 }
2076
2077 pub fn clip(self) -> Self {
2079 self.clip_with(FillRule::NonZero)
2080 }
2081
2082 pub fn clip_with(self, rule: FillRule) -> Self {
2084 self.op(CanvasOp::Clip(None, rule))
2085 }
2086
2087 pub fn clip_path(self, path: &Path, rule: FillRule) -> Self {
2089 self.op(CanvasOp::Clip(Some(path.clone()), rule))
2090 }
2091
2092 pub fn fill_rect(
2094 mut self,
2095 x: impl Into<CanvasArg>,
2096 y: impl Into<CanvasArg>,
2097 w: impl Into<CanvasArg>,
2098 h: impl Into<CanvasArg>,
2099 ) -> Self {
2100 let (x, y, w, h) = (self.num(x), self.num(y), self.num(w), self.num(h));
2101 self.op(CanvasOp::FillRect([x, y, w, h]))
2102 }
2103
2104 pub fn stroke_rect(self, rect: Bounds<Points>) -> Self {
2106 self.op(CanvasOp::StrokeRect(nums(rect)))
2107 }
2108
2109 pub fn clear_rect(self, rect: Bounds<Points>) -> Self {
2111 self.op(CanvasOp::ClearRect(nums(rect)))
2112 }
2113
2114 pub fn fill_color(self, color: impl Into<Hsla>) -> Self {
2116 self.fill_style(color.into())
2117 }
2118
2119 pub fn stroke_color(self, color: impl Into<Hsla>) -> Self {
2121 self.stroke_style(color.into())
2122 }
2123
2124 pub fn fill_style(mut self, paint: impl Into<CanvasPaint>) -> Self {
2127 let paint = self.paint(paint);
2128 self.op(CanvasOp::FillStyle(paint))
2129 }
2130
2131 pub fn fill_style_from_view(self, initial: SvgPaint) -> Self {
2137 self.view_paint(
2138 ViewPaint::Fill(initial),
2139 CanvasOp::FillStyle(Paint::Color(Color::TRANSPARENT)),
2140 )
2141 }
2142
2143 pub fn stroke_style_from_view(self, initial: SvgPaint) -> Self {
2146 self.view_paint(
2147 ViewPaint::Stroke(initial),
2148 CanvasOp::StrokeStyle(Paint::Color(Color::TRANSPARENT)),
2149 )
2150 }
2151
2152 pub fn line_width_from_view(self) -> Self {
2155 self.view_paint(ViewPaint::StrokeWidth, CanvasOp::LineWidth(Num::Const(1.0)))
2156 }
2157
2158 pub fn line_dash_from_view(self) -> Self {
2161 self.view_paint(
2162 ViewPaint::StrokeDasharray,
2163 CanvasOp::LineDash(Arc::from([])),
2164 )
2165 }
2166
2167 pub fn fill_background_from_view(self, area: Bounds<Points>) -> Self {
2176 self.view_paint(
2177 ViewPaint::Background {
2178 area,
2179 rule: FillRule::NonZero,
2180 },
2181 CanvasOp::Fill(None, FillRule::NonZero),
2182 )
2183 }
2184
2185 fn view_paint(mut self, view: ViewPaint, placeholder: CanvasOp) -> Self {
2186 let at = self.drawing.ops.len() as u32;
2187 self.drawing.view_paints.push((at, view));
2188 self.op(placeholder)
2189 }
2190
2191 pub fn stroke_style(mut self, paint: impl Into<CanvasPaint>) -> Self {
2193 let paint = self.paint(paint);
2194 self.op(CanvasOp::StrokeStyle(paint))
2195 }
2196
2197 pub fn line_width(mut self, width: impl Into<CanvasArg>) -> Self {
2199 let w = self.num(width);
2200 self.op(CanvasOp::LineWidth(w))
2201 }
2202
2203 pub fn line_cap(self, cap: LineCap) -> Self {
2205 self.op(CanvasOp::LineCap(cap))
2206 }
2207
2208 pub fn line_join(self, join: LineJoin) -> Self {
2210 self.op(CanvasOp::LineJoin(join))
2211 }
2212
2213 pub fn miter_limit(self, limit: f32) -> Self {
2216 self.op(CanvasOp::MiterLimit(limit.max(1.0)))
2217 }
2218
2219 pub fn line_dash(self, segments: &[Points]) -> Self {
2221 self.op(CanvasOp::LineDash(segments.into()))
2222 }
2223
2224 pub fn line_dash_offset(mut self, offset: impl Into<CanvasArg>) -> Self {
2227 let o = self.num(offset);
2228 self.op(CanvasOp::LineDashOffset(o))
2229 }
2230
2231 pub fn global_alpha(mut self, alpha: impl Into<CanvasArg>) -> Self {
2233 let a = self.num(alpha);
2234 self.op(CanvasOp::GlobalAlpha(a))
2235 }
2236
2237 pub fn composite(self, composite: Composite) -> Self {
2239 self.op(CanvasOp::Composite(composite))
2240 }
2241
2242 pub fn shadow(self, color: impl Into<Hsla>, blur: Points, offset: Point<Points>) -> Self {
2244 self.op(CanvasOp::ShadowColor(Color::from(color.into())))
2245 .op(CanvasOp::ShadowBlur(blur.max(Points::ZERO)))
2246 .op(CanvasOp::ShadowOffset(offset))
2247 }
2248
2249 pub fn font(self, font: &str) -> Self {
2252 match CanvasFont::parse(font) {
2253 Some(font) => self.op(CanvasOp::Font(font)),
2254 None => self,
2255 }
2256 }
2257
2258 pub fn font_variant_numeric(self, numeric: crate::style::FontVariant) -> Self {
2262 self.op(CanvasOp::FontVariantNumeric(crate::style::FontVariant(
2263 numeric.0 & !crate::style::FontVariant::SMALL_CAPS,
2264 )))
2265 }
2266
2267 pub fn text_align(self, align: CanvasTextAlign) -> Self {
2269 self.op(CanvasOp::TextAlign(align))
2270 }
2271
2272 pub fn text_baseline(self, baseline: CanvasTextBaseline) -> Self {
2274 self.op(CanvasOp::TextBaseline(baseline))
2275 }
2276
2277 pub fn fill_text(self, text: &str, x: impl Into<CanvasArg>, y: impl Into<CanvasArg>) -> Self {
2279 self.text(text, x, y, None, false)
2280 }
2281
2282 pub fn fill_text_max_width(
2284 self,
2285 text: &str,
2286 x: impl Into<CanvasArg>,
2287 y: impl Into<CanvasArg>,
2288 max_width: Points,
2289 ) -> Self {
2290 self.text(text, x, y, Some(max_width), false)
2291 }
2292
2293 pub fn stroke_text(self, text: &str, x: impl Into<CanvasArg>, y: impl Into<CanvasArg>) -> Self {
2295 self.text(text, x, y, None, true)
2296 }
2297
2298 pub fn stroke_text_max_width(
2301 self,
2302 text: &str,
2303 x: impl Into<CanvasArg>,
2304 y: impl Into<CanvasArg>,
2305 max_width: Points,
2306 ) -> Self {
2307 self.text(text, x, y, Some(max_width), true)
2308 }
2309
2310 fn text(
2311 mut self,
2312 text: &str,
2313 x: impl Into<CanvasArg>,
2314 y: impl Into<CanvasArg>,
2315 max_width: Option<Points>,
2316 stroke: bool,
2317 ) -> Self {
2318 let (text, x, y) = (text.into(), self.num(x), self.num(y));
2319 self.op(if stroke {
2320 CanvasOp::StrokeText {
2321 text,
2322 x,
2323 y,
2324 max_width,
2325 }
2326 } else {
2327 CanvasOp::FillText {
2328 text,
2329 x,
2330 y,
2331 max_width,
2332 }
2333 })
2334 }
2335
2336 pub fn draw_image(self, uri: &str, dest: Bounds<Points>) -> Self {
2338 self.draw_image_part(uri, None, dest)
2339 }
2340
2341 pub fn draw_image_part(
2344 self,
2345 uri: &str,
2346 source: Option<Bounds<ScaledPixels>>,
2347 dest: Bounds<Points>,
2348 ) -> Self {
2349 self.op(CanvasOp::DrawImage {
2350 image: CanvasImage { uri: uri.into() },
2351 source,
2352 dest: nums(dest),
2353 })
2354 }
2355}
2356
2357fn nums(rect: Bounds<Points>) -> [Num; 4] {
2359 [
2360 rect.origin.x,
2361 rect.origin.y,
2362 rect.size.width,
2363 rect.size.height,
2364 ]
2365 .map(|v| Num::Const(v.0))
2366}
2367
2368impl From<Drawing> for Painter {
2369 fn from(drawing: Drawing) -> Self {
2370 Self {
2371 drawing,
2372 nodes: Vec::new(),
2373 }
2374 }
2375}
2376
2377crate::static_reactive!(ScreenAnimation: ScreenAnimation);
2378
2379impl IntoReactive<Option<crate::shader::TransitionShader>> for crate::shader::TransitionShader {
2381 fn into_reactive(self) -> super::Reactive<Option<crate::shader::TransitionShader>> {
2382 super::Reactive::Static(Some(self))
2383 }
2384}
2385
2386#[cfg(test)]
2387mod tests {
2388 use super::*;
2389 use crate::{
2390 element::{
2391 AnimatedValue,
2392 reactive::{Runtime, create_root, signal},
2393 },
2394 shader::{ShaderUniforms, UniformValue},
2395 };
2396
2397 fn uniforms(attrs: &super::super::builder::Attrs) -> ShaderUniforms {
2398 attrs
2399 .props
2400 .iter()
2401 .find_map(|p| match p {
2402 Prop::Uniforms(u) => Some(u.clone()),
2403 _ => None,
2404 })
2405 .unwrap_or_default()
2406 }
2407
2408 fn released(executor: &super::super::task::Executor) -> usize {
2410 executor
2411 .take_actions()
2412 .into_iter()
2413 .filter(|a| {
2414 matches!(
2415 a,
2416 super::super::task::Action::Animation(
2417 crate::animation::AnimationOp::Release { .. }
2418 )
2419 )
2420 })
2421 .count()
2422 }
2423
2424 fn value(u: &ShaderUniforms, name: &str) -> Option<UniformValue> {
2425 u.0.iter()
2426 .find(|(n, _)| &**n == name)
2427 .map(|(_, v)| v.clone())
2428 }
2429
2430 #[test]
2431 fn screens_and_modals_take_a_transition_shader() {
2432 let runtime = Runtime::default();
2433 let _entered = runtime.enter();
2434 let source = "struct Uniforms { edge: f32 }\n\
2435 fn shade(uv: vec2f) -> vec4f {\n \
2436 return select(sample_from(uv), sample_to(uv), uv.x < nsh.progress * uniforms.edge);\n}\n";
2437 let shader = crate::shader::Shader::compile(source).expect("compiles");
2438 let wipe = crate::shader::TransitionShader::new(shader)
2439 .uniform("edge", 1.0_f32)
2440 .duration(std::time::Duration::from_millis(400));
2441 let expected = crate::shader::NavShaderSpec {
2442 source: source.into(),
2443 uniforms: ShaderUniforms(vec![("edge".into(), UniformValue::Number(1.0))]),
2444 duration: Some(400.0),
2445 };
2446 let spec = |attrs: &super::super::builder::Attrs| {
2447 attrs.props.iter().find_map(|p| match p {
2448 Prop::TransitionShader(s) => Some(s.clone()),
2449 _ => None,
2450 })
2451 };
2452 let page = screen().transition_shader(wipe.clone()).0;
2453 assert_eq!(spec(&page.resolved_attrs()), Some(Some(expected.clone())));
2454 let dialog = modal().transition_shader(wipe.clone()).0;
2455 assert_eq!(spec(&dialog.resolved_attrs()), Some(Some(expected.clone())));
2456 let on = signal(true);
2458 let bound = screen()
2459 .transition_shader(move || on.get().then(|| wipe.clone()))
2460 .0;
2461 assert_eq!(spec(&bound.resolved_attrs()), Some(Some(expected)));
2462 on.set(false);
2463 assert_eq!(spec(&bound.resolved_attrs()), Some(None));
2464 }
2465
2466 #[test]
2467 fn uniform_takes_static_bound_and_animated_values() {
2468 let runtime = Runtime::default();
2469 let _entered = runtime.enter();
2470 let executor = std::rc::Rc::new(super::super::task::Executor::default());
2471 let (value_owner, wave) = create_root(|| AnimatedValue::new(&executor, 0.0));
2472 let speed = signal(1.0_f32);
2473 let view = shader()
2474 .uniform("center", [0.5_f32, 0.5])
2475 .uniform("wave", &wave)
2476 .uniform("speed", move || speed.get());
2477 let node = view.0;
2478
2479 let set = uniforms(&node.attrs);
2482 assert_eq!(
2483 value(&set, "center"),
2484 Some(UniformValue::List(vec![
2485 UniformValue::Number(0.5),
2486 UniformValue::Number(0.5)
2487 ]))
2488 );
2489 let id = wave.node().live().expect("live").id();
2490 assert_eq!(value(&set, "wave"), Some(UniformValue::Animated(id)));
2491 assert_eq!(
2492 node.attrs.bound.len(),
2493 1,
2494 "the element holds the animated node"
2495 );
2496 assert_eq!(
2497 value(&set, "speed"),
2498 None,
2499 "a bound one is applied when resolved"
2500 );
2501
2502 assert_eq!(
2504 value(&uniforms(&node.resolved_attrs()), "speed"),
2505 Some(UniformValue::Number(1.0))
2506 );
2507 speed.set(2.0);
2508 assert_eq!(
2509 value(&uniforms(&node.resolved_attrs()), "speed"),
2510 Some(UniformValue::Number(2.0))
2511 );
2512
2513 value_owner.dispose();
2515 assert_eq!(released(&executor), 0, "the view keeps the animated node");
2516 drop(node);
2517 assert_eq!(released(&executor), 1, "and lets it go with the view");
2518 }
2519
2520 #[test]
2521 fn a_later_uniform_replaces_one_of_the_same_name() {
2522 let view = shader().uniform("speed", 1.0_f32).uniform("speed", 3.0_f32);
2523 let set = uniforms(&view.0.attrs);
2524 assert_eq!(set.0.len(), 1);
2525 assert_eq!(value(&set, "speed"), Some(UniformValue::Number(3.0)));
2526 }
2527}