gtk4/auto/cell_renderer_toggle.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4#![allow(deprecated)]
5
6use crate::{CellRenderer, CellRendererMode, TreePath, ffi};
7use glib::{
8 object::ObjectType as _,
9 prelude::*,
10 signal::{SignalHandlerId, connect_raw},
11 translate::*,
12};
13use std::boxed::Box as Box_;
14
15glib::wrapper! {
16 /// List views use widgets to display their contents.
17 /// You should use [`ToggleButton`][crate::ToggleButton] instead
18 /// Renders a toggle button in a cell
19 ///
20 /// [`CellRendererToggle`][crate::CellRendererToggle] renders a toggle button in a cell. The
21 /// button is drawn as a radio or a checkbutton, depending on the
22 /// `GtkCellRendererToggle:radio` property.
23 /// When activated, it emits the `GtkCellRendererToggle::toggled` signal.
24 ///
25 /// ## Properties
26 ///
27 ///
28 /// #### `activatable`
29 /// Readable | Writeable
30 ///
31 ///
32 /// #### `active`
33 /// Readable | Writeable
34 ///
35 ///
36 /// #### `inconsistent`
37 /// Readable | Writeable
38 ///
39 ///
40 /// #### `radio`
41 /// Readable | Writeable
42 /// <details><summary><h4>CellRenderer</h4></summary>
43 ///
44 ///
45 /// #### `cell-background`
46 /// Writeable
47 ///
48 ///
49 /// #### `cell-background-rgba`
50 /// Cell background as a [`gdk::RGBA`][crate::gdk::RGBA]
51 ///
52 /// Readable | Writeable
53 ///
54 ///
55 /// #### `cell-background-set`
56 /// Readable | Writeable
57 ///
58 ///
59 /// #### `editing`
60 /// Readable
61 ///
62 ///
63 /// #### `height`
64 /// Readable | Writeable
65 ///
66 ///
67 /// #### `is-expanded`
68 /// Readable | Writeable
69 ///
70 ///
71 /// #### `is-expander`
72 /// Readable | Writeable
73 ///
74 ///
75 /// #### `mode`
76 /// Readable | Writeable
77 ///
78 ///
79 /// #### `sensitive`
80 /// Readable | Writeable
81 ///
82 ///
83 /// #### `visible`
84 /// Readable | Writeable
85 ///
86 ///
87 /// #### `width`
88 /// Readable | Writeable
89 ///
90 ///
91 /// #### `xalign`
92 /// Readable | Writeable
93 ///
94 ///
95 /// #### `xpad`
96 /// Readable | Writeable
97 ///
98 ///
99 /// #### `yalign`
100 /// Readable | Writeable
101 ///
102 ///
103 /// #### `ypad`
104 /// Readable | Writeable
105 /// </details>
106 ///
107 /// ## Signals
108 ///
109 ///
110 /// #### `toggled`
111 /// The ::toggled signal is emitted when the cell is toggled.
112 ///
113 /// It is the responsibility of the application to update the model
114 /// with the correct value to store at @path. Often this is simply the
115 /// opposite of the value currently stored at @path.
116 ///
117 ///
118 /// <details><summary><h4>CellRenderer</h4></summary>
119 ///
120 ///
121 /// #### `editing-canceled`
122 /// This signal gets emitted when the user cancels the process of editing a
123 /// cell. For example, an editable cell renderer could be written to cancel
124 /// editing when the user presses Escape.
125 ///
126 /// See also: gtk_cell_renderer_stop_editing().
127 ///
128 ///
129 ///
130 ///
131 /// #### `editing-started`
132 /// This signal gets emitted when a cell starts to be edited.
133 /// The intended use of this signal is to do special setup
134 /// on @editable, e.g. adding a [`EntryCompletion`][crate::EntryCompletion] or setting
135 /// up additional columns in a [`ComboBox`][crate::ComboBox].
136 ///
137 /// See gtk_cell_editable_start_editing() for information on the lifecycle of
138 /// the @editable and a way to do setup that doesn’t depend on the @renderer.
139 ///
140 /// Note that GTK doesn't guarantee that cell renderers will
141 /// continue to use the same kind of widget for editing in future
142 /// releases, therefore you should check the type of @editable
143 /// before doing any specific setup, as in the following example:
144 ///
145 /// **⚠️ The following code is in c ⚠️**
146 ///
147 /// ```c
148 /// static void
149 /// text_editing_started (GtkCellRenderer *cell,
150 /// GtkCellEditable *editable,
151 /// const char *path,
152 /// gpointer data)
153 /// {
154 /// if (GTK_IS_ENTRY (editable))
155 /// {
156 /// GtkEntry *entry = GTK_ENTRY (editable);
157 ///
158 /// // ... create a GtkEntryCompletion
159 ///
160 /// gtk_entry_set_completion (entry, completion);
161 /// }
162 /// }
163 /// ```
164 ///
165 ///
166 /// </details>
167 ///
168 /// # Implements
169 ///
170 /// [`CellRendererExt`][trait@crate::prelude::CellRendererExt], [`trait@glib::ObjectExt`], [`CellRendererExtManual`][trait@crate::prelude::CellRendererExtManual]
171 #[doc(alias = "GtkCellRendererToggle")]
172 pub struct CellRendererToggle(Object<ffi::GtkCellRendererToggle>) @extends CellRenderer;
173
174 match fn {
175 type_ => || ffi::gtk_cell_renderer_toggle_get_type(),
176 }
177}
178
179impl CellRendererToggle {
180 /// Creates a new [`CellRendererToggle`][crate::CellRendererToggle]. Adjust rendering
181 /// parameters using object properties. Object properties can be set
182 /// globally (with g_object_set()). Also, with [`TreeViewColumn`][crate::TreeViewColumn], you
183 /// can bind a property to a value in a [`TreeModel`][crate::TreeModel]. For example, you
184 /// can bind the “active” property on the cell renderer to a boolean value
185 /// in the model, thus causing the check button to reflect the state of
186 /// the model.
187 ///
188 /// # Deprecated since 4.10
189 ///
190 ///
191 /// # Returns
192 ///
193 /// the new cell renderer
194 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
195 #[allow(deprecated)]
196 #[doc(alias = "gtk_cell_renderer_toggle_new")]
197 pub fn new() -> CellRendererToggle {
198 assert_initialized_main_thread!();
199 unsafe { CellRenderer::from_glib_none(ffi::gtk_cell_renderer_toggle_new()).unsafe_cast() }
200 }
201
202 // rustdoc-stripper-ignore-next
203 /// Creates a new builder-pattern struct instance to construct [`CellRendererToggle`] objects.
204 ///
205 /// This method returns an instance of [`CellRendererToggleBuilder`](crate::builders::CellRendererToggleBuilder) which can be used to create [`CellRendererToggle`] objects.
206 pub fn builder() -> CellRendererToggleBuilder {
207 CellRendererToggleBuilder::new()
208 }
209
210 /// Returns whether the cell renderer is activatable. See
211 /// gtk_cell_renderer_toggle_set_activatable().
212 ///
213 /// # Deprecated since 4.10
214 ///
215 ///
216 /// # Returns
217 ///
218 /// [`true`] if the cell renderer is activatable.
219 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
220 #[allow(deprecated)]
221 #[doc(alias = "gtk_cell_renderer_toggle_get_activatable")]
222 #[doc(alias = "get_activatable")]
223 #[doc(alias = "activatable")]
224 pub fn is_activatable(&self) -> bool {
225 unsafe {
226 from_glib(ffi::gtk_cell_renderer_toggle_get_activatable(
227 self.to_glib_none().0,
228 ))
229 }
230 }
231
232 /// Returns whether the cell renderer is active. See
233 /// gtk_cell_renderer_toggle_set_active().
234 ///
235 /// # Deprecated since 4.10
236 ///
237 ///
238 /// # Returns
239 ///
240 /// [`true`] if the cell renderer is active.
241 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
242 #[allow(deprecated)]
243 #[doc(alias = "gtk_cell_renderer_toggle_get_active")]
244 #[doc(alias = "get_active")]
245 #[doc(alias = "active")]
246 pub fn is_active(&self) -> bool {
247 unsafe {
248 from_glib(ffi::gtk_cell_renderer_toggle_get_active(
249 self.to_glib_none().0,
250 ))
251 }
252 }
253
254 /// Returns whether we’re rendering radio toggles rather than checkboxes.
255 ///
256 /// # Deprecated since 4.10
257 ///
258 ///
259 /// # Returns
260 ///
261 /// [`true`] if we’re rendering radio toggles rather than checkboxes
262 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
263 #[allow(deprecated)]
264 #[doc(alias = "gtk_cell_renderer_toggle_get_radio")]
265 #[doc(alias = "get_radio")]
266 #[doc(alias = "radio")]
267 pub fn is_radio(&self) -> bool {
268 unsafe {
269 from_glib(ffi::gtk_cell_renderer_toggle_get_radio(
270 self.to_glib_none().0,
271 ))
272 }
273 }
274
275 /// Makes the cell renderer activatable.
276 ///
277 /// # Deprecated since 4.10
278 ///
279 /// ## `setting`
280 /// the value to set.
281 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
282 #[allow(deprecated)]
283 #[doc(alias = "gtk_cell_renderer_toggle_set_activatable")]
284 #[doc(alias = "activatable")]
285 pub fn set_activatable(&self, setting: bool) {
286 unsafe {
287 ffi::gtk_cell_renderer_toggle_set_activatable(
288 self.to_glib_none().0,
289 setting.into_glib(),
290 );
291 }
292 }
293
294 /// Activates or deactivates a cell renderer.
295 ///
296 /// # Deprecated since 4.10
297 ///
298 /// ## `setting`
299 /// the value to set.
300 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
301 #[allow(deprecated)]
302 #[doc(alias = "gtk_cell_renderer_toggle_set_active")]
303 #[doc(alias = "active")]
304 pub fn set_active(&self, setting: bool) {
305 unsafe {
306 ffi::gtk_cell_renderer_toggle_set_active(self.to_glib_none().0, setting.into_glib());
307 }
308 }
309
310 /// If @radio is [`true`], the cell renderer renders a radio toggle
311 /// (i.e. a toggle in a group of mutually-exclusive toggles).
312 /// If [`false`], it renders a check toggle (a standalone boolean option).
313 /// This can be set globally for the cell renderer, or changed just
314 /// before rendering each cell in the model (for [`TreeView`][crate::TreeView], you set
315 /// up a per-row setting using [`TreeViewColumn`][crate::TreeViewColumn] to associate model
316 /// columns with cell renderer properties).
317 ///
318 /// # Deprecated since 4.10
319 ///
320 /// ## `radio`
321 /// [`true`] to make the toggle look like a radio button
322 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
323 #[allow(deprecated)]
324 #[doc(alias = "gtk_cell_renderer_toggle_set_radio")]
325 #[doc(alias = "radio")]
326 pub fn set_radio(&self, radio: bool) {
327 unsafe {
328 ffi::gtk_cell_renderer_toggle_set_radio(self.to_glib_none().0, radio.into_glib());
329 }
330 }
331
332 pub fn is_inconsistent(&self) -> bool {
333 ObjectExt::property(self, "inconsistent")
334 }
335
336 pub fn set_inconsistent(&self, inconsistent: bool) {
337 ObjectExt::set_property(self, "inconsistent", inconsistent)
338 }
339
340 /// The ::toggled signal is emitted when the cell is toggled.
341 ///
342 /// It is the responsibility of the application to update the model
343 /// with the correct value to store at @path. Often this is simply the
344 /// opposite of the value currently stored at @path.
345 /// ## `path`
346 /// string representation of [`TreePath`][crate::TreePath] describing the
347 /// event location
348 #[doc(alias = "toggled")]
349 pub fn connect_toggled<F: Fn(&Self, TreePath) + 'static>(&self, f: F) -> SignalHandlerId {
350 unsafe extern "C" fn toggled_trampoline<F: Fn(&CellRendererToggle, TreePath) + 'static>(
351 this: *mut ffi::GtkCellRendererToggle,
352 path: *mut std::ffi::c_char,
353 f: glib::ffi::gpointer,
354 ) {
355 unsafe {
356 let f: &F = &*(f as *const F);
357 let path = from_glib_full(crate::ffi::gtk_tree_path_new_from_string(path));
358 f(&from_glib_borrow(this), path)
359 }
360 }
361 unsafe {
362 let f: Box_<F> = Box_::new(f);
363 connect_raw(
364 self.as_ptr() as *mut _,
365 c"toggled".as_ptr() as *const _,
366 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
367 toggled_trampoline::<F> as *const (),
368 )),
369 Box_::into_raw(f),
370 )
371 }
372 }
373
374 #[doc(alias = "activatable")]
375 pub fn connect_activatable_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
376 unsafe extern "C" fn notify_activatable_trampoline<F: Fn(&CellRendererToggle) + 'static>(
377 this: *mut ffi::GtkCellRendererToggle,
378 _param_spec: glib::ffi::gpointer,
379 f: glib::ffi::gpointer,
380 ) {
381 unsafe {
382 let f: &F = &*(f as *const F);
383 f(&from_glib_borrow(this))
384 }
385 }
386 unsafe {
387 let f: Box_<F> = Box_::new(f);
388 connect_raw(
389 self.as_ptr() as *mut _,
390 c"notify::activatable".as_ptr() as *const _,
391 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
392 notify_activatable_trampoline::<F> as *const (),
393 )),
394 Box_::into_raw(f),
395 )
396 }
397 }
398
399 #[doc(alias = "active")]
400 pub fn connect_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
401 unsafe extern "C" fn notify_active_trampoline<F: Fn(&CellRendererToggle) + 'static>(
402 this: *mut ffi::GtkCellRendererToggle,
403 _param_spec: glib::ffi::gpointer,
404 f: glib::ffi::gpointer,
405 ) {
406 unsafe {
407 let f: &F = &*(f as *const F);
408 f(&from_glib_borrow(this))
409 }
410 }
411 unsafe {
412 let f: Box_<F> = Box_::new(f);
413 connect_raw(
414 self.as_ptr() as *mut _,
415 c"notify::active".as_ptr() as *const _,
416 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
417 notify_active_trampoline::<F> as *const (),
418 )),
419 Box_::into_raw(f),
420 )
421 }
422 }
423
424 #[doc(alias = "inconsistent")]
425 pub fn connect_inconsistent_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
426 unsafe extern "C" fn notify_inconsistent_trampoline<
427 F: Fn(&CellRendererToggle) + 'static,
428 >(
429 this: *mut ffi::GtkCellRendererToggle,
430 _param_spec: glib::ffi::gpointer,
431 f: glib::ffi::gpointer,
432 ) {
433 unsafe {
434 let f: &F = &*(f as *const F);
435 f(&from_glib_borrow(this))
436 }
437 }
438 unsafe {
439 let f: Box_<F> = Box_::new(f);
440 connect_raw(
441 self.as_ptr() as *mut _,
442 c"notify::inconsistent".as_ptr() as *const _,
443 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
444 notify_inconsistent_trampoline::<F> as *const (),
445 )),
446 Box_::into_raw(f),
447 )
448 }
449 }
450
451 #[doc(alias = "radio")]
452 pub fn connect_radio_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
453 unsafe extern "C" fn notify_radio_trampoline<F: Fn(&CellRendererToggle) + 'static>(
454 this: *mut ffi::GtkCellRendererToggle,
455 _param_spec: glib::ffi::gpointer,
456 f: glib::ffi::gpointer,
457 ) {
458 unsafe {
459 let f: &F = &*(f as *const F);
460 f(&from_glib_borrow(this))
461 }
462 }
463 unsafe {
464 let f: Box_<F> = Box_::new(f);
465 connect_raw(
466 self.as_ptr() as *mut _,
467 c"notify::radio".as_ptr() as *const _,
468 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
469 notify_radio_trampoline::<F> as *const (),
470 )),
471 Box_::into_raw(f),
472 )
473 }
474 }
475}
476
477impl Default for CellRendererToggle {
478 fn default() -> Self {
479 Self::new()
480 }
481}
482
483// rustdoc-stripper-ignore-next
484/// A [builder-pattern] type to construct [`CellRendererToggle`] objects.
485///
486/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
487#[must_use = "The builder must be built to be used"]
488pub struct CellRendererToggleBuilder {
489 builder: glib::object::ObjectBuilder<'static, CellRendererToggle>,
490}
491
492impl CellRendererToggleBuilder {
493 fn new() -> Self {
494 Self {
495 builder: glib::object::Object::builder(),
496 }
497 }
498
499 pub fn activatable(self, activatable: bool) -> Self {
500 Self {
501 builder: self.builder.property("activatable", activatable),
502 }
503 }
504
505 pub fn active(self, active: bool) -> Self {
506 Self {
507 builder: self.builder.property("active", active),
508 }
509 }
510
511 pub fn inconsistent(self, inconsistent: bool) -> Self {
512 Self {
513 builder: self.builder.property("inconsistent", inconsistent),
514 }
515 }
516
517 pub fn radio(self, radio: bool) -> Self {
518 Self {
519 builder: self.builder.property("radio", radio),
520 }
521 }
522
523 pub fn cell_background(self, cell_background: impl Into<glib::GString>) -> Self {
524 Self {
525 builder: self
526 .builder
527 .property("cell-background", cell_background.into()),
528 }
529 }
530
531 /// Cell background as a [`gdk::RGBA`][crate::gdk::RGBA]
532 pub fn cell_background_rgba(self, cell_background_rgba: &gdk::RGBA) -> Self {
533 Self {
534 builder: self
535 .builder
536 .property("cell-background-rgba", cell_background_rgba),
537 }
538 }
539
540 pub fn cell_background_set(self, cell_background_set: bool) -> Self {
541 Self {
542 builder: self
543 .builder
544 .property("cell-background-set", cell_background_set),
545 }
546 }
547
548 pub fn height(self, height: i32) -> Self {
549 Self {
550 builder: self.builder.property("height", height),
551 }
552 }
553
554 pub fn is_expanded(self, is_expanded: bool) -> Self {
555 Self {
556 builder: self.builder.property("is-expanded", is_expanded),
557 }
558 }
559
560 pub fn is_expander(self, is_expander: bool) -> Self {
561 Self {
562 builder: self.builder.property("is-expander", is_expander),
563 }
564 }
565
566 pub fn mode(self, mode: CellRendererMode) -> Self {
567 Self {
568 builder: self.builder.property("mode", mode),
569 }
570 }
571
572 pub fn sensitive(self, sensitive: bool) -> Self {
573 Self {
574 builder: self.builder.property("sensitive", sensitive),
575 }
576 }
577
578 pub fn visible(self, visible: bool) -> Self {
579 Self {
580 builder: self.builder.property("visible", visible),
581 }
582 }
583
584 pub fn width(self, width: i32) -> Self {
585 Self {
586 builder: self.builder.property("width", width),
587 }
588 }
589
590 pub fn xalign(self, xalign: f32) -> Self {
591 Self {
592 builder: self.builder.property("xalign", xalign),
593 }
594 }
595
596 pub fn xpad(self, xpad: u32) -> Self {
597 Self {
598 builder: self.builder.property("xpad", xpad),
599 }
600 }
601
602 pub fn yalign(self, yalign: f32) -> Self {
603 Self {
604 builder: self.builder.property("yalign", yalign),
605 }
606 }
607
608 pub fn ypad(self, ypad: u32) -> Self {
609 Self {
610 builder: self.builder.property("ypad", ypad),
611 }
612 }
613
614 // rustdoc-stripper-ignore-next
615 /// Build the [`CellRendererToggle`].
616 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
617 pub fn build(self) -> CellRendererToggle {
618 assert_initialized_main_thread!();
619 self.builder.build()
620 }
621}