ferroui-base 0.4.0

The base library of FerroUI: the property system, layout, input, styling, media, text, animation, data binding and the compositor
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
//! The WinUI lights: `CompositionLight` and its subclasses `AmbientLight`,
//! `DistantLight`, `PointLight` and `SpotLight`, and the
//! `VisualUnorderedCollection` of the visuals a light targets and excludes.
//!
//! As for the clips, every light is one [`CompositionLight`] behind an `Rc`,
//! which holds what the concrete class adds in a kind; the concrete classes
//! are typed handles around the same `Rc` ([`AmbientLight`],
//! [`DistantLight`], [`PointLight`], [`SpotLight`]).
//!
//! A light lights the visuals of its [`targets`](CompositionLight::targets)
//! and their subtrees, except the visuals of its
//! [`exclusions_from_targets`](CompositionLight::exclusions_from_targets)
//! and their subtrees: the diffuse lighting of flat visuals facing the
//! viewer, see `server::LitContent` for how it is drawn.

use super::composition_object_impls::composition_object_impls;
use super::generated::{
    AmbientLightHooks, AmbientLightProps, CompositionLightHooks, CompositionLightProps, DistantLightHooks,
    DistantLightProps, PointLightHooks, PointLightProps, ServerAmbientLightProps, ServerDistantLightProps,
    ServerPointLightProps, ServerSpotLightProps, SpotLightHooks, SpotLightProps, VisualUnorderedCollectionHooks,
    VisualUnorderedCollectionProps,
};
use super::server::{
    IServerObject, ServerAmbientLight, ServerCompositor, ServerDistantLight, ServerObjectId, ServerPointLight,
    ServerSpotLight, ServerVisualUnorderedCollection,
};
use super::{CompositionObject, CompositionVisual, Compositor, ICompositionObject};
use crate::media::Color;
use crate::Vector3D;
use std::cell::RefCell;
use std::ops::Deref;
use std::rc::{Rc, Weak};

// --- the visual collection -------------------------------------------------------------

/// A set of visuals (WinUI
/// `Microsoft.UI.Composition.VisualUnorderedCollection`): the targets or the
/// exclusions of a light.
pub struct VisualUnorderedCollection {
    this: Weak<VisualUnorderedCollection>,
    object: CompositionObject,
    props: VisualUnorderedCollectionProps<CompositionVisual>,
}

impl VisualUnorderedCollection {
    pub(crate) fn new(compositor: &Rc<Compositor>) -> Rc<VisualUnorderedCollection> {
        let server =
            compositor.create_server_object(|compositor, _| ServerVisualUnorderedCollection::new(compositor));
        let collection = Rc::new_cyclic(|this: &Weak<VisualUnorderedCollection>| VisualUnorderedCollection {
            this: this.clone(),
            object: CompositionObject::new(compositor, Some(server)),
            props: VisualUnorderedCollectionProps::new(),
        });
        collection.props.initialize_defaults(&*collection);
        collection
    }

    /// The id of the server-side collection.
    pub fn server(&self) -> ServerObjectId {
        self.object.required_server()
    }

    /// A snapshot of the visuals, for enumeration (in the order they were
    /// added, which has no meaning).
    pub fn items(&self) -> Vec<Rc<CompositionVisual>> {
        self.props.items()
    }

    /// `Add`: adds a visual; a visual that is in the collection already is
    /// not added again.
    pub fn add(&self, visual: Rc<CompositionVisual>) {
        if !self.props.contains(&visual) {
            self.props.add(self, visual);
        }
    }

    /// `Remove`: removes a visual; `false` when it was not in the
    /// collection.
    pub fn remove(&self, visual: &Rc<CompositionVisual>) -> bool {
        self.props.remove(self, visual)
    }

    /// `RemoveAll`.
    pub fn remove_all(&self) {
        self.props.clear(self);
    }

    /// `Count`.
    pub fn count(&self) -> usize {
        self.props.count()
    }

    /// Whether the visual is in the collection (compared by reference).
    pub fn contains(&self, visual: &Rc<CompositionVisual>) -> bool {
        self.props.contains(visual)
    }

    pub fn is_disposed(&self) -> bool {
        self.object.is_disposed()
    }

    pub fn dispose(&self) {
        self.object.dispose();
    }
}

impl VisualUnorderedCollectionHooks<CompositionVisual> for VisualUnorderedCollection {}

composition_object_impls!(
    VisualUnorderedCollection, "VisualUnorderedCollection",
    serialize: |this, writer| this.props.serialize_changes_core(this, writer),
    start_animation: |_this, _name, _animation, _final_value| false,
    composition_property: |_this, _name| None,
);

// --- the lights ----------------------------------------------------------------------

/// What the concrete class of a light adds to [`CompositionLight`].
pub(crate) enum CompositionLightKind {
    Ambient(AmbientLightProps),
    Distant(DistantLightProps),
    Point(PointLightProps),
    Spot(SpotLightProps),
}

/// A light (WinUI `Microsoft.UI.Composition.CompositionLight`): it lights
/// the visuals of [`targets`](Self::targets) and their subtrees, minus the
/// visuals of [`exclusions_from_targets`](Self::exclusions_from_targets)
/// and their subtrees, while it [`is_enabled`](Self::is_enabled). A visual
/// that some enabled light reaches shows its content multiplied by the sum
/// of the lights that reach it, so it is dark where none of them shines.
///
/// Deviation (winui-composition.md): the lighting is a light map drawn over
/// the content of each lit visual, see `server::LitContent`.
pub struct CompositionLight {
    this: Weak<CompositionLight>,
    object: CompositionObject,
    kind: CompositionLightKind,
    targets: Rc<VisualUnorderedCollection>,
    exclusions: Rc<VisualUnorderedCollection>,
    /// The XAML light the light belongs to (winui-materials.md): its id and
    /// the visual of the element that holds it, and whether they changed
    /// since the last batch.
    xaml_binding: RefCell<(Option<String>, Option<Rc<CompositionVisual>>, bool)>,
}

impl CompositionLight {
    fn create(
        compositor: &Rc<Compositor>,
        kind: CompositionLightKind,
        server: impl FnOnce(&Rc<ServerCompositor>) -> Rc<dyn IServerObject> + Send + 'static,
    ) -> Rc<CompositionLight> {
        // The collections first: the light refers to their server objects.
        let targets = VisualUnorderedCollection::new(compositor);
        let exclusions = VisualUnorderedCollection::new(compositor);
        let server = compositor.create_server_object(move |compositor, _| server(compositor));
        let light = Rc::new_cyclic(|this: &Weak<CompositionLight>| CompositionLight {
            this: this.clone(),
            object: CompositionObject::new(compositor, Some(server)),
            kind,
            targets,
            exclusions,
            xaml_binding: RefCell::new((None, None, false)),
        });
        match &light.kind {
            CompositionLightKind::Ambient(props) => props.initialize_defaults(&*light),
            CompositionLightKind::Distant(props) => props.initialize_defaults(&*light),
            CompositionLightKind::Point(props) => props.initialize_defaults(&*light),
            CompositionLightKind::Spot(props) => props.initialize_defaults(&*light),
        }
        let targets: Rc<dyn ICompositionObject> = light.targets.clone();
        light.light_props().set_targets(&*light, Some(targets));
        let exclusions: Rc<dyn ICompositionObject> = light.exclusions.clone();
        light.light_props().set_exclusions_from_targets(&*light, Some(exclusions));
        light
    }

    /// The generated properties of `CompositionLight`.
    pub fn light_props(&self) -> &CompositionLightProps {
        match &self.kind {
            CompositionLightKind::Ambient(props) => props.base(),
            CompositionLightKind::Distant(props) => props.base(),
            CompositionLightKind::Point(props) => props.base(),
            CompositionLightKind::Spot(props) => props.base(),
        }
    }

    pub fn compositor(&self) -> &Rc<Compositor> {
        self.object.compositor()
    }

    /// The embedded `CompositionObject`.
    pub fn object(&self) -> &CompositionObject {
        &self.object
    }

    /// The id of the server-side light.
    pub fn server(&self) -> ServerObjectId {
        self.object.required_server()
    }

    pub fn is_disposed(&self) -> bool {
        self.object.is_disposed()
    }

    /// Disposes the light and its two collections: the visuals it lit are
    /// drawn without it from the next frame.
    pub fn dispose(&self) {
        self.object.dispose();
        self.targets.dispose();
        self.exclusions.dispose();
    }

    /// The name of the concrete class, for messages.
    pub fn type_name(&self) -> &'static str {
        match &self.kind {
            CompositionLightKind::Ambient(_) => "AmbientLight",
            CompositionLightKind::Distant(_) => "DistantLight",
            CompositionLightKind::Point(_) => "PointLight",
            CompositionLightKind::Spot(_) => "SpotLight",
        }
    }

    /// `Targets`: the visuals the light lights, with their subtrees.
    pub fn targets(&self) -> &Rc<VisualUnorderedCollection> {
        &self.targets
    }

    /// `ExclusionsFromTargets`: the visuals, with their subtrees, the light
    /// does not light although they are in the subtree of a target.
    pub fn exclusions_from_targets(&self) -> &Rc<VisualUnorderedCollection> {
        &self.exclusions
    }

    /// Binds the light to a XAML light (`XamlLight.CompositionLight`): the
    /// light then also lights the XAML brushes that target the id `id`
    /// (`XamlLight.AddTargetBrush`) where they are drawn in the subtree of
    /// `scope`, the visual of the element whose `Lights` holds the XAML
    /// light. `None` unbinds it. Called by `XamlLight`.
    pub fn set_xaml_binding(&self, id: Option<String>, scope: Option<Rc<CompositionVisual>>) {
        {
            let mut binding = self.xaml_binding.borrow_mut();
            let same_scope = match (&binding.1, &scope) {
                (Some(a), Some(b)) => Rc::ptr_eq(a, b),
                (None, None) => true,
                _ => false,
            };
            if binding.0 == id && same_scope {
                return;
            }
            *binding = (id, scope, true);
        }
        self.object
            .register_for_serialization(|| self.this.upgrade().map(|this| this as Rc<dyn crate::rendering::composition::ICompositorSerializable>));
    }

    /// The id of the XAML light the light is bound to, if any.
    pub fn xaml_id(&self) -> Option<String> {
        self.xaml_binding.borrow().0.clone()
    }

    /// Writes the XAML binding when it changed (after the properties).
    fn serialize_xaml_binding(&self, writer: &mut crate::rendering::composition::transport::BatchStreamWriter<'_>) {
        let mut binding = self.xaml_binding.borrow_mut();
        let changes = binding.2.then(|| crate::rendering::composition::server::XamlLightChanges {
            id: binding.0.clone(),
            scope: binding.1.as_ref().and_then(|scope| scope.object().server()),
        });
        binding.2 = false;
        writer.write_value(changes);
    }

    /// `IsEnabled` (default `true`): a disabled light lights nothing, and
    /// the visuals it targets are drawn as if it did not exist.
    pub fn is_enabled(&self) -> bool {
        self.light_props().is_enabled()
    }

    pub fn set_is_enabled(&self, value: bool) {
        self.light_props().set_is_enabled(self, value)
    }
}

impl CompositionLightHooks for CompositionLight {}

impl AmbientLightHooks for CompositionLight {}

impl DistantLightHooks for CompositionLight {}

impl PointLightHooks for CompositionLight {}

impl SpotLightHooks for CompositionLight {}

composition_object_impls!(
    CompositionLight, "CompositionLight",
    serialize: |this, writer| {
        match &this.kind {
            CompositionLightKind::Ambient(props) => props.serialize_changes_core(this, writer),
            CompositionLightKind::Distant(props) => props.serialize_changes_core(this, writer),
            CompositionLightKind::Point(props) => props.serialize_changes_core(this, writer),
            CompositionLightKind::Spot(props) => props.serialize_changes_core(this, writer),
        }
        this.serialize_xaml_binding(writer);
    },
    start_animation: |this, name, animation, final_value| match &this.kind {
        CompositionLightKind::Ambient(props) => props.start_animation(this, name, animation, final_value),
        CompositionLightKind::Distant(props) => props.start_animation(this, name, animation, final_value),
        CompositionLightKind::Point(props) => props.start_animation(this, name, animation, final_value),
        CompositionLightKind::Spot(props) => props.start_animation(this, name, animation, final_value),
    },
    composition_property: |this, name| match &this.kind {
        CompositionLightKind::Ambient(_) => ServerAmbientLightProps::get_composition_property(name),
        CompositionLightKind::Distant(_) => ServerDistantLightProps::get_composition_property(name),
        CompositionLightKind::Point(_) => ServerPointLightProps::get_composition_property(name),
        CompositionLightKind::Spot(_) => ServerSpotLightProps::get_composition_property(name),
    },
);

/// The visual of an object property, as a visual.
fn as_visual(object: Option<Rc<dyn ICompositionObject>>) -> Option<Rc<CompositionVisual>> {
    object.and_then(|visual| visual.into_any_rc().downcast::<CompositionVisual>().ok())
}

/// A visual for an object property.
fn as_object(visual: Option<Rc<CompositionVisual>>) -> Option<Rc<dyn ICompositionObject>> {
    visual.map(|visual| visual as Rc<dyn ICompositionObject>)
}

/// Declares the typed handle of a light class: the struct, `Deref` to the
/// light, and `from_light`.
macro_rules! light_handle {
    ($(#[$meta:meta])* $name:ident, $kind:ident, $props:ident) => {
        $(#[$meta])*
        #[derive(Clone)]
        pub struct $name(Rc<CompositionLight>);

        impl Deref for $name {
            type Target = Rc<CompositionLight>;

            fn deref(&self) -> &Rc<CompositionLight> {
                &self.0
            }
        }

        impl $name {
            /// The handle of `light` as this class, if it is one.
            pub fn from_light(light: &Rc<CompositionLight>) -> Option<$name> {
                matches!(light.kind, CompositionLightKind::$kind(_)).then(|| $name(light.clone()))
            }

            /// The generated properties of the class.
            pub fn props(&self) -> &$props {
                match &self.0.kind {
                    CompositionLightKind::$kind(props) => props,
                    _ => unreachable!("a light handle wraps a light of its class"),
                }
            }
        }
    };
}

light_handle!(
    /// A light that lights every point of its targets alike (WinUI
    /// `Microsoft.UI.Composition.AmbientLight`): `Color` times `Intensity`,
    /// both animatable.
    AmbientLight,
    Ambient,
    AmbientLightProps
);

impl AmbientLight {
    pub(crate) fn new(compositor: &Rc<Compositor>) -> AmbientLight {
        AmbientLight(CompositionLight::create(
            compositor,
            CompositionLightKind::Ambient(AmbientLightProps::new()),
            |c| ServerAmbientLight::new(c),
        ))
    }

    /// The colour of the light (default white).
    pub fn color(&self) -> Color {
        self.props().color()
    }

    pub fn set_color(&self, value: Color) {
        self.props().set_color(&*self.0, value)
    }

    /// The intensity of the light (default 1).
    pub fn intensity(&self) -> f32 {
        self.props().intensity()
    }

    pub fn set_intensity(&self, value: f32) {
        self.props().set_intensity(&*self.0, value)
    }
}

light_handle!(
    /// A light from far away in one direction (WinUI
    /// `Microsoft.UI.Composition.DistantLight`): every point of a flat
    /// visual is lit alike, by the cosine of the angle between the direction
    /// and the visual. `Color`, `Direction` and `Intensity` are animatable.
    DistantLight,
    Distant,
    DistantLightProps
);

impl DistantLight {
    pub(crate) fn new(compositor: &Rc<Compositor>) -> DistantLight {
        DistantLight(CompositionLight::create(
            compositor,
            CompositionLightKind::Distant(DistantLightProps::new()),
            |c| ServerDistantLight::new(c),
        ))
    }

    /// The colour of the light (default white).
    pub fn color(&self) -> Color {
        self.props().color()
    }

    pub fn set_color(&self, value: Color) {
        self.props().set_color(&*self.0, value)
    }

    /// The visual whose coordinates `Direction` is in; `None` for the
    /// targeted visual.
    pub fn coordinate_space(&self) -> Option<Rc<CompositionVisual>> {
        as_visual(self.props().coordinate_space())
    }

    pub fn set_coordinate_space(&self, value: Option<Rc<CompositionVisual>>) {
        self.props().set_coordinate_space(&*self.0, as_object(value))
    }

    /// The direction the light shines in (default `(0, 0, -1)`: straight at
    /// a visual, which faces +Z).
    pub fn direction(&self) -> Vector3D {
        self.props().direction()
    }

    pub fn set_direction(&self, value: Vector3D) {
        self.props().set_direction(&*self.0, value)
    }

    /// The intensity of the light (default 1).
    pub fn intensity(&self) -> f32 {
        self.props().intensity()
    }

    pub fn set_intensity(&self, value: f32) {
        self.props().set_intensity(&*self.0, value)
    }
}

light_handle!(
    /// A light from a point (WinUI `Microsoft.UI.Composition.PointLight`):
    /// a point of a visual is lit by the cosine of the angle of the light to
    /// the visual, weakened by the attenuation of the distance
    /// `1 / (constant + linear * d + quadratic * d^2)` between the minimum and
    /// the maximum cutoff. Every member but `CoordinateSpace` is animatable.
    PointLight,
    Point,
    PointLightProps
);

impl PointLight {
    pub(crate) fn new(compositor: &Rc<Compositor>) -> PointLight {
        PointLight(CompositionLight::create(
            compositor,
            CompositionLightKind::Point(PointLightProps::new()),
            |c| ServerPointLight::new(c),
        ))
    }

    /// The colour of the light (default white).
    pub fn color(&self) -> Color {
        self.props().color()
    }

    pub fn set_color(&self, value: Color) {
        self.props().set_color(&*self.0, value)
    }

    /// The constant term of the attenuation (default 1).
    pub fn constant_attenuation(&self) -> f32 {
        self.props().constant_attenuation()
    }

    pub fn set_constant_attenuation(&self, value: f32) {
        self.props().set_constant_attenuation(&*self.0, value)
    }

    /// The term of the attenuation proportional to the distance (default 0).
    pub fn linear_attenuation(&self) -> f32 {
        self.props().linear_attenuation()
    }

    pub fn set_linear_attenuation(&self, value: f32) {
        self.props().set_linear_attenuation(&*self.0, value)
    }

    /// The term of the attenuation proportional to the square of the
    /// distance (default 0).
    pub fn quadratic_attenuation(&self) -> f32 {
        self.props().quadratic_attenuation()
    }

    pub fn set_quadratic_attenuation(&self, value: f32) {
        self.props().set_quadratic_attenuation(&*self.0, value)
    }

    /// The visual whose coordinates `Offset` is in; `None` for the targeted
    /// visual.
    pub fn coordinate_space(&self) -> Option<Rc<CompositionVisual>> {
        as_visual(self.props().coordinate_space())
    }

    pub fn set_coordinate_space(&self, value: Option<Rc<CompositionVisual>>) {
        self.props().set_coordinate_space(&*self.0, as_object(value))
    }

    /// The position of the light in its coordinate space; Z is the height
    /// above the visuals.
    pub fn offset(&self) -> Vector3D {
        self.props().offset()
    }

    pub fn set_offset(&self, value: Vector3D) {
        self.props().set_offset(&*self.0, value)
    }

    /// The intensity of the light (default 1).
    pub fn intensity(&self) -> f32 {
        self.props().intensity()
    }

    pub fn set_intensity(&self, value: f32) {
        self.props().set_intensity(&*self.0, value)
    }

    /// The distance up to which the light is not attenuated (default 0).
    pub fn min_attenuation_cutoff(&self) -> f32 {
        self.props().min_attenuation_cutoff()
    }

    pub fn set_min_attenuation_cutoff(&self, value: f32) {
        self.props().set_min_attenuation_cutoff(&*self.0, value)
    }

    /// The distance beyond which the light lights nothing (default
    /// `f32::MAX`).
    pub fn max_attenuation_cutoff(&self) -> f32 {
        self.props().max_attenuation_cutoff()
    }

    pub fn set_max_attenuation_cutoff(&self, value: f32) {
        self.props().set_max_attenuation_cutoff(&*self.0, value)
    }
}

light_handle!(
    /// A light from a point into a cone (WinUI
    /// `Microsoft.UI.Composition.SpotLight`): a point light whose light is
    /// the inner cone colour inside the inner cone, falls off to the outer
    /// cone colour and to nothing at the edge of the outer cone, and is
    /// nothing outside it. The cone angles are measured from the direction
    /// to the edge of the cone, in radians. Every member but
    /// `CoordinateSpace` is animatable.
    ///
    /// Deviation (winui-composition.md): `InnerConeAngleInDegrees` and
    /// `OuterConeAngleInDegrees` are views of the radians and cannot be the
    /// target of an animation.
    SpotLight,
    Spot,
    SpotLightProps
);

impl SpotLight {
    pub(crate) fn new(compositor: &Rc<Compositor>) -> SpotLight {
        SpotLight(CompositionLight::create(
            compositor,
            CompositionLightKind::Spot(SpotLightProps::new()),
            |c| ServerSpotLight::new(c),
        ))
    }

    /// The constant term of the attenuation (default 1).
    pub fn constant_attenuation(&self) -> f32 {
        self.props().constant_attenuation()
    }

    pub fn set_constant_attenuation(&self, value: f32) {
        self.props().set_constant_attenuation(&*self.0, value)
    }

    /// The term of the attenuation proportional to the distance (default 0).
    pub fn linear_attenuation(&self) -> f32 {
        self.props().linear_attenuation()
    }

    pub fn set_linear_attenuation(&self, value: f32) {
        self.props().set_linear_attenuation(&*self.0, value)
    }

    /// The term of the attenuation proportional to the square of the
    /// distance (default 0).
    pub fn quadratic_attenuation(&self) -> f32 {
        self.props().quadratic_attenuation()
    }

    pub fn set_quadratic_attenuation(&self, value: f32) {
        self.props().set_quadratic_attenuation(&*self.0, value)
    }

    /// The visual whose coordinates `Offset` and `Direction` are in; `None`
    /// for the targeted visual.
    pub fn coordinate_space(&self) -> Option<Rc<CompositionVisual>> {
        as_visual(self.props().coordinate_space())
    }

    pub fn set_coordinate_space(&self, value: Option<Rc<CompositionVisual>>) {
        self.props().set_coordinate_space(&*self.0, as_object(value))
    }

    /// The direction the light shines in (default `(0, 0, -1)`).
    pub fn direction(&self) -> Vector3D {
        self.props().direction()
    }

    pub fn set_direction(&self, value: Vector3D) {
        self.props().set_direction(&*self.0, value)
    }

    /// The angle from the direction to the edge of the inner cone, in
    /// radians (default 0).
    pub fn inner_cone_angle(&self) -> f32 {
        self.props().inner_cone_angle()
    }

    pub fn set_inner_cone_angle(&self, value: f32) {
        self.props().set_inner_cone_angle(&*self.0, value)
    }

    /// The inner cone angle in degrees: a view of
    /// [`inner_cone_angle`](Self::inner_cone_angle).
    pub fn inner_cone_angle_in_degrees(&self) -> f32 {
        self.inner_cone_angle().to_degrees()
    }

    pub fn set_inner_cone_angle_in_degrees(&self, value: f32) {
        self.set_inner_cone_angle(value.to_radians())
    }

    /// The colour of the light inside the inner cone (default white).
    pub fn inner_cone_color(&self) -> Color {
        self.props().inner_cone_color()
    }

    pub fn set_inner_cone_color(&self, value: Color) {
        self.props().set_inner_cone_color(&*self.0, value)
    }

    /// The intensity of the light inside the inner cone (default 1).
    pub fn inner_cone_intensity(&self) -> f32 {
        self.props().inner_cone_intensity()
    }

    pub fn set_inner_cone_intensity(&self, value: f32) {
        self.props().set_inner_cone_intensity(&*self.0, value)
    }

    /// The angle from the direction to the edge of the outer cone, in
    /// radians (default pi / 4).
    pub fn outer_cone_angle(&self) -> f32 {
        self.props().outer_cone_angle()
    }

    pub fn set_outer_cone_angle(&self, value: f32) {
        self.props().set_outer_cone_angle(&*self.0, value)
    }

    /// The outer cone angle in degrees: a view of
    /// [`outer_cone_angle`](Self::outer_cone_angle).
    pub fn outer_cone_angle_in_degrees(&self) -> f32 {
        self.outer_cone_angle().to_degrees()
    }

    pub fn set_outer_cone_angle_in_degrees(&self, value: f32) {
        self.set_outer_cone_angle(value.to_radians())
    }

    /// The colour of the light between the inner and the outer cone
    /// (default white).
    pub fn outer_cone_color(&self) -> Color {
        self.props().outer_cone_color()
    }

    pub fn set_outer_cone_color(&self, value: Color) {
        self.props().set_outer_cone_color(&*self.0, value)
    }

    /// The intensity of the light between the inner and the outer cone
    /// (default 1).
    pub fn outer_cone_intensity(&self) -> f32 {
        self.props().outer_cone_intensity()
    }

    pub fn set_outer_cone_intensity(&self, value: f32) {
        self.props().set_outer_cone_intensity(&*self.0, value)
    }

    /// The position of the light in its coordinate space; Z is the height
    /// above the visuals.
    pub fn offset(&self) -> Vector3D {
        self.props().offset()
    }

    pub fn set_offset(&self, value: Vector3D) {
        self.props().set_offset(&*self.0, value)
    }

    /// The distance up to which the light is not attenuated (default 0).
    pub fn min_attenuation_cutoff(&self) -> f32 {
        self.props().min_attenuation_cutoff()
    }

    pub fn set_min_attenuation_cutoff(&self, value: f32) {
        self.props().set_min_attenuation_cutoff(&*self.0, value)
    }

    /// The distance beyond which the light lights nothing (default
    /// `f32::MAX`).
    pub fn max_attenuation_cutoff(&self) -> f32 {
        self.props().max_attenuation_cutoff()
    }

    pub fn set_max_attenuation_cutoff(&self, value: f32) {
        self.props().set_max_attenuation_cutoff(&*self.0, value)
    }
}

impl Compositor {
    /// `CreateAmbientLight`.
    pub fn create_ambient_light(&self) -> AmbientLight {
        AmbientLight::new(&self.this_handle())
    }

    /// `CreateDistantLight`.
    pub fn create_distant_light(&self) -> DistantLight {
        DistantLight::new(&self.this_handle())
    }

    /// `CreatePointLight`.
    pub fn create_point_light(&self) -> PointLight {
        PointLight::new(&self.this_handle())
    }

    /// `CreateSpotLight`.
    pub fn create_spot_light(&self) -> SpotLight {
        SpotLight::new(&self.this_handle())
    }
}