1use std::cmp;
4
5use glib::{Quark, translate::*};
6
7use crate::{CssParserWarning, Ordering, ffi, prelude::*};
8
9impl From<cmp::Ordering> for Ordering {
10 #[inline]
11 fn from(o: cmp::Ordering) -> Self {
12 skip_assert_initialized!();
13 match o {
14 cmp::Ordering::Equal => Self::Equal,
15 cmp::Ordering::Greater => Self::Larger,
16 cmp::Ordering::Less => Self::Smaller,
17 }
18 }
19}
20
21impl From<Ordering> for cmp::Ordering {
22 #[inline]
23 fn from(o: Ordering) -> Self {
24 skip_assert_initialized!();
25 match o {
26 Ordering::Equal => Self::Equal,
27 Ordering::Larger => Self::Greater,
28 Ordering::Smaller => Self::Less,
29 Ordering::__Unknown(_) => unreachable!(),
30 }
31 }
32}
33
34impl ErrorDomain for CssParserWarning {
35 #[inline]
36 fn domain() -> Quark {
37 skip_assert_initialized!();
38 unsafe { from_glib(ffi::gtk_css_parser_warning_quark()) }
39 }
40
41 #[inline]
42 fn code(self) -> i32 {
43 self.into_glib()
44 }
45
46 #[inline]
47 fn from(code: i32) -> Option<Self> {
48 skip_assert_initialized!();
49 match code {
50 ffi::GTK_CSS_PARSER_WARNING_DEPRECATED => Some(Self::Deprecated),
51 ffi::GTK_CSS_PARSER_WARNING_SYNTAX => Some(Self::Syntax),
52 ffi::GTK_CSS_PARSER_WARNING_UNIMPLEMENTED => Some(Self::Unimplemented),
53 value => Some(Self::__Unknown(value)),
54 }
55 }
56}
57
58#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)]
73#[non_exhaustive]
74#[doc(alias = "GtkAlign")]
75pub enum Align {
76 #[doc(alias = "GTK_ALIGN_FILL")]
79 Fill,
80 #[doc(alias = "GTK_ALIGN_START")]
82 Start,
83 #[doc(alias = "GTK_ALIGN_END")]
85 End,
86 #[doc(alias = "GTK_ALIGN_CENTER")]
88 Center,
89 #[doc(alias = "GTK_ALIGN_BASELINE")]
92 Baseline,
93 #[cfg(feature = "v4_12")]
95 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
96 #[doc(alias = "GTK_ALIGN_BASELINE_FILL")]
97 BaselineFill,
98 #[cfg(feature = "v4_12")]
100 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
101 #[doc(alias = "GTK_ALIGN_BASELINE_CENTER")]
102 BaselineCenter,
103 #[doc(hidden)]
104 __Unknown(i32),
105}
106
107impl std::fmt::Display for Align {
108 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
109 write!(
110 f,
111 "Align::{}",
112 match *self {
113 Self::Fill => "Fill",
114 Self::Start => "Start",
115 Self::End => "End",
116 Self::Center => "Center",
117 Self::Baseline => "Baseline",
118 #[cfg(feature = "v4_12")]
119 Self::BaselineFill => "BaselineFill",
120 #[cfg(feature = "v4_12")]
121 Self::BaselineCenter => "BaselineCenter",
122 _ => "Unknown",
123 }
124 )
125 }
126}
127
128#[doc(hidden)]
129impl IntoGlib for Align {
130 type GlibType = ffi::GtkAlign;
131
132 #[inline]
133 fn into_glib(self) -> ffi::GtkAlign {
134 match self {
135 Self::Fill => ffi::GTK_ALIGN_FILL,
136 Self::Start => ffi::GTK_ALIGN_START,
137 Self::End => ffi::GTK_ALIGN_END,
138 Self::Center => ffi::GTK_ALIGN_CENTER,
139 #[cfg(not(feature = "v4_12"))]
140 Self::Baseline => ffi::GTK_ALIGN_BASELINE,
141 #[cfg(feature = "v4_12")]
142 Self::BaselineFill | Self::Baseline => ffi::GTK_ALIGN_BASELINE_FILL,
143 #[cfg(feature = "v4_12")]
144 Self::BaselineCenter => ffi::GTK_ALIGN_BASELINE_CENTER,
145 Self::__Unknown(value) => value,
146 }
147 }
148}
149
150#[doc(hidden)]
151impl FromGlib<ffi::GtkAlign> for Align {
152 #[inline]
153 unsafe fn from_glib(value: ffi::GtkAlign) -> Self {
154 skip_assert_initialized!();
155
156 match value {
157 ffi::GTK_ALIGN_FILL => Self::Fill,
158 ffi::GTK_ALIGN_START => Self::Start,
159 ffi::GTK_ALIGN_END => Self::End,
160 ffi::GTK_ALIGN_CENTER => Self::Center,
161 #[cfg(not(feature = "v4_12"))]
162 ffi::GTK_ALIGN_BASELINE => Self::Baseline,
163 #[cfg(feature = "v4_12")]
164 ffi::GTK_ALIGN_BASELINE_FILL => Self::BaselineFill,
165 #[cfg(feature = "v4_12")]
166 ffi::GTK_ALIGN_BASELINE_CENTER => Self::BaselineCenter,
167 value => Self::__Unknown(value),
168 }
169 }
170}
171
172impl StaticType for Align {
173 #[inline]
174 #[doc(alias = "gtk_align_get_type")]
175 fn static_type() -> glib::Type {
176 unsafe { from_glib(ffi::gtk_align_get_type()) }
177 }
178}
179
180impl glib::HasParamSpec for Align {
181 type ParamSpec = glib::ParamSpecEnum;
182 type SetValue = Self;
183 type BuilderFn = fn(&str, Self) -> glib::ParamSpecEnumBuilder<Self>;
184
185 fn param_spec_builder() -> Self::BuilderFn {
186 Self::ParamSpec::builder_with_default
187 }
188}
189
190impl glib::value::ValueType for Align {
191 type Type = Self;
192}
193
194unsafe impl<'a> glib::value::FromValue<'a> for Align {
195 type Checker = glib::value::GenericValueTypeChecker<Self>;
196
197 #[inline]
198 unsafe fn from_value(value: &'a glib::Value) -> Self {
199 unsafe {
200 skip_assert_initialized!();
201 from_glib(glib::gobject_ffi::g_value_get_enum(value.to_glib_none().0))
202 }
203 }
204}
205
206impl glib::value::ToValue for Align {
207 #[inline]
208 fn to_value(&self) -> glib::Value {
209 let mut value = glib::Value::for_value_type::<Self>();
210 unsafe {
211 glib::gobject_ffi::g_value_set_enum(value.to_glib_none_mut().0, self.into_glib());
212 }
213 value
214 }
215
216 #[inline]
217 fn value_type(&self) -> glib::Type {
218 Self::static_type()
219 }
220}
221
222impl From<Align> for glib::Value {
223 #[inline]
224 fn from(v: Align) -> Self {
225 skip_assert_initialized!();
226 glib::value::ToValue::to_value(&v)
227 }
228}