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 ///
146 /// **⚠️ The following code is in C ⚠️**
147 ///
148 /// ```C
149 /// static void
150 /// text_editing_started (GtkCellRenderer *cell,
151 /// GtkCellEditable *editable,
152 /// const char *path,
153 /// gpointer data)
154 /// {
155 /// if (GTK_IS_ENTRY (editable))
156 /// {
157 /// GtkEntry *entry = GTK_ENTRY (editable);
158 ///
159 /// // ... create a GtkEntryCompletion
160 ///
161 /// gtk_entry_set_completion (entry, completion);
162 /// }
163 /// }
164 /// ```
165 ///
166 ///
167 /// </details>
168 ///
169 /// # Implements
170 ///
171 /// [`CellRendererExt`][trait@crate::prelude::CellRendererExt], [`trait@glib::ObjectExt`], [`CellRendererExtManual`][trait@crate::prelude::CellRendererExtManual]
172 #[doc(alias = "GtkCellRendererToggle")]
173 pub struct CellRendererToggle(Object<ffi::GtkCellRendererToggle>) @extends CellRenderer;
174
175 match fn {
176 type_ => || ffi::gtk_cell_renderer_toggle_get_type(),
177 }
178}
179
180impl CellRendererToggle {
181 /// Creates a new [`CellRendererToggle`][crate::CellRendererToggle]. Adjust rendering
182 /// parameters using object properties. Object properties can be set
183 /// globally (with g_object_set()). Also, with [`TreeViewColumn`][crate::TreeViewColumn], you
184 /// can bind a property to a value in a [`TreeModel`][crate::TreeModel]. For example, you
185 /// can bind the “active” property on the cell renderer to a boolean value
186 /// in the model, thus causing the check button to reflect the state of
187 /// the model.
188 ///
189 /// # Deprecated since 4.10
190 ///
191 ///
192 /// # Returns
193 ///
194 /// the new cell renderer
195 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
196 #[allow(deprecated)]
197 #[doc(alias = "gtk_cell_renderer_toggle_new")]
198 pub fn new() -> CellRendererToggle {
199 assert_initialized_main_thread!();
200 unsafe { CellRenderer::from_glib_none(ffi::gtk_cell_renderer_toggle_new()).unsafe_cast() }
201 }
202
203 // rustdoc-stripper-ignore-next
204 /// Creates a new builder-pattern struct instance to construct [`CellRendererToggle`] objects.
205 ///
206 /// This method returns an instance of [`CellRendererToggleBuilder`](crate::builders::CellRendererToggleBuilder) which can be used to create [`CellRendererToggle`] objects.
207 pub fn builder() -> CellRendererToggleBuilder {
208 CellRendererToggleBuilder::new()
209 }
210
211 /// Returns whether the cell renderer is activatable. See
212 /// gtk_cell_renderer_toggle_set_activatable().
213 ///
214 /// # Deprecated since 4.10
215 ///
216 ///
217 /// # Returns
218 ///
219 /// [`true`] if the cell renderer is activatable.
220 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
221 #[allow(deprecated)]
222 #[doc(alias = "gtk_cell_renderer_toggle_get_activatable")]
223 #[doc(alias = "get_activatable")]
224 #[doc(alias = "activatable")]
225 pub fn is_activatable(&self) -> bool {
226 unsafe {
227 from_glib(ffi::gtk_cell_renderer_toggle_get_activatable(
228 self.to_glib_none().0,
229 ))
230 }
231 }
232
233 /// Returns whether the cell renderer is active. See
234 /// gtk_cell_renderer_toggle_set_active().
235 ///
236 /// # Deprecated since 4.10
237 ///
238 ///
239 /// # Returns
240 ///
241 /// [`true`] if the cell renderer is active.
242 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
243 #[allow(deprecated)]
244 #[doc(alias = "gtk_cell_renderer_toggle_get_active")]
245 #[doc(alias = "get_active")]
246 #[doc(alias = "active")]
247 pub fn is_active(&self) -> bool {
248 unsafe {
249 from_glib(ffi::gtk_cell_renderer_toggle_get_active(
250 self.to_glib_none().0,
251 ))
252 }
253 }
254
255 /// Returns whether we’re rendering radio toggles rather than checkboxes.
256 ///
257 /// # Deprecated since 4.10
258 ///
259 ///
260 /// # Returns
261 ///
262 /// [`true`] if we’re rendering radio toggles rather than checkboxes
263 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
264 #[allow(deprecated)]
265 #[doc(alias = "gtk_cell_renderer_toggle_get_radio")]
266 #[doc(alias = "get_radio")]
267 #[doc(alias = "radio")]
268 pub fn is_radio(&self) -> bool {
269 unsafe {
270 from_glib(ffi::gtk_cell_renderer_toggle_get_radio(
271 self.to_glib_none().0,
272 ))
273 }
274 }
275
276 /// Makes the cell renderer activatable.
277 ///
278 /// # Deprecated since 4.10
279 ///
280 /// ## `setting`
281 /// the value to set.
282 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
283 #[allow(deprecated)]
284 #[doc(alias = "gtk_cell_renderer_toggle_set_activatable")]
285 #[doc(alias = "activatable")]
286 pub fn set_activatable(&self, setting: bool) {
287 unsafe {
288 ffi::gtk_cell_renderer_toggle_set_activatable(
289 self.to_glib_none().0,
290 setting.into_glib(),
291 );
292 }
293 }
294
295 /// Activates or deactivates a cell renderer.
296 ///
297 /// # Deprecated since 4.10
298 ///
299 /// ## `setting`
300 /// the value to set.
301 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
302 #[allow(deprecated)]
303 #[doc(alias = "gtk_cell_renderer_toggle_set_active")]
304 #[doc(alias = "active")]
305 pub fn set_active(&self, setting: bool) {
306 unsafe {
307 ffi::gtk_cell_renderer_toggle_set_active(self.to_glib_none().0, setting.into_glib());
308 }
309 }
310
311 /// If @radio is [`true`], the cell renderer renders a radio toggle
312 /// (i.e. a toggle in a group of mutually-exclusive toggles).
313 /// If [`false`], it renders a check toggle (a standalone boolean option).
314 /// This can be set globally for the cell renderer, or changed just
315 /// before rendering each cell in the model (for [`TreeView`][crate::TreeView], you set
316 /// up a per-row setting using [`TreeViewColumn`][crate::TreeViewColumn] to associate model
317 /// columns with cell renderer properties).
318 ///
319 /// # Deprecated since 4.10
320 ///
321 /// ## `radio`
322 /// [`true`] to make the toggle look like a radio button
323 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
324 #[allow(deprecated)]
325 #[doc(alias = "gtk_cell_renderer_toggle_set_radio")]
326 #[doc(alias = "radio")]
327 pub fn set_radio(&self, radio: bool) {
328 unsafe {
329 ffi::gtk_cell_renderer_toggle_set_radio(self.to_glib_none().0, radio.into_glib());
330 }
331 }
332
333 pub fn is_inconsistent(&self) -> bool {
334 ObjectExt::property(self, "inconsistent")
335 }
336
337 pub fn set_inconsistent(&self, inconsistent: bool) {
338 ObjectExt::set_property(self, "inconsistent", inconsistent)
339 }
340
341 /// The ::toggled signal is emitted when the cell is toggled.
342 ///
343 /// It is the responsibility of the application to update the model
344 /// with the correct value to store at @path. Often this is simply the
345 /// opposite of the value currently stored at @path.
346 /// ## `path`
347 /// string representation of [`TreePath`][crate::TreePath] describing the
348 /// event location
349 #[doc(alias = "toggled")]
350 pub fn connect_toggled<F: Fn(&Self, TreePath) + 'static>(&self, f: F) -> SignalHandlerId {
351 unsafe extern "C" fn toggled_trampoline<F: Fn(&CellRendererToggle, TreePath) + 'static>(
352 this: *mut ffi::GtkCellRendererToggle,
353 path: *mut std::ffi::c_char,
354 f: glib::ffi::gpointer,
355 ) {
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 unsafe {
361 let f: Box_<F> = Box_::new(f);
362 connect_raw(
363 self.as_ptr() as *mut _,
364 b"toggled\0".as_ptr() as *const _,
365 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
366 toggled_trampoline::<F> as *const (),
367 )),
368 Box_::into_raw(f),
369 )
370 }
371 }
372
373 #[doc(alias = "activatable")]
374 pub fn connect_activatable_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
375 unsafe extern "C" fn notify_activatable_trampoline<F: Fn(&CellRendererToggle) + 'static>(
376 this: *mut ffi::GtkCellRendererToggle,
377 _param_spec: glib::ffi::gpointer,
378 f: glib::ffi::gpointer,
379 ) {
380 let f: &F = &*(f as *const F);
381 f(&from_glib_borrow(this))
382 }
383 unsafe {
384 let f: Box_<F> = Box_::new(f);
385 connect_raw(
386 self.as_ptr() as *mut _,
387 b"notify::activatable\0".as_ptr() as *const _,
388 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
389 notify_activatable_trampoline::<F> as *const (),
390 )),
391 Box_::into_raw(f),
392 )
393 }
394 }
395
396 #[doc(alias = "active")]
397 pub fn connect_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
398 unsafe extern "C" fn notify_active_trampoline<F: Fn(&CellRendererToggle) + 'static>(
399 this: *mut ffi::GtkCellRendererToggle,
400 _param_spec: glib::ffi::gpointer,
401 f: glib::ffi::gpointer,
402 ) {
403 let f: &F = &*(f as *const F);
404 f(&from_glib_borrow(this))
405 }
406 unsafe {
407 let f: Box_<F> = Box_::new(f);
408 connect_raw(
409 self.as_ptr() as *mut _,
410 b"notify::active\0".as_ptr() as *const _,
411 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
412 notify_active_trampoline::<F> as *const (),
413 )),
414 Box_::into_raw(f),
415 )
416 }
417 }
418
419 #[doc(alias = "inconsistent")]
420 pub fn connect_inconsistent_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
421 unsafe extern "C" fn notify_inconsistent_trampoline<
422 F: Fn(&CellRendererToggle) + 'static,
423 >(
424 this: *mut ffi::GtkCellRendererToggle,
425 _param_spec: glib::ffi::gpointer,
426 f: glib::ffi::gpointer,
427 ) {
428 let f: &F = &*(f as *const F);
429 f(&from_glib_borrow(this))
430 }
431 unsafe {
432 let f: Box_<F> = Box_::new(f);
433 connect_raw(
434 self.as_ptr() as *mut _,
435 b"notify::inconsistent\0".as_ptr() as *const _,
436 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
437 notify_inconsistent_trampoline::<F> as *const (),
438 )),
439 Box_::into_raw(f),
440 )
441 }
442 }
443
444 #[doc(alias = "radio")]
445 pub fn connect_radio_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
446 unsafe extern "C" fn notify_radio_trampoline<F: Fn(&CellRendererToggle) + 'static>(
447 this: *mut ffi::GtkCellRendererToggle,
448 _param_spec: glib::ffi::gpointer,
449 f: glib::ffi::gpointer,
450 ) {
451 let f: &F = &*(f as *const F);
452 f(&from_glib_borrow(this))
453 }
454 unsafe {
455 let f: Box_<F> = Box_::new(f);
456 connect_raw(
457 self.as_ptr() as *mut _,
458 b"notify::radio\0".as_ptr() as *const _,
459 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
460 notify_radio_trampoline::<F> as *const (),
461 )),
462 Box_::into_raw(f),
463 )
464 }
465 }
466}
467
468impl Default for CellRendererToggle {
469 fn default() -> Self {
470 Self::new()
471 }
472}
473
474// rustdoc-stripper-ignore-next
475/// A [builder-pattern] type to construct [`CellRendererToggle`] objects.
476///
477/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
478#[must_use = "The builder must be built to be used"]
479pub struct CellRendererToggleBuilder {
480 builder: glib::object::ObjectBuilder<'static, CellRendererToggle>,
481}
482
483impl CellRendererToggleBuilder {
484 fn new() -> Self {
485 Self {
486 builder: glib::object::Object::builder(),
487 }
488 }
489
490 pub fn activatable(self, activatable: bool) -> Self {
491 Self {
492 builder: self.builder.property("activatable", activatable),
493 }
494 }
495
496 pub fn active(self, active: bool) -> Self {
497 Self {
498 builder: self.builder.property("active", active),
499 }
500 }
501
502 pub fn inconsistent(self, inconsistent: bool) -> Self {
503 Self {
504 builder: self.builder.property("inconsistent", inconsistent),
505 }
506 }
507
508 pub fn radio(self, radio: bool) -> Self {
509 Self {
510 builder: self.builder.property("radio", radio),
511 }
512 }
513
514 pub fn cell_background(self, cell_background: impl Into<glib::GString>) -> Self {
515 Self {
516 builder: self
517 .builder
518 .property("cell-background", cell_background.into()),
519 }
520 }
521
522 /// Cell background as a [`gdk::RGBA`][crate::gdk::RGBA]
523 pub fn cell_background_rgba(self, cell_background_rgba: &gdk::RGBA) -> Self {
524 Self {
525 builder: self
526 .builder
527 .property("cell-background-rgba", cell_background_rgba),
528 }
529 }
530
531 pub fn cell_background_set(self, cell_background_set: bool) -> Self {
532 Self {
533 builder: self
534 .builder
535 .property("cell-background-set", cell_background_set),
536 }
537 }
538
539 pub fn height(self, height: i32) -> Self {
540 Self {
541 builder: self.builder.property("height", height),
542 }
543 }
544
545 pub fn is_expanded(self, is_expanded: bool) -> Self {
546 Self {
547 builder: self.builder.property("is-expanded", is_expanded),
548 }
549 }
550
551 pub fn is_expander(self, is_expander: bool) -> Self {
552 Self {
553 builder: self.builder.property("is-expander", is_expander),
554 }
555 }
556
557 pub fn mode(self, mode: CellRendererMode) -> Self {
558 Self {
559 builder: self.builder.property("mode", mode),
560 }
561 }
562
563 pub fn sensitive(self, sensitive: bool) -> Self {
564 Self {
565 builder: self.builder.property("sensitive", sensitive),
566 }
567 }
568
569 pub fn visible(self, visible: bool) -> Self {
570 Self {
571 builder: self.builder.property("visible", visible),
572 }
573 }
574
575 pub fn width(self, width: i32) -> Self {
576 Self {
577 builder: self.builder.property("width", width),
578 }
579 }
580
581 pub fn xalign(self, xalign: f32) -> Self {
582 Self {
583 builder: self.builder.property("xalign", xalign),
584 }
585 }
586
587 pub fn xpad(self, xpad: u32) -> Self {
588 Self {
589 builder: self.builder.property("xpad", xpad),
590 }
591 }
592
593 pub fn yalign(self, yalign: f32) -> Self {
594 Self {
595 builder: self.builder.property("yalign", yalign),
596 }
597 }
598
599 pub fn ypad(self, ypad: u32) -> Self {
600 Self {
601 builder: self.builder.property("ypad", ypad),
602 }
603 }
604
605 // rustdoc-stripper-ignore-next
606 /// Build the [`CellRendererToggle`].
607 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
608 pub fn build(self) -> CellRendererToggle {
609 assert_initialized_main_thread!();
610 self.builder.build()
611 }
612}