Skip to main content

media_pp\elements\source\compositor/
text_layer.rs

1//! [`TextLayer`] — backend-agnostic construction-time settings for a
2//! dynamic text layer, the text sibling of [`super::video_layer::VideoLayer`].
3//! Mirrors that module's own role: plain data only, no backend-specific
4//! implementation. The only backend that currently draws a `TextLayer` is
5//! [`super::d3d11_video_compositor`] (`D3d11TextLayerHandle`); this file
6//! has no D3D11 dependency itself.
7
8use crate::color::Color;
9
10/// Construction-time settings for one text layer, passed to
11/// `D3d11VideoCompositorHandle::add_text_layer` — the
12/// text sibling of [`super::video_layer::VideoLayer`], which `add_source`
13/// takes the same way. `font_data` (raw TTF/OTF bytes; this crate bundles
14/// no font of its own) has no sane default, so — mirroring
15/// [`super::video_layer::VideoLayer::new`], which takes the one field a
16/// caller must supply (`rect`) and defaults the rest — [`Self::new`] takes
17/// only `font_data` and defaults `font_size`/`color`/`x`/`y`, all freely
18/// reassignable before the call to `add_text_layer`.
19#[derive(Debug, Clone)]
20pub struct TextLayer {
21    pub font_data: Vec<u8>,
22    /// Pixel height of rendered glyphs (not a point size).
23    pub font_size: f32,
24    pub color: Color,
25    /// Initial top-left corner of the layer — like `VideoLayer::rect`'s
26    /// `x`/`y`, but with no `width`/`height` counterpart, since a text
27    /// layer's size is only known once something has actually rasterized
28    /// its content (e.g. `D3d11TextLayerHandle::set_text`).
29    pub x: i32,
30    pub y: i32,
31}
32
33impl TextLayer {
34    pub const fn new(font_data: Vec<u8>) -> Self {
35        Self {
36            font_data,
37            font_size: 32.0,
38            color: Color::WHITE,
39            x: 0,
40            y: 0,
41        }
42    }
43}