1#![allow(deprecated)]
5
6use crate::{
7 ffi, Accessible, AccessibleRole, Align, Buildable, ColorChooser, ConstraintTarget,
8 LayoutManager, Overflow, Widget,
9};
10use glib::{
11 object::ObjectType as _,
12 prelude::*,
13 signal::{connect_raw, SignalHandlerId},
14 translate::*,
15};
16use std::boxed::Box as Box_;
17
18glib::wrapper! {
19 #[doc(alias = "GtkColorButton")]
20 pub struct ColorButton(Object<ffi::GtkColorButton>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget, ColorChooser;
21
22 match fn {
23 type_ => || ffi::gtk_color_button_get_type(),
24 }
25}
26
27impl ColorButton {
28 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
29 #[allow(deprecated)]
30 #[doc(alias = "gtk_color_button_new")]
31 pub fn new() -> ColorButton {
32 assert_initialized_main_thread!();
33 unsafe { Widget::from_glib_none(ffi::gtk_color_button_new()).unsafe_cast() }
34 }
35
36 #[doc(alias = "gtk_color_button_new_with_rgba")]
37 #[doc(alias = "new_with_rgba")]
38 pub fn with_rgba(rgba: &gdk::RGBA) -> ColorButton {
39 assert_initialized_main_thread!();
40 unsafe {
41 Widget::from_glib_none(ffi::gtk_color_button_new_with_rgba(rgba.to_glib_none().0))
42 .unsafe_cast()
43 }
44 }
45
46 pub fn builder() -> ColorButtonBuilder {
51 ColorButtonBuilder::new()
52 }
53
54 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
55 #[allow(deprecated)]
56 #[doc(alias = "gtk_color_button_get_modal")]
57 #[doc(alias = "get_modal")]
58 #[doc(alias = "modal")]
59 pub fn is_modal(&self) -> bool {
60 unsafe { from_glib(ffi::gtk_color_button_get_modal(self.to_glib_none().0)) }
61 }
62
63 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
64 #[allow(deprecated)]
65 #[doc(alias = "gtk_color_button_get_title")]
66 #[doc(alias = "get_title")]
67 pub fn title(&self) -> glib::GString {
68 unsafe { from_glib_none(ffi::gtk_color_button_get_title(self.to_glib_none().0)) }
69 }
70
71 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
72 #[allow(deprecated)]
73 #[doc(alias = "gtk_color_button_set_modal")]
74 #[doc(alias = "modal")]
75 pub fn set_modal(&self, modal: bool) {
76 unsafe {
77 ffi::gtk_color_button_set_modal(self.to_glib_none().0, modal.into_glib());
78 }
79 }
80
81 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
82 #[allow(deprecated)]
83 #[doc(alias = "gtk_color_button_set_title")]
84 #[doc(alias = "title")]
85 pub fn set_title(&self, title: &str) {
86 unsafe {
87 ffi::gtk_color_button_set_title(self.to_glib_none().0, title.to_glib_none().0);
88 }
89 }
90
91 #[doc(alias = "show-editor")]
92 pub fn shows_editor(&self) -> bool {
93 ObjectExt::property(self, "show-editor")
94 }
95
96 #[doc(alias = "show-editor")]
97 pub fn set_show_editor(&self, show_editor: bool) {
98 ObjectExt::set_property(self, "show-editor", show_editor)
99 }
100
101 #[cfg(feature = "v4_4")]
102 #[cfg_attr(docsrs, doc(cfg(feature = "v4_4")))]
103 #[doc(alias = "activate")]
104 pub fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
105 unsafe extern "C" fn activate_trampoline<F: Fn(&ColorButton) + 'static>(
106 this: *mut ffi::GtkColorButton,
107 f: glib::ffi::gpointer,
108 ) {
109 let f: &F = &*(f as *const F);
110 f(&from_glib_borrow(this))
111 }
112 unsafe {
113 let f: Box_<F> = Box_::new(f);
114 connect_raw(
115 self.as_ptr() as *mut _,
116 b"activate\0".as_ptr() as *const _,
117 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
118 activate_trampoline::<F> as *const (),
119 )),
120 Box_::into_raw(f),
121 )
122 }
123 }
124
125 #[cfg(feature = "v4_4")]
126 #[cfg_attr(docsrs, doc(cfg(feature = "v4_4")))]
127 pub fn emit_activate(&self) {
128 self.emit_by_name::<()>("activate", &[]);
129 }
130
131 #[doc(alias = "color-set")]
132 pub fn connect_color_set<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
133 unsafe extern "C" fn color_set_trampoline<F: Fn(&ColorButton) + 'static>(
134 this: *mut ffi::GtkColorButton,
135 f: glib::ffi::gpointer,
136 ) {
137 let f: &F = &*(f as *const F);
138 f(&from_glib_borrow(this))
139 }
140 unsafe {
141 let f: Box_<F> = Box_::new(f);
142 connect_raw(
143 self.as_ptr() as *mut _,
144 b"color-set\0".as_ptr() as *const _,
145 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
146 color_set_trampoline::<F> as *const (),
147 )),
148 Box_::into_raw(f),
149 )
150 }
151 }
152
153 #[doc(alias = "modal")]
154 pub fn connect_modal_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
155 unsafe extern "C" fn notify_modal_trampoline<F: Fn(&ColorButton) + 'static>(
156 this: *mut ffi::GtkColorButton,
157 _param_spec: glib::ffi::gpointer,
158 f: glib::ffi::gpointer,
159 ) {
160 let f: &F = &*(f as *const F);
161 f(&from_glib_borrow(this))
162 }
163 unsafe {
164 let f: Box_<F> = Box_::new(f);
165 connect_raw(
166 self.as_ptr() as *mut _,
167 b"notify::modal\0".as_ptr() as *const _,
168 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
169 notify_modal_trampoline::<F> as *const (),
170 )),
171 Box_::into_raw(f),
172 )
173 }
174 }
175
176 #[doc(alias = "show-editor")]
177 pub fn connect_show_editor_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
178 unsafe extern "C" fn notify_show_editor_trampoline<F: Fn(&ColorButton) + 'static>(
179 this: *mut ffi::GtkColorButton,
180 _param_spec: glib::ffi::gpointer,
181 f: glib::ffi::gpointer,
182 ) {
183 let f: &F = &*(f as *const F);
184 f(&from_glib_borrow(this))
185 }
186 unsafe {
187 let f: Box_<F> = Box_::new(f);
188 connect_raw(
189 self.as_ptr() as *mut _,
190 b"notify::show-editor\0".as_ptr() as *const _,
191 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
192 notify_show_editor_trampoline::<F> as *const (),
193 )),
194 Box_::into_raw(f),
195 )
196 }
197 }
198
199 #[doc(alias = "title")]
200 pub fn connect_title_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
201 unsafe extern "C" fn notify_title_trampoline<F: Fn(&ColorButton) + 'static>(
202 this: *mut ffi::GtkColorButton,
203 _param_spec: glib::ffi::gpointer,
204 f: glib::ffi::gpointer,
205 ) {
206 let f: &F = &*(f as *const F);
207 f(&from_glib_borrow(this))
208 }
209 unsafe {
210 let f: Box_<F> = Box_::new(f);
211 connect_raw(
212 self.as_ptr() as *mut _,
213 b"notify::title\0".as_ptr() as *const _,
214 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
215 notify_title_trampoline::<F> as *const (),
216 )),
217 Box_::into_raw(f),
218 )
219 }
220 }
221}
222
223impl Default for ColorButton {
224 fn default() -> Self {
225 Self::new()
226 }
227}
228
229#[must_use = "The builder must be built to be used"]
234pub struct ColorButtonBuilder {
235 builder: glib::object::ObjectBuilder<'static, ColorButton>,
236}
237
238impl ColorButtonBuilder {
239 fn new() -> Self {
240 Self {
241 builder: glib::object::Object::builder(),
242 }
243 }
244
245 pub fn modal(self, modal: bool) -> Self {
246 Self {
247 builder: self.builder.property("modal", modal),
248 }
249 }
250
251 pub fn show_editor(self, show_editor: bool) -> Self {
252 Self {
253 builder: self.builder.property("show-editor", show_editor),
254 }
255 }
256
257 pub fn title(self, title: impl Into<glib::GString>) -> Self {
258 Self {
259 builder: self.builder.property("title", title.into()),
260 }
261 }
262
263 pub fn can_focus(self, can_focus: bool) -> Self {
264 Self {
265 builder: self.builder.property("can-focus", can_focus),
266 }
267 }
268
269 pub fn can_target(self, can_target: bool) -> Self {
270 Self {
271 builder: self.builder.property("can-target", can_target),
272 }
273 }
274
275 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
276 Self {
277 builder: self.builder.property("css-classes", css_classes.into()),
278 }
279 }
280
281 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
282 Self {
283 builder: self.builder.property("css-name", css_name.into()),
284 }
285 }
286
287 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
288 Self {
289 builder: self.builder.property("cursor", cursor.clone()),
290 }
291 }
292
293 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
294 Self {
295 builder: self.builder.property("focus-on-click", focus_on_click),
296 }
297 }
298
299 pub fn focusable(self, focusable: bool) -> Self {
300 Self {
301 builder: self.builder.property("focusable", focusable),
302 }
303 }
304
305 pub fn halign(self, halign: Align) -> Self {
306 Self {
307 builder: self.builder.property("halign", halign),
308 }
309 }
310
311 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
312 Self {
313 builder: self.builder.property("has-tooltip", has_tooltip),
314 }
315 }
316
317 pub fn height_request(self, height_request: i32) -> Self {
318 Self {
319 builder: self.builder.property("height-request", height_request),
320 }
321 }
322
323 pub fn hexpand(self, hexpand: bool) -> Self {
324 Self {
325 builder: self.builder.property("hexpand", hexpand),
326 }
327 }
328
329 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
330 Self {
331 builder: self.builder.property("hexpand-set", hexpand_set),
332 }
333 }
334
335 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
336 Self {
337 builder: self
338 .builder
339 .property("layout-manager", layout_manager.clone().upcast()),
340 }
341 }
342
343 #[cfg(feature = "v4_18")]
344 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
345 pub fn limit_events(self, limit_events: bool) -> Self {
346 Self {
347 builder: self.builder.property("limit-events", limit_events),
348 }
349 }
350
351 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
352 Self {
353 builder: self.builder.property("margin-bottom", margin_bottom),
354 }
355 }
356
357 pub fn margin_end(self, margin_end: i32) -> Self {
358 Self {
359 builder: self.builder.property("margin-end", margin_end),
360 }
361 }
362
363 pub fn margin_start(self, margin_start: i32) -> Self {
364 Self {
365 builder: self.builder.property("margin-start", margin_start),
366 }
367 }
368
369 pub fn margin_top(self, margin_top: i32) -> Self {
370 Self {
371 builder: self.builder.property("margin-top", margin_top),
372 }
373 }
374
375 pub fn name(self, name: impl Into<glib::GString>) -> Self {
376 Self {
377 builder: self.builder.property("name", name.into()),
378 }
379 }
380
381 pub fn opacity(self, opacity: f64) -> Self {
382 Self {
383 builder: self.builder.property("opacity", opacity),
384 }
385 }
386
387 pub fn overflow(self, overflow: Overflow) -> Self {
388 Self {
389 builder: self.builder.property("overflow", overflow),
390 }
391 }
392
393 pub fn receives_default(self, receives_default: bool) -> Self {
394 Self {
395 builder: self.builder.property("receives-default", receives_default),
396 }
397 }
398
399 pub fn sensitive(self, sensitive: bool) -> Self {
400 Self {
401 builder: self.builder.property("sensitive", sensitive),
402 }
403 }
404
405 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
406 Self {
407 builder: self
408 .builder
409 .property("tooltip-markup", tooltip_markup.into()),
410 }
411 }
412
413 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
414 Self {
415 builder: self.builder.property("tooltip-text", tooltip_text.into()),
416 }
417 }
418
419 pub fn valign(self, valign: Align) -> Self {
420 Self {
421 builder: self.builder.property("valign", valign),
422 }
423 }
424
425 pub fn vexpand(self, vexpand: bool) -> Self {
426 Self {
427 builder: self.builder.property("vexpand", vexpand),
428 }
429 }
430
431 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
432 Self {
433 builder: self.builder.property("vexpand-set", vexpand_set),
434 }
435 }
436
437 pub fn visible(self, visible: bool) -> Self {
438 Self {
439 builder: self.builder.property("visible", visible),
440 }
441 }
442
443 pub fn width_request(self, width_request: i32) -> Self {
444 Self {
445 builder: self.builder.property("width-request", width_request),
446 }
447 }
448
449 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
450 Self {
451 builder: self.builder.property("accessible-role", accessible_role),
452 }
453 }
454
455 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
456 pub fn rgba(self, rgba: &gdk::RGBA) -> Self {
457 Self {
458 builder: self.builder.property("rgba", rgba),
459 }
460 }
461
462 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
463 pub fn use_alpha(self, use_alpha: bool) -> Self {
464 Self {
465 builder: self.builder.property("use-alpha", use_alpha),
466 }
467 }
468
469 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
472 pub fn build(self) -> ColorButton {
473 assert_initialized_main_thread!();
474 self.builder.build()
475 }
476}