gtk4/auto/
string_object.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
5use crate::ffi;
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    /// [`StringObject`][crate::StringObject] is the type of items in a [`StringList`][crate::StringList].
15    ///
16    /// A [`StringObject`][crate::StringObject] is a wrapper around a `const char*`; it has
17    /// a [`string`][struct@crate::StringObject#string] property that can be used
18    /// for property bindings and expressions.
19    ///
20    /// ## Properties
21    ///
22    ///
23    /// #### `string`
24    ///  The string.
25    ///
26    /// Readable
27    ///
28    /// # Implements
29    ///
30    /// [`trait@glib::ObjectExt`]
31    #[doc(alias = "GtkStringObject")]
32    pub struct StringObject(Object<ffi::GtkStringObject, ffi::GtkStringObjectClass>);
33
34    match fn {
35        type_ => || ffi::gtk_string_object_get_type(),
36    }
37}
38
39impl StringObject {
40    /// Wraps a string in an object for use with `GListModel`.
41    /// ## `string`
42    /// The string to wrap
43    ///
44    /// # Returns
45    ///
46    /// a new [`StringObject`][crate::StringObject]
47    #[doc(alias = "gtk_string_object_new")]
48    pub fn new(string: &str) -> StringObject {
49        assert_initialized_main_thread!();
50        unsafe { from_glib_full(ffi::gtk_string_object_new(string.to_glib_none().0)) }
51    }
52
53    /// Returns the string contained in a [`StringObject`][crate::StringObject].
54    ///
55    /// # Returns
56    ///
57    /// the string of @self
58    #[doc(alias = "gtk_string_object_get_string")]
59    #[doc(alias = "get_string")]
60    pub fn string(&self) -> glib::GString {
61        unsafe { from_glib_none(ffi::gtk_string_object_get_string(self.to_glib_none().0)) }
62    }
63
64    #[doc(alias = "string")]
65    pub fn connect_string_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
66        unsafe extern "C" fn notify_string_trampoline<F: Fn(&StringObject) + 'static>(
67            this: *mut ffi::GtkStringObject,
68            _param_spec: glib::ffi::gpointer,
69            f: glib::ffi::gpointer,
70        ) {
71            let f: &F = &*(f as *const F);
72            f(&from_glib_borrow(this))
73        }
74        unsafe {
75            let f: Box_<F> = Box_::new(f);
76            connect_raw(
77                self.as_ptr() as *mut _,
78                b"notify::string\0".as_ptr() as *const _,
79                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
80                    notify_string_trampoline::<F> as *const (),
81                )),
82                Box_::into_raw(f),
83            )
84        }
85    }
86}