gtk4/auto/
search_bar.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::{
6    ffi, Accessible, AccessibleRole, Align, Buildable, ConstraintTarget, Editable, LayoutManager,
7    Overflow, Widget,
8};
9use glib::{
10    prelude::*,
11    signal::{connect_raw, SignalHandlerId},
12    translate::*,
13};
14use std::boxed::Box as Box_;
15
16glib::wrapper! {
17    #[doc(alias = "GtkSearchBar")]
18    pub struct SearchBar(Object<ffi::GtkSearchBar>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget;
19
20    match fn {
21        type_ => || ffi::gtk_search_bar_get_type(),
22    }
23}
24
25impl SearchBar {
26    #[doc(alias = "gtk_search_bar_new")]
27    pub fn new() -> SearchBar {
28        assert_initialized_main_thread!();
29        unsafe { Widget::from_glib_none(ffi::gtk_search_bar_new()).unsafe_cast() }
30    }
31
32    // rustdoc-stripper-ignore-next
33    /// Creates a new builder-pattern struct instance to construct [`SearchBar`] objects.
34    ///
35    /// This method returns an instance of [`SearchBarBuilder`](crate::builders::SearchBarBuilder) which can be used to create [`SearchBar`] objects.
36    pub fn builder() -> SearchBarBuilder {
37        SearchBarBuilder::new()
38    }
39
40    #[doc(alias = "gtk_search_bar_connect_entry")]
41    pub fn connect_entry(&self, entry: &impl IsA<Editable>) {
42        unsafe {
43            ffi::gtk_search_bar_connect_entry(
44                self.to_glib_none().0,
45                entry.as_ref().to_glib_none().0,
46            );
47        }
48    }
49
50    #[doc(alias = "gtk_search_bar_get_child")]
51    #[doc(alias = "get_child")]
52    pub fn child(&self) -> Option<Widget> {
53        unsafe { from_glib_none(ffi::gtk_search_bar_get_child(self.to_glib_none().0)) }
54    }
55
56    #[doc(alias = "gtk_search_bar_get_key_capture_widget")]
57    #[doc(alias = "get_key_capture_widget")]
58    #[doc(alias = "key-capture-widget")]
59    pub fn key_capture_widget(&self) -> Option<Widget> {
60        unsafe {
61            from_glib_none(ffi::gtk_search_bar_get_key_capture_widget(
62                self.to_glib_none().0,
63            ))
64        }
65    }
66
67    #[doc(alias = "gtk_search_bar_get_search_mode")]
68    #[doc(alias = "get_search_mode")]
69    #[doc(alias = "search-mode-enabled")]
70    pub fn is_search_mode(&self) -> bool {
71        unsafe { from_glib(ffi::gtk_search_bar_get_search_mode(self.to_glib_none().0)) }
72    }
73
74    #[doc(alias = "gtk_search_bar_get_show_close_button")]
75    #[doc(alias = "get_show_close_button")]
76    #[doc(alias = "show-close-button")]
77    pub fn shows_close_button(&self) -> bool {
78        unsafe {
79            from_glib(ffi::gtk_search_bar_get_show_close_button(
80                self.to_glib_none().0,
81            ))
82        }
83    }
84
85    #[doc(alias = "gtk_search_bar_set_child")]
86    #[doc(alias = "child")]
87    pub fn set_child(&self, child: Option<&impl IsA<Widget>>) {
88        unsafe {
89            ffi::gtk_search_bar_set_child(
90                self.to_glib_none().0,
91                child.map(|p| p.as_ref()).to_glib_none().0,
92            );
93        }
94    }
95
96    #[doc(alias = "gtk_search_bar_set_key_capture_widget")]
97    #[doc(alias = "key-capture-widget")]
98    pub fn set_key_capture_widget(&self, widget: Option<&impl IsA<Widget>>) {
99        unsafe {
100            ffi::gtk_search_bar_set_key_capture_widget(
101                self.to_glib_none().0,
102                widget.map(|p| p.as_ref()).to_glib_none().0,
103            );
104        }
105    }
106
107    #[doc(alias = "gtk_search_bar_set_search_mode")]
108    #[doc(alias = "search-mode-enabled")]
109    pub fn set_search_mode(&self, search_mode: bool) {
110        unsafe {
111            ffi::gtk_search_bar_set_search_mode(self.to_glib_none().0, search_mode.into_glib());
112        }
113    }
114
115    #[doc(alias = "gtk_search_bar_set_show_close_button")]
116    #[doc(alias = "show-close-button")]
117    pub fn set_show_close_button(&self, visible: bool) {
118        unsafe {
119            ffi::gtk_search_bar_set_show_close_button(self.to_glib_none().0, visible.into_glib());
120        }
121    }
122
123    #[doc(alias = "child")]
124    pub fn connect_child_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
125        unsafe extern "C" fn notify_child_trampoline<F: Fn(&SearchBar) + 'static>(
126            this: *mut ffi::GtkSearchBar,
127            _param_spec: glib::ffi::gpointer,
128            f: glib::ffi::gpointer,
129        ) {
130            let f: &F = &*(f as *const F);
131            f(&from_glib_borrow(this))
132        }
133        unsafe {
134            let f: Box_<F> = Box_::new(f);
135            connect_raw(
136                self.as_ptr() as *mut _,
137                c"notify::child".as_ptr() as *const _,
138                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
139                    notify_child_trampoline::<F> as *const (),
140                )),
141                Box_::into_raw(f),
142            )
143        }
144    }
145
146    #[doc(alias = "key-capture-widget")]
147    pub fn connect_key_capture_widget_notify<F: Fn(&Self) + 'static>(
148        &self,
149        f: F,
150    ) -> SignalHandlerId {
151        unsafe extern "C" fn notify_key_capture_widget_trampoline<F: Fn(&SearchBar) + 'static>(
152            this: *mut ffi::GtkSearchBar,
153            _param_spec: glib::ffi::gpointer,
154            f: glib::ffi::gpointer,
155        ) {
156            let f: &F = &*(f as *const F);
157            f(&from_glib_borrow(this))
158        }
159        unsafe {
160            let f: Box_<F> = Box_::new(f);
161            connect_raw(
162                self.as_ptr() as *mut _,
163                c"notify::key-capture-widget".as_ptr() as *const _,
164                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
165                    notify_key_capture_widget_trampoline::<F> as *const (),
166                )),
167                Box_::into_raw(f),
168            )
169        }
170    }
171
172    #[doc(alias = "search-mode-enabled")]
173    pub fn connect_search_mode_enabled_notify<F: Fn(&Self) + 'static>(
174        &self,
175        f: F,
176    ) -> SignalHandlerId {
177        unsafe extern "C" fn notify_search_mode_enabled_trampoline<F: Fn(&SearchBar) + 'static>(
178            this: *mut ffi::GtkSearchBar,
179            _param_spec: glib::ffi::gpointer,
180            f: glib::ffi::gpointer,
181        ) {
182            let f: &F = &*(f as *const F);
183            f(&from_glib_borrow(this))
184        }
185        unsafe {
186            let f: Box_<F> = Box_::new(f);
187            connect_raw(
188                self.as_ptr() as *mut _,
189                c"notify::search-mode-enabled".as_ptr() as *const _,
190                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
191                    notify_search_mode_enabled_trampoline::<F> as *const (),
192                )),
193                Box_::into_raw(f),
194            )
195        }
196    }
197
198    #[doc(alias = "show-close-button")]
199    pub fn connect_show_close_button_notify<F: Fn(&Self) + 'static>(
200        &self,
201        f: F,
202    ) -> SignalHandlerId {
203        unsafe extern "C" fn notify_show_close_button_trampoline<F: Fn(&SearchBar) + 'static>(
204            this: *mut ffi::GtkSearchBar,
205            _param_spec: glib::ffi::gpointer,
206            f: glib::ffi::gpointer,
207        ) {
208            let f: &F = &*(f as *const F);
209            f(&from_glib_borrow(this))
210        }
211        unsafe {
212            let f: Box_<F> = Box_::new(f);
213            connect_raw(
214                self.as_ptr() as *mut _,
215                c"notify::show-close-button".as_ptr() as *const _,
216                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
217                    notify_show_close_button_trampoline::<F> as *const (),
218                )),
219                Box_::into_raw(f),
220            )
221        }
222    }
223}
224
225impl Default for SearchBar {
226    fn default() -> Self {
227        Self::new()
228    }
229}
230
231// rustdoc-stripper-ignore-next
232/// A [builder-pattern] type to construct [`SearchBar`] objects.
233///
234/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
235#[must_use = "The builder must be built to be used"]
236pub struct SearchBarBuilder {
237    builder: glib::object::ObjectBuilder<'static, SearchBar>,
238}
239
240impl SearchBarBuilder {
241    fn new() -> Self {
242        Self {
243            builder: glib::object::Object::builder(),
244        }
245    }
246
247    pub fn child(self, child: &impl IsA<Widget>) -> Self {
248        Self {
249            builder: self.builder.property("child", child.clone().upcast()),
250        }
251    }
252
253    pub fn key_capture_widget(self, key_capture_widget: &impl IsA<Widget>) -> Self {
254        Self {
255            builder: self
256                .builder
257                .property("key-capture-widget", key_capture_widget.clone().upcast()),
258        }
259    }
260
261    pub fn search_mode_enabled(self, search_mode_enabled: bool) -> Self {
262        Self {
263            builder: self
264                .builder
265                .property("search-mode-enabled", search_mode_enabled),
266        }
267    }
268
269    pub fn show_close_button(self, show_close_button: bool) -> Self {
270        Self {
271            builder: self
272                .builder
273                .property("show-close-button", show_close_button),
274        }
275    }
276
277    pub fn can_focus(self, can_focus: bool) -> Self {
278        Self {
279            builder: self.builder.property("can-focus", can_focus),
280        }
281    }
282
283    pub fn can_target(self, can_target: bool) -> Self {
284        Self {
285            builder: self.builder.property("can-target", can_target),
286        }
287    }
288
289    pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
290        Self {
291            builder: self.builder.property("css-classes", css_classes.into()),
292        }
293    }
294
295    pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
296        Self {
297            builder: self.builder.property("css-name", css_name.into()),
298        }
299    }
300
301    pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
302        Self {
303            builder: self.builder.property("cursor", cursor.clone()),
304        }
305    }
306
307    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
308        Self {
309            builder: self.builder.property("focus-on-click", focus_on_click),
310        }
311    }
312
313    pub fn focusable(self, focusable: bool) -> Self {
314        Self {
315            builder: self.builder.property("focusable", focusable),
316        }
317    }
318
319    pub fn halign(self, halign: Align) -> Self {
320        Self {
321            builder: self.builder.property("halign", halign),
322        }
323    }
324
325    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
326        Self {
327            builder: self.builder.property("has-tooltip", has_tooltip),
328        }
329    }
330
331    pub fn height_request(self, height_request: i32) -> Self {
332        Self {
333            builder: self.builder.property("height-request", height_request),
334        }
335    }
336
337    pub fn hexpand(self, hexpand: bool) -> Self {
338        Self {
339            builder: self.builder.property("hexpand", hexpand),
340        }
341    }
342
343    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
344        Self {
345            builder: self.builder.property("hexpand-set", hexpand_set),
346        }
347    }
348
349    pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
350        Self {
351            builder: self
352                .builder
353                .property("layout-manager", layout_manager.clone().upcast()),
354        }
355    }
356
357    #[cfg(feature = "v4_18")]
358    #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
359    pub fn limit_events(self, limit_events: bool) -> Self {
360        Self {
361            builder: self.builder.property("limit-events", limit_events),
362        }
363    }
364
365    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
366        Self {
367            builder: self.builder.property("margin-bottom", margin_bottom),
368        }
369    }
370
371    pub fn margin_end(self, margin_end: i32) -> Self {
372        Self {
373            builder: self.builder.property("margin-end", margin_end),
374        }
375    }
376
377    pub fn margin_start(self, margin_start: i32) -> Self {
378        Self {
379            builder: self.builder.property("margin-start", margin_start),
380        }
381    }
382
383    pub fn margin_top(self, margin_top: i32) -> Self {
384        Self {
385            builder: self.builder.property("margin-top", margin_top),
386        }
387    }
388
389    pub fn name(self, name: impl Into<glib::GString>) -> Self {
390        Self {
391            builder: self.builder.property("name", name.into()),
392        }
393    }
394
395    pub fn opacity(self, opacity: f64) -> Self {
396        Self {
397            builder: self.builder.property("opacity", opacity),
398        }
399    }
400
401    pub fn overflow(self, overflow: Overflow) -> Self {
402        Self {
403            builder: self.builder.property("overflow", overflow),
404        }
405    }
406
407    pub fn receives_default(self, receives_default: bool) -> Self {
408        Self {
409            builder: self.builder.property("receives-default", receives_default),
410        }
411    }
412
413    pub fn sensitive(self, sensitive: bool) -> Self {
414        Self {
415            builder: self.builder.property("sensitive", sensitive),
416        }
417    }
418
419    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
420        Self {
421            builder: self
422                .builder
423                .property("tooltip-markup", tooltip_markup.into()),
424        }
425    }
426
427    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
428        Self {
429            builder: self.builder.property("tooltip-text", tooltip_text.into()),
430        }
431    }
432
433    pub fn valign(self, valign: Align) -> Self {
434        Self {
435            builder: self.builder.property("valign", valign),
436        }
437    }
438
439    pub fn vexpand(self, vexpand: bool) -> Self {
440        Self {
441            builder: self.builder.property("vexpand", vexpand),
442        }
443    }
444
445    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
446        Self {
447            builder: self.builder.property("vexpand-set", vexpand_set),
448        }
449    }
450
451    pub fn visible(self, visible: bool) -> Self {
452        Self {
453            builder: self.builder.property("visible", visible),
454        }
455    }
456
457    pub fn width_request(self, width_request: i32) -> Self {
458        Self {
459            builder: self.builder.property("width-request", width_request),
460        }
461    }
462
463    pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
464        Self {
465            builder: self.builder.property("accessible-role", accessible_role),
466        }
467    }
468
469    // rustdoc-stripper-ignore-next
470    /// Build the [`SearchBar`].
471    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
472    pub fn build(self) -> SearchBar {
473        assert_initialized_main_thread!();
474        self.builder.build()
475    }
476}