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::{ffi, CellRenderer, CellRendererMode, TreePath};
7use glib::{
8 object::ObjectType as _,
9 prelude::*,
10 signal::{connect_raw, SignalHandlerId},
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 let f: &F = &*(f as *const F);
356 let path = from_glib_full(crate::ffi::gtk_tree_path_new_from_string(path));
357 f(&from_glib_borrow(this), path)
358 }
359 unsafe {
360 let f: Box_<F> = Box_::new(f);
361 connect_raw(
362 self.as_ptr() as *mut _,
363 c"toggled".as_ptr() as *const _,
364 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
365 toggled_trampoline::<F> as *const (),
366 )),
367 Box_::into_raw(f),
368 )
369 }
370 }
371
372 #[doc(alias = "activatable")]
373 pub fn connect_activatable_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
374 unsafe extern "C" fn notify_activatable_trampoline<F: Fn(&CellRendererToggle) + 'static>(
375 this: *mut ffi::GtkCellRendererToggle,
376 _param_spec: glib::ffi::gpointer,
377 f: glib::ffi::gpointer,
378 ) {
379 let f: &F = &*(f as *const F);
380 f(&from_glib_borrow(this))
381 }
382 unsafe {
383 let f: Box_<F> = Box_::new(f);
384 connect_raw(
385 self.as_ptr() as *mut _,
386 c"notify::activatable".as_ptr() as *const _,
387 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
388 notify_activatable_trampoline::<F> as *const (),
389 )),
390 Box_::into_raw(f),
391 )
392 }
393 }
394
395 #[doc(alias = "active")]
396 pub fn connect_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
397 unsafe extern "C" fn notify_active_trampoline<F: Fn(&CellRendererToggle) + 'static>(
398 this: *mut ffi::GtkCellRendererToggle,
399 _param_spec: glib::ffi::gpointer,
400 f: glib::ffi::gpointer,
401 ) {
402 let f: &F = &*(f as *const F);
403 f(&from_glib_borrow(this))
404 }
405 unsafe {
406 let f: Box_<F> = Box_::new(f);
407 connect_raw(
408 self.as_ptr() as *mut _,
409 c"notify::active".as_ptr() as *const _,
410 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
411 notify_active_trampoline::<F> as *const (),
412 )),
413 Box_::into_raw(f),
414 )
415 }
416 }
417
418 #[doc(alias = "inconsistent")]
419 pub fn connect_inconsistent_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
420 unsafe extern "C" fn notify_inconsistent_trampoline<
421 F: Fn(&CellRendererToggle) + 'static,
422 >(
423 this: *mut ffi::GtkCellRendererToggle,
424 _param_spec: glib::ffi::gpointer,
425 f: glib::ffi::gpointer,
426 ) {
427 let f: &F = &*(f as *const F);
428 f(&from_glib_borrow(this))
429 }
430 unsafe {
431 let f: Box_<F> = Box_::new(f);
432 connect_raw(
433 self.as_ptr() as *mut _,
434 c"notify::inconsistent".as_ptr() as *const _,
435 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
436 notify_inconsistent_trampoline::<F> as *const (),
437 )),
438 Box_::into_raw(f),
439 )
440 }
441 }
442
443 #[doc(alias = "radio")]
444 pub fn connect_radio_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
445 unsafe extern "C" fn notify_radio_trampoline<F: Fn(&CellRendererToggle) + 'static>(
446 this: *mut ffi::GtkCellRendererToggle,
447 _param_spec: glib::ffi::gpointer,
448 f: glib::ffi::gpointer,
449 ) {
450 let f: &F = &*(f as *const F);
451 f(&from_glib_borrow(this))
452 }
453 unsafe {
454 let f: Box_<F> = Box_::new(f);
455 connect_raw(
456 self.as_ptr() as *mut _,
457 c"notify::radio".as_ptr() as *const _,
458 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
459 notify_radio_trampoline::<F> as *const (),
460 )),
461 Box_::into_raw(f),
462 )
463 }
464 }
465}
466
467impl Default for CellRendererToggle {
468 fn default() -> Self {
469 Self::new()
470 }
471}
472
473// rustdoc-stripper-ignore-next
474/// A [builder-pattern] type to construct [`CellRendererToggle`] objects.
475///
476/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
477#[must_use = "The builder must be built to be used"]
478pub struct CellRendererToggleBuilder {
479 builder: glib::object::ObjectBuilder<'static, CellRendererToggle>,
480}
481
482impl CellRendererToggleBuilder {
483 fn new() -> Self {
484 Self {
485 builder: glib::object::Object::builder(),
486 }
487 }
488
489 pub fn activatable(self, activatable: bool) -> Self {
490 Self {
491 builder: self.builder.property("activatable", activatable),
492 }
493 }
494
495 pub fn active(self, active: bool) -> Self {
496 Self {
497 builder: self.builder.property("active", active),
498 }
499 }
500
501 pub fn inconsistent(self, inconsistent: bool) -> Self {
502 Self {
503 builder: self.builder.property("inconsistent", inconsistent),
504 }
505 }
506
507 pub fn radio(self, radio: bool) -> Self {
508 Self {
509 builder: self.builder.property("radio", radio),
510 }
511 }
512
513 pub fn cell_background(self, cell_background: impl Into<glib::GString>) -> Self {
514 Self {
515 builder: self
516 .builder
517 .property("cell-background", cell_background.into()),
518 }
519 }
520
521 /// Cell background as a [`gdk::RGBA`][crate::gdk::RGBA]
522 pub fn cell_background_rgba(self, cell_background_rgba: &gdk::RGBA) -> Self {
523 Self {
524 builder: self
525 .builder
526 .property("cell-background-rgba", cell_background_rgba),
527 }
528 }
529
530 pub fn cell_background_set(self, cell_background_set: bool) -> Self {
531 Self {
532 builder: self
533 .builder
534 .property("cell-background-set", cell_background_set),
535 }
536 }
537
538 pub fn height(self, height: i32) -> Self {
539 Self {
540 builder: self.builder.property("height", height),
541 }
542 }
543
544 pub fn is_expanded(self, is_expanded: bool) -> Self {
545 Self {
546 builder: self.builder.property("is-expanded", is_expanded),
547 }
548 }
549
550 pub fn is_expander(self, is_expander: bool) -> Self {
551 Self {
552 builder: self.builder.property("is-expander", is_expander),
553 }
554 }
555
556 pub fn mode(self, mode: CellRendererMode) -> Self {
557 Self {
558 builder: self.builder.property("mode", mode),
559 }
560 }
561
562 pub fn sensitive(self, sensitive: bool) -> Self {
563 Self {
564 builder: self.builder.property("sensitive", sensitive),
565 }
566 }
567
568 pub fn visible(self, visible: bool) -> Self {
569 Self {
570 builder: self.builder.property("visible", visible),
571 }
572 }
573
574 pub fn width(self, width: i32) -> Self {
575 Self {
576 builder: self.builder.property("width", width),
577 }
578 }
579
580 pub fn xalign(self, xalign: f32) -> Self {
581 Self {
582 builder: self.builder.property("xalign", xalign),
583 }
584 }
585
586 pub fn xpad(self, xpad: u32) -> Self {
587 Self {
588 builder: self.builder.property("xpad", xpad),
589 }
590 }
591
592 pub fn yalign(self, yalign: f32) -> Self {
593 Self {
594 builder: self.builder.property("yalign", yalign),
595 }
596 }
597
598 pub fn ypad(self, ypad: u32) -> Self {
599 Self {
600 builder: self.builder.property("ypad", ypad),
601 }
602 }
603
604 // rustdoc-stripper-ignore-next
605 /// Build the [`CellRendererToggle`].
606 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
607 pub fn build(self) -> CellRendererToggle {
608 assert_initialized_main_thread!();
609 self.builder.build()
610 }
611}