rust_tdlib/types/
theme_settings.rs1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct ThemeSettings {
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 #[serde(default)]
16 accent_color: i32,
17 background: Option<Background>,
19 #[serde(skip_serializing_if = "BackgroundFill::_is_default")]
22 outgoing_message_fill: BackgroundFill,
23 #[serde(default)]
26 animate_outgoing_message_fill: bool,
27 #[serde(default)]
30 outgoing_message_accent_color: i32,
31}
32
33impl RObject for ThemeSettings {
34 #[doc(hidden)]
35 fn extra(&self) -> Option<&str> {
36 self.extra.as_deref()
37 }
38 #[doc(hidden)]
39 fn client_id(&self) -> Option<i32> {
40 self.client_id
41 }
42}
43
44impl ThemeSettings {
45 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
46 Ok(serde_json::from_str(json.as_ref())?)
47 }
48 pub fn builder() -> ThemeSettingsBuilder {
49 let mut inner = ThemeSettings::default();
50 inner.extra = Some(Uuid::new_v4().to_string());
51
52 ThemeSettingsBuilder { inner }
53 }
54
55 pub fn accent_color(&self) -> i32 {
56 self.accent_color
57 }
58
59 pub fn background(&self) -> &Option<Background> {
60 &self.background
61 }
62
63 pub fn outgoing_message_fill(&self) -> &BackgroundFill {
64 &self.outgoing_message_fill
65 }
66
67 pub fn animate_outgoing_message_fill(&self) -> bool {
68 self.animate_outgoing_message_fill
69 }
70
71 pub fn outgoing_message_accent_color(&self) -> i32 {
72 self.outgoing_message_accent_color
73 }
74}
75
76#[doc(hidden)]
77pub struct ThemeSettingsBuilder {
78 inner: ThemeSettings,
79}
80
81#[deprecated]
82pub type RTDThemeSettingsBuilder = ThemeSettingsBuilder;
83
84impl ThemeSettingsBuilder {
85 pub fn build(&self) -> ThemeSettings {
86 self.inner.clone()
87 }
88
89 pub fn accent_color(&mut self, accent_color: i32) -> &mut Self {
90 self.inner.accent_color = accent_color;
91 self
92 }
93
94 pub fn background<T: AsRef<Background>>(&mut self, background: T) -> &mut Self {
95 self.inner.background = Some(background.as_ref().clone());
96 self
97 }
98
99 pub fn outgoing_message_fill<T: AsRef<BackgroundFill>>(
100 &mut self,
101 outgoing_message_fill: T,
102 ) -> &mut Self {
103 self.inner.outgoing_message_fill = outgoing_message_fill.as_ref().clone();
104 self
105 }
106
107 pub fn animate_outgoing_message_fill(
108 &mut self,
109 animate_outgoing_message_fill: bool,
110 ) -> &mut Self {
111 self.inner.animate_outgoing_message_fill = animate_outgoing_message_fill;
112 self
113 }
114
115 pub fn outgoing_message_accent_color(
116 &mut self,
117 outgoing_message_accent_color: i32,
118 ) -> &mut Self {
119 self.inner.outgoing_message_accent_color = outgoing_message_accent_color;
120 self
121 }
122}
123
124impl AsRef<ThemeSettings> for ThemeSettings {
125 fn as_ref(&self) -> &ThemeSettings {
126 self
127 }
128}
129
130impl AsRef<ThemeSettings> for ThemeSettingsBuilder {
131 fn as_ref(&self) -> &ThemeSettings {
132 &self.inner
133 }
134}