1use crate::{
6 ffi, Accessible, AccessibleRole, Align, Buildable, ColorDialog, ConstraintTarget,
7 LayoutManager, Overflow, Widget,
8};
9#[cfg(feature = "v4_14")]
10#[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
11use glib::object::ObjectType as _;
12use glib::{
13 prelude::*,
14 signal::{connect_raw, SignalHandlerId},
15 translate::*,
16};
17use std::boxed::Box as Box_;
18
19glib::wrapper! {
20 #[doc(alias = "GtkColorDialogButton")]
21 pub struct ColorDialogButton(Object<ffi::GtkColorDialogButton, ffi::GtkColorDialogButtonClass>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget;
22
23 match fn {
24 type_ => || ffi::gtk_color_dialog_button_get_type(),
25 }
26}
27
28impl ColorDialogButton {
29 #[doc(alias = "gtk_color_dialog_button_new")]
30 pub fn new(dialog: Option<ColorDialog>) -> ColorDialogButton {
31 assert_initialized_main_thread!();
32 unsafe {
33 Widget::from_glib_none(ffi::gtk_color_dialog_button_new(dialog.into_glib_ptr()))
34 .unsafe_cast()
35 }
36 }
37
38 pub fn builder() -> ColorDialogButtonBuilder {
43 ColorDialogButtonBuilder::new()
44 }
45
46 #[doc(alias = "gtk_color_dialog_button_get_dialog")]
47 #[doc(alias = "get_dialog")]
48 pub fn dialog(&self) -> Option<ColorDialog> {
49 unsafe {
50 from_glib_none(ffi::gtk_color_dialog_button_get_dialog(
51 self.to_glib_none().0,
52 ))
53 }
54 }
55
56 #[doc(alias = "gtk_color_dialog_button_get_rgba")]
57 #[doc(alias = "get_rgba")]
58 pub fn rgba(&self) -> gdk::RGBA {
59 unsafe { from_glib_none(ffi::gtk_color_dialog_button_get_rgba(self.to_glib_none().0)) }
60 }
61
62 #[doc(alias = "gtk_color_dialog_button_set_dialog")]
63 #[doc(alias = "dialog")]
64 pub fn set_dialog(&self, dialog: &ColorDialog) {
65 unsafe {
66 ffi::gtk_color_dialog_button_set_dialog(self.to_glib_none().0, dialog.to_glib_none().0);
67 }
68 }
69
70 #[doc(alias = "gtk_color_dialog_button_set_rgba")]
71 #[doc(alias = "rgba")]
72 pub fn set_rgba(&self, color: &gdk::RGBA) {
73 unsafe {
74 ffi::gtk_color_dialog_button_set_rgba(self.to_glib_none().0, color.to_glib_none().0);
75 }
76 }
77
78 #[cfg(feature = "v4_14")]
79 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
80 #[doc(alias = "activate")]
81 pub fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
82 unsafe extern "C" fn activate_trampoline<F: Fn(&ColorDialogButton) + 'static>(
83 this: *mut ffi::GtkColorDialogButton,
84 f: glib::ffi::gpointer,
85 ) {
86 let f: &F = &*(f as *const F);
87 f(&from_glib_borrow(this))
88 }
89 unsafe {
90 let f: Box_<F> = Box_::new(f);
91 connect_raw(
92 self.as_ptr() as *mut _,
93 c"activate".as_ptr() as *const _,
94 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
95 activate_trampoline::<F> as *const (),
96 )),
97 Box_::into_raw(f),
98 )
99 }
100 }
101
102 #[cfg(feature = "v4_14")]
103 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
104 pub fn emit_activate(&self) {
105 self.emit_by_name::<()>("activate", &[]);
106 }
107
108 #[cfg(feature = "v4_10")]
109 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
110 #[doc(alias = "dialog")]
111 pub fn connect_dialog_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
112 unsafe extern "C" fn notify_dialog_trampoline<F: Fn(&ColorDialogButton) + 'static>(
113 this: *mut ffi::GtkColorDialogButton,
114 _param_spec: glib::ffi::gpointer,
115 f: glib::ffi::gpointer,
116 ) {
117 let f: &F = &*(f as *const F);
118 f(&from_glib_borrow(this))
119 }
120 unsafe {
121 let f: Box_<F> = Box_::new(f);
122 connect_raw(
123 self.as_ptr() as *mut _,
124 c"notify::dialog".as_ptr() as *const _,
125 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
126 notify_dialog_trampoline::<F> as *const (),
127 )),
128 Box_::into_raw(f),
129 )
130 }
131 }
132
133 #[cfg(feature = "v4_10")]
134 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
135 #[doc(alias = "rgba")]
136 pub fn connect_rgba_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
137 unsafe extern "C" fn notify_rgba_trampoline<F: Fn(&ColorDialogButton) + 'static>(
138 this: *mut ffi::GtkColorDialogButton,
139 _param_spec: glib::ffi::gpointer,
140 f: glib::ffi::gpointer,
141 ) {
142 let f: &F = &*(f as *const F);
143 f(&from_glib_borrow(this))
144 }
145 unsafe {
146 let f: Box_<F> = Box_::new(f);
147 connect_raw(
148 self.as_ptr() as *mut _,
149 c"notify::rgba".as_ptr() as *const _,
150 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
151 notify_rgba_trampoline::<F> as *const (),
152 )),
153 Box_::into_raw(f),
154 )
155 }
156 }
157}
158
159#[cfg(feature = "v4_10")]
160#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
161impl Default for ColorDialogButton {
162 fn default() -> Self {
163 glib::object::Object::new::<Self>()
164 }
165}
166
167#[must_use = "The builder must be built to be used"]
172pub struct ColorDialogButtonBuilder {
173 builder: glib::object::ObjectBuilder<'static, ColorDialogButton>,
174}
175
176impl ColorDialogButtonBuilder {
177 fn new() -> Self {
178 Self {
179 builder: glib::object::Object::builder(),
180 }
181 }
182
183 #[cfg(feature = "v4_10")]
184 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
185 pub fn dialog(self, dialog: &ColorDialog) -> Self {
186 Self {
187 builder: self.builder.property("dialog", dialog.clone()),
188 }
189 }
190
191 #[cfg(feature = "v4_10")]
192 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
193 pub fn rgba(self, rgba: &gdk::RGBA) -> Self {
194 Self {
195 builder: self.builder.property("rgba", rgba),
196 }
197 }
198
199 pub fn can_focus(self, can_focus: bool) -> Self {
200 Self {
201 builder: self.builder.property("can-focus", can_focus),
202 }
203 }
204
205 pub fn can_target(self, can_target: bool) -> Self {
206 Self {
207 builder: self.builder.property("can-target", can_target),
208 }
209 }
210
211 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
212 Self {
213 builder: self.builder.property("css-classes", css_classes.into()),
214 }
215 }
216
217 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
218 Self {
219 builder: self.builder.property("css-name", css_name.into()),
220 }
221 }
222
223 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
224 Self {
225 builder: self.builder.property("cursor", cursor.clone()),
226 }
227 }
228
229 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
230 Self {
231 builder: self.builder.property("focus-on-click", focus_on_click),
232 }
233 }
234
235 pub fn focusable(self, focusable: bool) -> Self {
236 Self {
237 builder: self.builder.property("focusable", focusable),
238 }
239 }
240
241 pub fn halign(self, halign: Align) -> Self {
242 Self {
243 builder: self.builder.property("halign", halign),
244 }
245 }
246
247 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
248 Self {
249 builder: self.builder.property("has-tooltip", has_tooltip),
250 }
251 }
252
253 pub fn height_request(self, height_request: i32) -> Self {
254 Self {
255 builder: self.builder.property("height-request", height_request),
256 }
257 }
258
259 pub fn hexpand(self, hexpand: bool) -> Self {
260 Self {
261 builder: self.builder.property("hexpand", hexpand),
262 }
263 }
264
265 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
266 Self {
267 builder: self.builder.property("hexpand-set", hexpand_set),
268 }
269 }
270
271 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
272 Self {
273 builder: self
274 .builder
275 .property("layout-manager", layout_manager.clone().upcast()),
276 }
277 }
278
279 #[cfg(feature = "v4_18")]
280 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
281 pub fn limit_events(self, limit_events: bool) -> Self {
282 Self {
283 builder: self.builder.property("limit-events", limit_events),
284 }
285 }
286
287 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
288 Self {
289 builder: self.builder.property("margin-bottom", margin_bottom),
290 }
291 }
292
293 pub fn margin_end(self, margin_end: i32) -> Self {
294 Self {
295 builder: self.builder.property("margin-end", margin_end),
296 }
297 }
298
299 pub fn margin_start(self, margin_start: i32) -> Self {
300 Self {
301 builder: self.builder.property("margin-start", margin_start),
302 }
303 }
304
305 pub fn margin_top(self, margin_top: i32) -> Self {
306 Self {
307 builder: self.builder.property("margin-top", margin_top),
308 }
309 }
310
311 pub fn name(self, name: impl Into<glib::GString>) -> Self {
312 Self {
313 builder: self.builder.property("name", name.into()),
314 }
315 }
316
317 pub fn opacity(self, opacity: f64) -> Self {
318 Self {
319 builder: self.builder.property("opacity", opacity),
320 }
321 }
322
323 pub fn overflow(self, overflow: Overflow) -> Self {
324 Self {
325 builder: self.builder.property("overflow", overflow),
326 }
327 }
328
329 pub fn receives_default(self, receives_default: bool) -> Self {
330 Self {
331 builder: self.builder.property("receives-default", receives_default),
332 }
333 }
334
335 pub fn sensitive(self, sensitive: bool) -> Self {
336 Self {
337 builder: self.builder.property("sensitive", sensitive),
338 }
339 }
340
341 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
342 Self {
343 builder: self
344 .builder
345 .property("tooltip-markup", tooltip_markup.into()),
346 }
347 }
348
349 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
350 Self {
351 builder: self.builder.property("tooltip-text", tooltip_text.into()),
352 }
353 }
354
355 pub fn valign(self, valign: Align) -> Self {
356 Self {
357 builder: self.builder.property("valign", valign),
358 }
359 }
360
361 pub fn vexpand(self, vexpand: bool) -> Self {
362 Self {
363 builder: self.builder.property("vexpand", vexpand),
364 }
365 }
366
367 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
368 Self {
369 builder: self.builder.property("vexpand-set", vexpand_set),
370 }
371 }
372
373 pub fn visible(self, visible: bool) -> Self {
374 Self {
375 builder: self.builder.property("visible", visible),
376 }
377 }
378
379 pub fn width_request(self, width_request: i32) -> Self {
380 Self {
381 builder: self.builder.property("width-request", width_request),
382 }
383 }
384
385 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
386 Self {
387 builder: self.builder.property("accessible-role", accessible_role),
388 }
389 }
390
391 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
394 pub fn build(self) -> ColorDialogButton {
395 assert_initialized_main_thread!();
396 self.builder.build()
397 }
398}