1use crate::{
6 ffi, Accessible, AccessibleRole, Align, Buildable, ColorChooser, ConstraintTarget,
7 LayoutManager, Overflow, Widget,
8};
9use glib::{
10 prelude::*,
11 signal::{connect_raw, SignalHandlerId},
12 translate::*,
13};
14use std::boxed::Box as Box_;
15
16glib::wrapper! {
17 #[doc(alias = "GtkColorChooserWidget")]
18 pub struct ColorChooserWidget(Object<ffi::GtkColorChooserWidget>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget, ColorChooser;
19
20 match fn {
21 type_ => || ffi::gtk_color_chooser_widget_get_type(),
22 }
23}
24
25impl ColorChooserWidget {
26 #[doc(alias = "gtk_color_chooser_widget_new")]
27 pub fn new() -> ColorChooserWidget {
28 assert_initialized_main_thread!();
29 unsafe { Widget::from_glib_none(ffi::gtk_color_chooser_widget_new()).unsafe_cast() }
30 }
31
32 pub fn builder() -> ColorChooserWidgetBuilder {
37 ColorChooserWidgetBuilder::new()
38 }
39
40 #[doc(alias = "show-editor")]
41 pub fn shows_editor(&self) -> bool {
42 ObjectExt::property(self, "show-editor")
43 }
44
45 #[doc(alias = "show-editor")]
46 pub fn set_show_editor(&self, show_editor: bool) {
47 ObjectExt::set_property(self, "show-editor", show_editor)
48 }
49
50 #[doc(alias = "show-editor")]
51 pub fn connect_show_editor_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
52 unsafe extern "C" fn notify_show_editor_trampoline<F: Fn(&ColorChooserWidget) + 'static>(
53 this: *mut ffi::GtkColorChooserWidget,
54 _param_spec: glib::ffi::gpointer,
55 f: glib::ffi::gpointer,
56 ) {
57 let f: &F = &*(f as *const F);
58 f(&from_glib_borrow(this))
59 }
60 unsafe {
61 let f: Box_<F> = Box_::new(f);
62 connect_raw(
63 self.as_ptr() as *mut _,
64 c"notify::show-editor".as_ptr() as *const _,
65 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
66 notify_show_editor_trampoline::<F> as *const (),
67 )),
68 Box_::into_raw(f),
69 )
70 }
71 }
72}
73
74impl Default for ColorChooserWidget {
75 fn default() -> Self {
76 Self::new()
77 }
78}
79
80#[must_use = "The builder must be built to be used"]
85pub struct ColorChooserWidgetBuilder {
86 builder: glib::object::ObjectBuilder<'static, ColorChooserWidget>,
87}
88
89impl ColorChooserWidgetBuilder {
90 fn new() -> Self {
91 Self {
92 builder: glib::object::Object::builder(),
93 }
94 }
95
96 pub fn show_editor(self, show_editor: bool) -> Self {
97 Self {
98 builder: self.builder.property("show-editor", show_editor),
99 }
100 }
101
102 pub fn can_focus(self, can_focus: bool) -> Self {
103 Self {
104 builder: self.builder.property("can-focus", can_focus),
105 }
106 }
107
108 pub fn can_target(self, can_target: bool) -> Self {
109 Self {
110 builder: self.builder.property("can-target", can_target),
111 }
112 }
113
114 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
115 Self {
116 builder: self.builder.property("css-classes", css_classes.into()),
117 }
118 }
119
120 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
121 Self {
122 builder: self.builder.property("css-name", css_name.into()),
123 }
124 }
125
126 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
127 Self {
128 builder: self.builder.property("cursor", cursor.clone()),
129 }
130 }
131
132 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
133 Self {
134 builder: self.builder.property("focus-on-click", focus_on_click),
135 }
136 }
137
138 pub fn focusable(self, focusable: bool) -> Self {
139 Self {
140 builder: self.builder.property("focusable", focusable),
141 }
142 }
143
144 pub fn halign(self, halign: Align) -> Self {
145 Self {
146 builder: self.builder.property("halign", halign),
147 }
148 }
149
150 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
151 Self {
152 builder: self.builder.property("has-tooltip", has_tooltip),
153 }
154 }
155
156 pub fn height_request(self, height_request: i32) -> Self {
157 Self {
158 builder: self.builder.property("height-request", height_request),
159 }
160 }
161
162 pub fn hexpand(self, hexpand: bool) -> Self {
163 Self {
164 builder: self.builder.property("hexpand", hexpand),
165 }
166 }
167
168 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
169 Self {
170 builder: self.builder.property("hexpand-set", hexpand_set),
171 }
172 }
173
174 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
175 Self {
176 builder: self
177 .builder
178 .property("layout-manager", layout_manager.clone().upcast()),
179 }
180 }
181
182 #[cfg(feature = "v4_18")]
183 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
184 pub fn limit_events(self, limit_events: bool) -> Self {
185 Self {
186 builder: self.builder.property("limit-events", limit_events),
187 }
188 }
189
190 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
191 Self {
192 builder: self.builder.property("margin-bottom", margin_bottom),
193 }
194 }
195
196 pub fn margin_end(self, margin_end: i32) -> Self {
197 Self {
198 builder: self.builder.property("margin-end", margin_end),
199 }
200 }
201
202 pub fn margin_start(self, margin_start: i32) -> Self {
203 Self {
204 builder: self.builder.property("margin-start", margin_start),
205 }
206 }
207
208 pub fn margin_top(self, margin_top: i32) -> Self {
209 Self {
210 builder: self.builder.property("margin-top", margin_top),
211 }
212 }
213
214 pub fn name(self, name: impl Into<glib::GString>) -> Self {
215 Self {
216 builder: self.builder.property("name", name.into()),
217 }
218 }
219
220 pub fn opacity(self, opacity: f64) -> Self {
221 Self {
222 builder: self.builder.property("opacity", opacity),
223 }
224 }
225
226 pub fn overflow(self, overflow: Overflow) -> Self {
227 Self {
228 builder: self.builder.property("overflow", overflow),
229 }
230 }
231
232 pub fn receives_default(self, receives_default: bool) -> Self {
233 Self {
234 builder: self.builder.property("receives-default", receives_default),
235 }
236 }
237
238 pub fn sensitive(self, sensitive: bool) -> Self {
239 Self {
240 builder: self.builder.property("sensitive", sensitive),
241 }
242 }
243
244 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
245 Self {
246 builder: self
247 .builder
248 .property("tooltip-markup", tooltip_markup.into()),
249 }
250 }
251
252 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
253 Self {
254 builder: self.builder.property("tooltip-text", tooltip_text.into()),
255 }
256 }
257
258 pub fn valign(self, valign: Align) -> Self {
259 Self {
260 builder: self.builder.property("valign", valign),
261 }
262 }
263
264 pub fn vexpand(self, vexpand: bool) -> Self {
265 Self {
266 builder: self.builder.property("vexpand", vexpand),
267 }
268 }
269
270 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
271 Self {
272 builder: self.builder.property("vexpand-set", vexpand_set),
273 }
274 }
275
276 pub fn visible(self, visible: bool) -> Self {
277 Self {
278 builder: self.builder.property("visible", visible),
279 }
280 }
281
282 pub fn width_request(self, width_request: i32) -> Self {
283 Self {
284 builder: self.builder.property("width-request", width_request),
285 }
286 }
287
288 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
289 Self {
290 builder: self.builder.property("accessible-role", accessible_role),
291 }
292 }
293
294 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
295 pub fn rgba(self, rgba: &gdk::RGBA) -> Self {
296 Self {
297 builder: self.builder.property("rgba", rgba),
298 }
299 }
300
301 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
302 pub fn use_alpha(self, use_alpha: bool) -> Self {
303 Self {
304 builder: self.builder.property("use-alpha", use_alpha),
305 }
306 }
307
308 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
311 pub fn build(self) -> ColorChooserWidget {
312 assert_initialized_main_thread!();
313 self.builder.build()
314 }
315}