1use std::cmp;
4
5use glib::{translate::*, Quark};
6
7use crate::{ffi, prelude::*, CssParserWarning, Ordering};
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)]
59#[non_exhaustive]
60#[doc(alias = "GtkAlign")]
61pub enum Align {
62 #[doc(alias = "GTK_ALIGN_FILL")]
63 Fill,
64 #[doc(alias = "GTK_ALIGN_START")]
65 Start,
66 #[doc(alias = "GTK_ALIGN_END")]
67 End,
68 #[doc(alias = "GTK_ALIGN_CENTER")]
69 Center,
70 #[doc(alias = "GTK_ALIGN_BASELINE")]
71 Baseline,
72 #[cfg(feature = "v4_12")]
73 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
74 #[doc(alias = "GTK_ALIGN_BASELINE_FILL")]
75 BaselineFill,
76 #[cfg(feature = "v4_12")]
77 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
78 #[doc(alias = "GTK_ALIGN_BASELINE_CENTER")]
79 BaselineCenter,
80 #[doc(hidden)]
81 __Unknown(i32),
82}
83
84impl std::fmt::Display for Align {
85 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
86 write!(
87 f,
88 "Align::{}",
89 match *self {
90 Self::Fill => "Fill",
91 Self::Start => "Start",
92 Self::End => "End",
93 Self::Center => "Center",
94 Self::Baseline => "Baseline",
95 #[cfg(feature = "v4_12")]
96 Self::BaselineFill => "BaselineFill",
97 #[cfg(feature = "v4_12")]
98 Self::BaselineCenter => "BaselineCenter",
99 _ => "Unknown",
100 }
101 )
102 }
103}
104
105#[doc(hidden)]
106impl IntoGlib for Align {
107 type GlibType = ffi::GtkAlign;
108
109 #[inline]
110 fn into_glib(self) -> ffi::GtkAlign {
111 match self {
112 Self::Fill => ffi::GTK_ALIGN_FILL,
113 Self::Start => ffi::GTK_ALIGN_START,
114 Self::End => ffi::GTK_ALIGN_END,
115 Self::Center => ffi::GTK_ALIGN_CENTER,
116 #[cfg(not(feature = "v4_12"))]
117 Self::Baseline => ffi::GTK_ALIGN_BASELINE,
118 #[cfg(feature = "v4_12")]
119 Self::BaselineFill | Self::Baseline => ffi::GTK_ALIGN_BASELINE_FILL,
120 #[cfg(feature = "v4_12")]
121 Self::BaselineCenter => ffi::GTK_ALIGN_BASELINE_CENTER,
122 Self::__Unknown(value) => value,
123 }
124 }
125}
126
127#[doc(hidden)]
128impl FromGlib<ffi::GtkAlign> for Align {
129 #[inline]
130 unsafe fn from_glib(value: ffi::GtkAlign) -> Self {
131 skip_assert_initialized!();
132
133 match value {
134 ffi::GTK_ALIGN_FILL => Self::Fill,
135 ffi::GTK_ALIGN_START => Self::Start,
136 ffi::GTK_ALIGN_END => Self::End,
137 ffi::GTK_ALIGN_CENTER => Self::Center,
138 #[cfg(not(feature = "v4_12"))]
139 ffi::GTK_ALIGN_BASELINE => Self::Baseline,
140 #[cfg(feature = "v4_12")]
141 ffi::GTK_ALIGN_BASELINE_FILL => Self::BaselineFill,
142 #[cfg(feature = "v4_12")]
143 ffi::GTK_ALIGN_BASELINE_CENTER => Self::BaselineCenter,
144 value => Self::__Unknown(value),
145 }
146 }
147}
148
149impl StaticType for Align {
150 #[inline]
151 #[doc(alias = "gtk_align_get_type")]
152 fn static_type() -> glib::Type {
153 unsafe { from_glib(ffi::gtk_align_get_type()) }
154 }
155}
156
157impl glib::HasParamSpec for Align {
158 type ParamSpec = glib::ParamSpecEnum;
159 type SetValue = Self;
160 type BuilderFn = fn(&str, Self) -> glib::ParamSpecEnumBuilder<Self>;
161
162 fn param_spec_builder() -> Self::BuilderFn {
163 Self::ParamSpec::builder_with_default
164 }
165}
166
167impl glib::value::ValueType for Align {
168 type Type = Self;
169}
170
171unsafe impl<'a> glib::value::FromValue<'a> for Align {
172 type Checker = glib::value::GenericValueTypeChecker<Self>;
173
174 #[inline]
175 unsafe fn from_value(value: &'a glib::Value) -> Self {
176 skip_assert_initialized!();
177 from_glib(glib::gobject_ffi::g_value_get_enum(value.to_glib_none().0))
178 }
179}
180
181impl glib::value::ToValue for Align {
182 #[inline]
183 fn to_value(&self) -> glib::Value {
184 let mut value = glib::Value::for_value_type::<Self>();
185 unsafe {
186 glib::gobject_ffi::g_value_set_enum(value.to_glib_none_mut().0, self.into_glib());
187 }
188 value
189 }
190
191 #[inline]
192 fn value_type(&self) -> glib::Type {
193 Self::static_type()
194 }
195}
196
197impl From<Align> for glib::Value {
198 #[inline]
199 fn from(v: Align) -> Self {
200 skip_assert_initialized!();
201 glib::value::ToValue::to_value(&v)
202 }
203}