rust_tdlib/types/
mask_position.rs

1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5/// Position on a photo where a mask is placed
6#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct MaskPosition {
8    #[doc(hidden)]
9    #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
10    extra: Option<String>,
11    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
12    client_id: Option<i32>,
13    /// Part of the face, relative to which the mask is placed
14
15    #[serde(skip_serializing_if = "MaskPoint::_is_default")]
16    point: MaskPoint,
17    /// Shift by X-axis measured in widths of the mask scaled to the face size, from left to right. (For example, 1.0 will place the mask just to the left of the default mask position)
18
19    #[serde(default)]
20    x_shift: f32,
21    /// Shift by Y-axis measured in heights of the mask scaled to the face size, from top to bottom. (For example, 1.0 will place the mask just below the default mask position)
22
23    #[serde(default)]
24    y_shift: f32,
25    /// Mask scaling coefficient. (For example, 2.0 means a doubled size)
26
27    #[serde(default)]
28    scale: f32,
29}
30
31impl RObject for MaskPosition {
32    #[doc(hidden)]
33    fn extra(&self) -> Option<&str> {
34        self.extra.as_deref()
35    }
36    #[doc(hidden)]
37    fn client_id(&self) -> Option<i32> {
38        self.client_id
39    }
40}
41
42impl MaskPosition {
43    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
44        Ok(serde_json::from_str(json.as_ref())?)
45    }
46    pub fn builder() -> MaskPositionBuilder {
47        let mut inner = MaskPosition::default();
48        inner.extra = Some(Uuid::new_v4().to_string());
49
50        MaskPositionBuilder { inner }
51    }
52
53    pub fn point(&self) -> &MaskPoint {
54        &self.point
55    }
56
57    pub fn x_shift(&self) -> f32 {
58        self.x_shift
59    }
60
61    pub fn y_shift(&self) -> f32 {
62        self.y_shift
63    }
64
65    pub fn scale(&self) -> f32 {
66        self.scale
67    }
68}
69
70#[doc(hidden)]
71pub struct MaskPositionBuilder {
72    inner: MaskPosition,
73}
74
75#[deprecated]
76pub type RTDMaskPositionBuilder = MaskPositionBuilder;
77
78impl MaskPositionBuilder {
79    pub fn build(&self) -> MaskPosition {
80        self.inner.clone()
81    }
82
83    pub fn point<T: AsRef<MaskPoint>>(&mut self, point: T) -> &mut Self {
84        self.inner.point = point.as_ref().clone();
85        self
86    }
87
88    pub fn x_shift(&mut self, x_shift: f32) -> &mut Self {
89        self.inner.x_shift = x_shift;
90        self
91    }
92
93    pub fn y_shift(&mut self, y_shift: f32) -> &mut Self {
94        self.inner.y_shift = y_shift;
95        self
96    }
97
98    pub fn scale(&mut self, scale: f32) -> &mut Self {
99        self.inner.scale = scale;
100        self
101    }
102}
103
104impl AsRef<MaskPosition> for MaskPosition {
105    fn as_ref(&self) -> &MaskPosition {
106        self
107    }
108}
109
110impl AsRef<MaskPosition> for MaskPositionBuilder {
111    fn as_ref(&self) -> &MaskPosition {
112        &self.inner
113    }
114}