gtk4/auto/
entry_buffer.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    #[doc(alias = "GtkEntryBuffer")]
15    pub struct EntryBuffer(Object<ffi::GtkEntryBuffer, ffi::GtkEntryBufferClass>);
16
17    match fn {
18        type_ => || ffi::gtk_entry_buffer_get_type(),
19    }
20}
21
22impl EntryBuffer {
23    pub const NONE: Option<&'static EntryBuffer> = None;
24
25    // rustdoc-stripper-ignore-next
26    /// Creates a new builder-pattern struct instance to construct [`EntryBuffer`] objects.
27    ///
28    /// This method returns an instance of [`EntryBufferBuilder`](crate::builders::EntryBufferBuilder) which can be used to create [`EntryBuffer`] objects.
29    pub fn builder() -> EntryBufferBuilder {
30        EntryBufferBuilder::new()
31    }
32}
33
34// rustdoc-stripper-ignore-next
35/// A [builder-pattern] type to construct [`EntryBuffer`] objects.
36///
37/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
38#[must_use = "The builder must be built to be used"]
39pub struct EntryBufferBuilder {
40    builder: glib::object::ObjectBuilder<'static, EntryBuffer>,
41}
42
43impl EntryBufferBuilder {
44    fn new() -> Self {
45        Self {
46            builder: glib::object::Object::builder(),
47        }
48    }
49
50    pub fn max_length(self, max_length: i32) -> Self {
51        Self {
52            builder: self.builder.property("max-length", max_length),
53        }
54    }
55
56    pub fn text(self, text: impl Into<glib::GString>) -> Self {
57        Self {
58            builder: self.builder.property("text", text.into()),
59        }
60    }
61
62    // rustdoc-stripper-ignore-next
63    /// Build the [`EntryBuffer`].
64    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
65    pub fn build(self) -> EntryBuffer {
66        assert_initialized_main_thread!();
67        self.builder.build()
68    }
69}
70
71pub trait EntryBufferExt: IsA<EntryBuffer> + 'static {
72    #[doc(alias = "gtk_entry_buffer_emit_deleted_text")]
73    fn emit_deleted_text(&self, position: u32, n_chars: u32) {
74        unsafe {
75            ffi::gtk_entry_buffer_emit_deleted_text(
76                self.as_ref().to_glib_none().0,
77                position,
78                n_chars,
79            );
80        }
81    }
82
83    #[doc(alias = "gtk_entry_buffer_emit_inserted_text")]
84    fn emit_inserted_text(&self, position: u32, chars: &str, n_chars: u32) {
85        unsafe {
86            ffi::gtk_entry_buffer_emit_inserted_text(
87                self.as_ref().to_glib_none().0,
88                position,
89                chars.to_glib_none().0,
90                n_chars,
91            );
92        }
93    }
94
95    #[doc(alias = "length")]
96    fn connect_length_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
97        unsafe extern "C" fn notify_length_trampoline<P: IsA<EntryBuffer>, F: Fn(&P) + 'static>(
98            this: *mut ffi::GtkEntryBuffer,
99            _param_spec: glib::ffi::gpointer,
100            f: glib::ffi::gpointer,
101        ) {
102            let f: &F = &*(f as *const F);
103            f(EntryBuffer::from_glib_borrow(this).unsafe_cast_ref())
104        }
105        unsafe {
106            let f: Box_<F> = Box_::new(f);
107            connect_raw(
108                self.as_ptr() as *mut _,
109                c"notify::length".as_ptr() as *const _,
110                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
111                    notify_length_trampoline::<Self, F> as *const (),
112                )),
113                Box_::into_raw(f),
114            )
115        }
116    }
117
118    #[doc(alias = "max-length")]
119    fn connect_max_length_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
120        unsafe extern "C" fn notify_max_length_trampoline<
121            P: IsA<EntryBuffer>,
122            F: Fn(&P) + 'static,
123        >(
124            this: *mut ffi::GtkEntryBuffer,
125            _param_spec: glib::ffi::gpointer,
126            f: glib::ffi::gpointer,
127        ) {
128            let f: &F = &*(f as *const F);
129            f(EntryBuffer::from_glib_borrow(this).unsafe_cast_ref())
130        }
131        unsafe {
132            let f: Box_<F> = Box_::new(f);
133            connect_raw(
134                self.as_ptr() as *mut _,
135                c"notify::max-length".as_ptr() as *const _,
136                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
137                    notify_max_length_trampoline::<Self, F> as *const (),
138                )),
139                Box_::into_raw(f),
140            )
141        }
142    }
143
144    #[doc(alias = "text")]
145    fn connect_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
146        unsafe extern "C" fn notify_text_trampoline<P: IsA<EntryBuffer>, F: Fn(&P) + 'static>(
147            this: *mut ffi::GtkEntryBuffer,
148            _param_spec: glib::ffi::gpointer,
149            f: glib::ffi::gpointer,
150        ) {
151            let f: &F = &*(f as *const F);
152            f(EntryBuffer::from_glib_borrow(this).unsafe_cast_ref())
153        }
154        unsafe {
155            let f: Box_<F> = Box_::new(f);
156            connect_raw(
157                self.as_ptr() as *mut _,
158                c"notify::text".as_ptr() as *const _,
159                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
160                    notify_text_trampoline::<Self, F> as *const (),
161                )),
162                Box_::into_raw(f),
163            )
164        }
165    }
166}
167
168impl<O: IsA<EntryBuffer>> EntryBufferExt for O {}