windows_composition/target.rs
1use super::*;
2
3/// A composition target that hosts a visual tree inside a window.
4///
5/// Created by
6/// [`Compositor::create_desktop_window_target`](crate::Compositor::create_desktop_window_target).
7/// Assign the tree's root with [`set_root`](Self::set_root); the target renders
8/// its root for as long as it is kept alive.
9pub struct DesktopWindowTarget(bindings::CompositionTarget);
10
11impl DesktopWindowTarget {
12 pub(crate) fn new(target: bindings::IDesktopWindowTarget) -> Self {
13 Self(target.cast().unwrap())
14 }
15
16 /// Sets the root visual displayed by the target.
17 pub fn set_root(&self, visual: &Visual) {
18 self.0.SetRoot(&visual.0).unwrap();
19 }
20
21 /// Returns the target's current root visual, if any has been set.
22 pub fn root(&self) -> Option<Visual> {
23 // Before `set_root`, the WinRT getter yields a null reference (surfaced
24 // as an error), which maps to `None` rather than a panic.
25 self.0.Root().ok().map(Visual)
26 }
27}