gtk/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::{Align, Bin, Buildable, Container, Entry, ResizeMode, Widget};
6use glib::{
7 prelude::*,
8 signal::{connect_raw, SignalHandlerId},
9 translate::*,
10};
11use std::{boxed::Box as Box_, fmt, mem::transmute};
12
13glib::wrapper! {
14 /// [`SearchBar`][crate::SearchBar] is a container made to have a search entry (possibly
15 /// with additional connex widgets, such as drop-down menus, or buttons)
16 /// built-in. The search bar would appear when a search is started through
17 /// typing on the keyboard, or the application’s search mode is toggled on.
18 ///
19 /// For keyboard presses to start a search, events will need to be
20 /// forwarded from the top-level window that contains the search bar.
21 /// See [`SearchBarExt::handle_event()`][crate::prelude::SearchBarExt::handle_event()] for example code. Common shortcuts
22 /// such as Ctrl+F should be handled as an application action, or through
23 /// the menu items.
24 ///
25 /// You will also need to tell the search bar about which entry you
26 /// are using as your search entry using [`SearchBarExt::connect_entry()`][crate::prelude::SearchBarExt::connect_entry()].
27 /// The following example shows you how to create a more complex search
28 /// entry.
29 ///
30 /// # CSS nodes
31 ///
32 /// GtkSearchBar has a single CSS node with name searchbar.
33 ///
34 /// ## Creating a search bar
35 ///
36 /// [A simple example](https://gitlab.gnome.org/GNOME/gtk/blob/gtk-3-24/examples/search-bar.c)
37 ///
38 /// ## Properties
39 ///
40 ///
41 /// #### `search-mode-enabled`
42 /// Readable | Writeable
43 ///
44 ///
45 /// #### `show-close-button`
46 /// Readable | Writeable | Construct
47 /// <details><summary><h4>Container</h4></summary>
48 ///
49 ///
50 /// #### `border-width`
51 /// Readable | Writeable
52 ///
53 ///
54 /// #### `child`
55 /// Writeable
56 ///
57 ///
58 /// #### `resize-mode`
59 /// Readable | Writeable
60 /// </details>
61 /// <details><summary><h4>Widget</h4></summary>
62 ///
63 ///
64 /// #### `app-paintable`
65 /// Readable | Writeable
66 ///
67 ///
68 /// #### `can-default`
69 /// Readable | Writeable
70 ///
71 ///
72 /// #### `can-focus`
73 /// Readable | Writeable
74 ///
75 ///
76 /// #### `composite-child`
77 /// Readable
78 ///
79 ///
80 /// #### `double-buffered`
81 /// Whether the widget is double buffered.
82 ///
83 /// Readable | Writeable
84 ///
85 ///
86 /// #### `events`
87 /// Readable | Writeable
88 ///
89 ///
90 /// #### `expand`
91 /// Whether to expand in both directions. Setting this sets both [`hexpand`][struct@crate::Widget#hexpand] and [`vexpand`][struct@crate::Widget#vexpand]
92 ///
93 /// Readable | Writeable
94 ///
95 ///
96 /// #### `focus-on-click`
97 /// Whether the widget should grab focus when it is clicked with the mouse.
98 ///
99 /// This property is only relevant for widgets that can take focus.
100 ///
101 /// Before 3.20, several widgets (GtkButton, GtkFileChooserButton,
102 /// GtkComboBox) implemented this property individually.
103 ///
104 /// Readable | Writeable
105 ///
106 ///
107 /// #### `halign`
108 /// How to distribute horizontal space if widget gets extra space, see [`Align`][crate::Align]
109 ///
110 /// Readable | Writeable
111 ///
112 ///
113 /// #### `has-default`
114 /// Readable | Writeable
115 ///
116 ///
117 /// #### `has-focus`
118 /// Readable | Writeable
119 ///
120 ///
121 /// #### `has-tooltip`
122 /// Enables or disables the emission of [`query-tooltip`][struct@crate::Widget#query-tooltip] on `widget`.
123 /// A value of [`true`] indicates that `widget` can have a tooltip, in this case
124 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to determine
125 /// whether it will provide a tooltip or not.
126 ///
127 /// Note that setting this property to [`true`] for the first time will change
128 /// the event masks of the GdkWindows of this widget to include leave-notify
129 /// and motion-notify events. This cannot and will not be undone when the
130 /// property is set to [`false`] again.
131 ///
132 /// Readable | Writeable
133 ///
134 ///
135 /// #### `height-request`
136 /// Readable | Writeable
137 ///
138 ///
139 /// #### `hexpand`
140 /// Whether to expand horizontally. See [`WidgetExt::set_hexpand()`][crate::prelude::WidgetExt::set_hexpand()].
141 ///
142 /// Readable | Writeable
143 ///
144 ///
145 /// #### `hexpand-set`
146 /// Whether to use the [`hexpand`][struct@crate::Widget#hexpand] property. See [`WidgetExt::is_hexpand_set()`][crate::prelude::WidgetExt::is_hexpand_set()].
147 ///
148 /// Readable | Writeable
149 ///
150 ///
151 /// #### `is-focus`
152 /// Readable | Writeable
153 ///
154 ///
155 /// #### `margin`
156 /// Sets all four sides' margin at once. If read, returns max
157 /// margin on any side.
158 ///
159 /// Readable | Writeable
160 ///
161 ///
162 /// #### `margin-bottom`
163 /// Margin on bottom side of widget.
164 ///
165 /// This property adds margin outside of the widget's normal size
166 /// request, the margin will be added in addition to the size from
167 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
168 ///
169 /// Readable | Writeable
170 ///
171 ///
172 /// #### `margin-end`
173 /// Margin on end of widget, horizontally. This property supports
174 /// left-to-right and right-to-left text directions.
175 ///
176 /// This property adds margin outside of the widget's normal size
177 /// request, the margin will be added in addition to the size from
178 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
179 ///
180 /// Readable | Writeable
181 ///
182 ///
183 /// #### `margin-left`
184 /// Margin on left side of widget.
185 ///
186 /// This property adds margin outside of the widget's normal size
187 /// request, the margin will be added in addition to the size from
188 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
189 ///
190 /// Readable | Writeable
191 ///
192 ///
193 /// #### `margin-right`
194 /// Margin on right side of widget.
195 ///
196 /// This property adds margin outside of the widget's normal size
197 /// request, the margin will be added in addition to the size from
198 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
199 ///
200 /// Readable | Writeable
201 ///
202 ///
203 /// #### `margin-start`
204 /// Margin on start of widget, horizontally. This property supports
205 /// left-to-right and right-to-left text directions.
206 ///
207 /// This property adds margin outside of the widget's normal size
208 /// request, the margin will be added in addition to the size from
209 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
210 ///
211 /// Readable | Writeable
212 ///
213 ///
214 /// #### `margin-top`
215 /// Margin on top side of widget.
216 ///
217 /// This property adds margin outside of the widget's normal size
218 /// request, the margin will be added in addition to the size from
219 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
220 ///
221 /// Readable | Writeable
222 ///
223 ///
224 /// #### `name`
225 /// Readable | Writeable
226 ///
227 ///
228 /// #### `no-show-all`
229 /// Readable | Writeable
230 ///
231 ///
232 /// #### `opacity`
233 /// The requested opacity of the widget. See [`WidgetExt::set_opacity()`][crate::prelude::WidgetExt::set_opacity()] for
234 /// more details about window opacity.
235 ///
236 /// Before 3.8 this was only available in GtkWindow
237 ///
238 /// Readable | Writeable
239 ///
240 ///
241 /// #### `parent`
242 /// Readable | Writeable
243 ///
244 ///
245 /// #### `receives-default`
246 /// Readable | Writeable
247 ///
248 ///
249 /// #### `scale-factor`
250 /// The scale factor of the widget. See [`WidgetExt::scale_factor()`][crate::prelude::WidgetExt::scale_factor()] for
251 /// more details about widget scaling.
252 ///
253 /// Readable
254 ///
255 ///
256 /// #### `sensitive`
257 /// Readable | Writeable
258 ///
259 ///
260 /// #### `style`
261 /// The style of the widget, which contains information about how it will look (colors, etc).
262 ///
263 /// Readable | Writeable
264 ///
265 ///
266 /// #### `tooltip-markup`
267 /// Sets the text of tooltip to be the given string, which is marked up
268 /// with the [Pango text markup language][PangoMarkupFormat].
269 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
270 ///
271 /// This is a convenience property which will take care of getting the
272 /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
273 /// will automatically be set to [`true`] and there will be taken care of
274 /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
275 ///
276 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
277 /// are set, the last one wins.
278 ///
279 /// Readable | Writeable
280 ///
281 ///
282 /// #### `tooltip-text`
283 /// Sets the text of tooltip to be the given string.
284 ///
285 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
286 ///
287 /// This is a convenience property which will take care of getting the
288 /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
289 /// will automatically be set to [`true`] and there will be taken care of
290 /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
291 ///
292 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
293 /// are set, the last one wins.
294 ///
295 /// Readable | Writeable
296 ///
297 ///
298 /// #### `valign`
299 /// How to distribute vertical space if widget gets extra space, see [`Align`][crate::Align]
300 ///
301 /// Readable | Writeable
302 ///
303 ///
304 /// #### `vexpand`
305 /// Whether to expand vertically. See [`WidgetExt::set_vexpand()`][crate::prelude::WidgetExt::set_vexpand()].
306 ///
307 /// Readable | Writeable
308 ///
309 ///
310 /// #### `vexpand-set`
311 /// Whether to use the [`vexpand`][struct@crate::Widget#vexpand] property. See [`WidgetExt::is_vexpand_set()`][crate::prelude::WidgetExt::is_vexpand_set()].
312 ///
313 /// Readable | Writeable
314 ///
315 ///
316 /// #### `visible`
317 /// Readable | Writeable
318 ///
319 ///
320 /// #### `width-request`
321 /// Readable | Writeable
322 ///
323 ///
324 /// #### `window`
325 /// The widget's window if it is realized, [`None`] otherwise.
326 ///
327 /// Readable
328 /// </details>
329 ///
330 /// # Implements
331 ///
332 /// [`SearchBarExt`][trait@crate::prelude::SearchBarExt], [`BinExt`][trait@crate::prelude::BinExt], [`ContainerExt`][trait@crate::prelude::ContainerExt], [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ContainerExtManual`][trait@crate::prelude::ContainerExtManual], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`BuildableExtManual`][trait@crate::prelude::BuildableExtManual]
333 #[doc(alias = "GtkSearchBar")]
334 pub struct SearchBar(Object<ffi::GtkSearchBar, ffi::GtkSearchBarClass>) @extends Bin, Container, Widget, @implements Buildable;
335
336 match fn {
337 type_ => || ffi::gtk_search_bar_get_type(),
338 }
339}
340
341impl SearchBar {
342 pub const NONE: Option<&'static SearchBar> = None;
343
344 /// Creates a [`SearchBar`][crate::SearchBar]. You will need to tell it about
345 /// which widget is going to be your text entry using
346 /// [`SearchBarExt::connect_entry()`][crate::prelude::SearchBarExt::connect_entry()].
347 ///
348 /// # Returns
349 ///
350 /// a new [`SearchBar`][crate::SearchBar]
351 #[doc(alias = "gtk_search_bar_new")]
352 pub fn new() -> SearchBar {
353 assert_initialized_main_thread!();
354 unsafe { Widget::from_glib_none(ffi::gtk_search_bar_new()).unsafe_cast() }
355 }
356
357 // rustdoc-stripper-ignore-next
358 /// Creates a new builder-pattern struct instance to construct [`SearchBar`] objects.
359 ///
360 /// This method returns an instance of [`SearchBarBuilder`](crate::builders::SearchBarBuilder) which can be used to create [`SearchBar`] objects.
361 pub fn builder() -> SearchBarBuilder {
362 SearchBarBuilder::new()
363 }
364}
365
366impl Default for SearchBar {
367 fn default() -> Self {
368 Self::new()
369 }
370}
371
372// rustdoc-stripper-ignore-next
373/// A [builder-pattern] type to construct [`SearchBar`] objects.
374///
375/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
376#[must_use = "The builder must be built to be used"]
377pub struct SearchBarBuilder {
378 builder: glib::object::ObjectBuilder<'static, SearchBar>,
379}
380
381impl SearchBarBuilder {
382 fn new() -> Self {
383 Self {
384 builder: glib::object::Object::builder(),
385 }
386 }
387
388 pub fn search_mode_enabled(self, search_mode_enabled: bool) -> Self {
389 Self {
390 builder: self
391 .builder
392 .property("search-mode-enabled", search_mode_enabled),
393 }
394 }
395
396 pub fn show_close_button(self, show_close_button: bool) -> Self {
397 Self {
398 builder: self
399 .builder
400 .property("show-close-button", show_close_button),
401 }
402 }
403
404 pub fn border_width(self, border_width: u32) -> Self {
405 Self {
406 builder: self.builder.property("border-width", border_width),
407 }
408 }
409
410 pub fn child(self, child: &impl IsA<Widget>) -> Self {
411 Self {
412 builder: self.builder.property("child", child.clone().upcast()),
413 }
414 }
415
416 pub fn resize_mode(self, resize_mode: ResizeMode) -> Self {
417 Self {
418 builder: self.builder.property("resize-mode", resize_mode),
419 }
420 }
421
422 pub fn app_paintable(self, app_paintable: bool) -> Self {
423 Self {
424 builder: self.builder.property("app-paintable", app_paintable),
425 }
426 }
427
428 pub fn can_default(self, can_default: bool) -> Self {
429 Self {
430 builder: self.builder.property("can-default", can_default),
431 }
432 }
433
434 pub fn can_focus(self, can_focus: bool) -> Self {
435 Self {
436 builder: self.builder.property("can-focus", can_focus),
437 }
438 }
439
440 pub fn events(self, events: gdk::EventMask) -> Self {
441 Self {
442 builder: self.builder.property("events", events),
443 }
444 }
445
446 /// Whether to expand in both directions. Setting this sets both [`hexpand`][struct@crate::Widget#hexpand] and [`vexpand`][struct@crate::Widget#vexpand]
447 pub fn expand(self, expand: bool) -> Self {
448 Self {
449 builder: self.builder.property("expand", expand),
450 }
451 }
452
453 /// Whether the widget should grab focus when it is clicked with the mouse.
454 ///
455 /// This property is only relevant for widgets that can take focus.
456 ///
457 /// Before 3.20, several widgets (GtkButton, GtkFileChooserButton,
458 /// GtkComboBox) implemented this property individually.
459 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
460 Self {
461 builder: self.builder.property("focus-on-click", focus_on_click),
462 }
463 }
464
465 /// How to distribute horizontal space if widget gets extra space, see [`Align`][crate::Align]
466 pub fn halign(self, halign: Align) -> Self {
467 Self {
468 builder: self.builder.property("halign", halign),
469 }
470 }
471
472 pub fn has_default(self, has_default: bool) -> Self {
473 Self {
474 builder: self.builder.property("has-default", has_default),
475 }
476 }
477
478 pub fn has_focus(self, has_focus: bool) -> Self {
479 Self {
480 builder: self.builder.property("has-focus", has_focus),
481 }
482 }
483
484 /// Enables or disables the emission of [`query-tooltip`][struct@crate::Widget#query-tooltip] on `widget`.
485 /// A value of [`true`] indicates that `widget` can have a tooltip, in this case
486 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to determine
487 /// whether it will provide a tooltip or not.
488 ///
489 /// Note that setting this property to [`true`] for the first time will change
490 /// the event masks of the GdkWindows of this widget to include leave-notify
491 /// and motion-notify events. This cannot and will not be undone when the
492 /// property is set to [`false`] again.
493 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
494 Self {
495 builder: self.builder.property("has-tooltip", has_tooltip),
496 }
497 }
498
499 pub fn height_request(self, height_request: i32) -> Self {
500 Self {
501 builder: self.builder.property("height-request", height_request),
502 }
503 }
504
505 /// Whether to expand horizontally. See [`WidgetExt::set_hexpand()`][crate::prelude::WidgetExt::set_hexpand()].
506 pub fn hexpand(self, hexpand: bool) -> Self {
507 Self {
508 builder: self.builder.property("hexpand", hexpand),
509 }
510 }
511
512 /// Whether to use the [`hexpand`][struct@crate::Widget#hexpand] property. See [`WidgetExt::is_hexpand_set()`][crate::prelude::WidgetExt::is_hexpand_set()].
513 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
514 Self {
515 builder: self.builder.property("hexpand-set", hexpand_set),
516 }
517 }
518
519 pub fn is_focus(self, is_focus: bool) -> Self {
520 Self {
521 builder: self.builder.property("is-focus", is_focus),
522 }
523 }
524
525 /// Sets all four sides' margin at once. If read, returns max
526 /// margin on any side.
527 pub fn margin(self, margin: i32) -> Self {
528 Self {
529 builder: self.builder.property("margin", margin),
530 }
531 }
532
533 /// Margin on bottom side of widget.
534 ///
535 /// This property adds margin outside of the widget's normal size
536 /// request, the margin will be added in addition to the size from
537 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
538 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
539 Self {
540 builder: self.builder.property("margin-bottom", margin_bottom),
541 }
542 }
543
544 /// Margin on end of widget, horizontally. This property supports
545 /// left-to-right and right-to-left text directions.
546 ///
547 /// This property adds margin outside of the widget's normal size
548 /// request, the margin will be added in addition to the size from
549 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
550 pub fn margin_end(self, margin_end: i32) -> Self {
551 Self {
552 builder: self.builder.property("margin-end", margin_end),
553 }
554 }
555
556 /// Margin on start of widget, horizontally. This property supports
557 /// left-to-right and right-to-left text directions.
558 ///
559 /// This property adds margin outside of the widget's normal size
560 /// request, the margin will be added in addition to the size from
561 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
562 pub fn margin_start(self, margin_start: i32) -> Self {
563 Self {
564 builder: self.builder.property("margin-start", margin_start),
565 }
566 }
567
568 /// Margin on top side of widget.
569 ///
570 /// This property adds margin outside of the widget's normal size
571 /// request, the margin will be added in addition to the size from
572 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
573 pub fn margin_top(self, margin_top: i32) -> Self {
574 Self {
575 builder: self.builder.property("margin-top", margin_top),
576 }
577 }
578
579 pub fn name(self, name: impl Into<glib::GString>) -> Self {
580 Self {
581 builder: self.builder.property("name", name.into()),
582 }
583 }
584
585 pub fn no_show_all(self, no_show_all: bool) -> Self {
586 Self {
587 builder: self.builder.property("no-show-all", no_show_all),
588 }
589 }
590
591 /// The requested opacity of the widget. See [`WidgetExt::set_opacity()`][crate::prelude::WidgetExt::set_opacity()] for
592 /// more details about window opacity.
593 ///
594 /// Before 3.8 this was only available in GtkWindow
595 pub fn opacity(self, opacity: f64) -> Self {
596 Self {
597 builder: self.builder.property("opacity", opacity),
598 }
599 }
600
601 pub fn parent(self, parent: &impl IsA<Container>) -> Self {
602 Self {
603 builder: self.builder.property("parent", parent.clone().upcast()),
604 }
605 }
606
607 pub fn receives_default(self, receives_default: bool) -> Self {
608 Self {
609 builder: self.builder.property("receives-default", receives_default),
610 }
611 }
612
613 pub fn sensitive(self, sensitive: bool) -> Self {
614 Self {
615 builder: self.builder.property("sensitive", sensitive),
616 }
617 }
618
619 /// Sets the text of tooltip to be the given string, which is marked up
620 /// with the [Pango text markup language][PangoMarkupFormat].
621 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
622 ///
623 /// This is a convenience property which will take care of getting the
624 /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
625 /// will automatically be set to [`true`] and there will be taken care of
626 /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
627 ///
628 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
629 /// are set, the last one wins.
630 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
631 Self {
632 builder: self
633 .builder
634 .property("tooltip-markup", tooltip_markup.into()),
635 }
636 }
637
638 /// Sets the text of tooltip to be the given string.
639 ///
640 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
641 ///
642 /// This is a convenience property which will take care of getting the
643 /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
644 /// will automatically be set to [`true`] and there will be taken care of
645 /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
646 ///
647 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
648 /// are set, the last one wins.
649 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
650 Self {
651 builder: self.builder.property("tooltip-text", tooltip_text.into()),
652 }
653 }
654
655 /// How to distribute vertical space if widget gets extra space, see [`Align`][crate::Align]
656 pub fn valign(self, valign: Align) -> Self {
657 Self {
658 builder: self.builder.property("valign", valign),
659 }
660 }
661
662 /// Whether to expand vertically. See [`WidgetExt::set_vexpand()`][crate::prelude::WidgetExt::set_vexpand()].
663 pub fn vexpand(self, vexpand: bool) -> Self {
664 Self {
665 builder: self.builder.property("vexpand", vexpand),
666 }
667 }
668
669 /// Whether to use the [`vexpand`][struct@crate::Widget#vexpand] property. See [`WidgetExt::is_vexpand_set()`][crate::prelude::WidgetExt::is_vexpand_set()].
670 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
671 Self {
672 builder: self.builder.property("vexpand-set", vexpand_set),
673 }
674 }
675
676 pub fn visible(self, visible: bool) -> Self {
677 Self {
678 builder: self.builder.property("visible", visible),
679 }
680 }
681
682 pub fn width_request(self, width_request: i32) -> Self {
683 Self {
684 builder: self.builder.property("width-request", width_request),
685 }
686 }
687
688 // rustdoc-stripper-ignore-next
689 /// Build the [`SearchBar`].
690 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
691 pub fn build(self) -> SearchBar {
692 self.builder.build()
693 }
694}
695
696mod sealed {
697 pub trait Sealed {}
698 impl<T: super::IsA<super::SearchBar>> Sealed for T {}
699}
700
701/// Trait containing all [`struct@SearchBar`] methods.
702///
703/// # Implementors
704///
705/// [`SearchBar`][struct@crate::SearchBar]
706pub trait SearchBarExt: IsA<SearchBar> + sealed::Sealed + 'static {
707 /// Connects the [`Entry`][crate::Entry] widget passed as the one to be used in
708 /// this search bar. The entry should be a descendant of the search bar.
709 /// This is only required if the entry isn’t the direct child of the
710 /// search bar (as in our main example).
711 /// ## `entry`
712 /// a [`Entry`][crate::Entry]
713 #[doc(alias = "gtk_search_bar_connect_entry")]
714 fn connect_entry(&self, entry: &impl IsA<Entry>) {
715 unsafe {
716 ffi::gtk_search_bar_connect_entry(
717 self.as_ref().to_glib_none().0,
718 entry.as_ref().to_glib_none().0,
719 );
720 }
721 }
722
723 /// Returns whether the search mode is on or off.
724 ///
725 /// # Returns
726 ///
727 /// whether search mode is toggled on
728 #[doc(alias = "gtk_search_bar_get_search_mode")]
729 #[doc(alias = "get_search_mode")]
730 fn is_search_mode(&self) -> bool {
731 unsafe {
732 from_glib(ffi::gtk_search_bar_get_search_mode(
733 self.as_ref().to_glib_none().0,
734 ))
735 }
736 }
737
738 /// Returns whether the close button is shown.
739 ///
740 /// # Returns
741 ///
742 /// whether the close button is shown
743 #[doc(alias = "gtk_search_bar_get_show_close_button")]
744 #[doc(alias = "get_show_close_button")]
745 fn shows_close_button(&self) -> bool {
746 unsafe {
747 from_glib(ffi::gtk_search_bar_get_show_close_button(
748 self.as_ref().to_glib_none().0,
749 ))
750 }
751 }
752
753 /// This function should be called when the top-level
754 /// window which contains the search bar received a key event.
755 ///
756 /// If the key event is handled by the search bar, the bar will
757 /// be shown, the entry populated with the entered text and `GDK_EVENT_STOP`
758 /// will be returned. The caller should ensure that events are
759 /// not propagated further.
760 ///
761 /// If no entry has been connected to the search bar, using
762 /// [`connect_entry()`][Self::connect_entry()], this function will return
763 /// immediately with a warning.
764 ///
765 /// ## Showing the search bar on key presses
766 ///
767 ///
768 ///
769 /// **⚠️ The following code is in C ⚠️**
770 ///
771 /// ```C
772 /// static gboolean
773 /// on_key_press_event (GtkWidget *widget,
774 /// GdkEvent *event,
775 /// gpointer user_data)
776 /// {
777 /// GtkSearchBar *bar = GTK_SEARCH_BAR (user_data);
778 /// return gtk_search_bar_handle_event (bar, event);
779 /// }
780 ///
781 /// static void
782 /// create_toplevel (void)
783 /// {
784 /// GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
785 /// GtkWindow *search_bar = gtk_search_bar_new ();
786 ///
787 /// // Add more widgets to the window...
788 ///
789 /// g_signal_connect (window,
790 /// "key-press-event",
791 /// G_CALLBACK (on_key_press_event),
792 /// search_bar);
793 /// }
794 /// ```
795 /// ## `event`
796 /// a `GdkEvent` containing key press events
797 ///
798 /// # Returns
799 ///
800 /// `GDK_EVENT_STOP` if the key press event resulted
801 /// in text being entered in the search entry (and revealing
802 /// the search bar if necessary), `GDK_EVENT_PROPAGATE` otherwise.
803 #[doc(alias = "gtk_search_bar_handle_event")]
804 fn handle_event(&self, event: &gdk::Event) -> bool {
805 unsafe {
806 from_glib(ffi::gtk_search_bar_handle_event(
807 self.as_ref().to_glib_none().0,
808 mut_override(event.to_glib_none().0),
809 ))
810 }
811 }
812
813 /// Switches the search mode on or off.
814 /// ## `search_mode`
815 /// the new state of the search mode
816 #[doc(alias = "gtk_search_bar_set_search_mode")]
817 fn set_search_mode(&self, search_mode: bool) {
818 unsafe {
819 ffi::gtk_search_bar_set_search_mode(
820 self.as_ref().to_glib_none().0,
821 search_mode.into_glib(),
822 );
823 }
824 }
825
826 /// Shows or hides the close button. Applications that
827 /// already have a “search” toggle button should not show a close
828 /// button in their search bar, as it duplicates the role of the
829 /// toggle button.
830 /// ## `visible`
831 /// whether the close button will be shown or not
832 #[doc(alias = "gtk_search_bar_set_show_close_button")]
833 fn set_show_close_button(&self, visible: bool) {
834 unsafe {
835 ffi::gtk_search_bar_set_show_close_button(
836 self.as_ref().to_glib_none().0,
837 visible.into_glib(),
838 );
839 }
840 }
841
842 #[doc(alias = "search-mode-enabled")]
843 fn is_search_mode_enabled(&self) -> bool {
844 ObjectExt::property(self.as_ref(), "search-mode-enabled")
845 }
846
847 #[doc(alias = "search-mode-enabled")]
848 fn set_search_mode_enabled(&self, search_mode_enabled: bool) {
849 ObjectExt::set_property(self.as_ref(), "search-mode-enabled", search_mode_enabled)
850 }
851
852 #[doc(alias = "search-mode-enabled")]
853 fn connect_search_mode_enabled_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
854 unsafe extern "C" fn notify_search_mode_enabled_trampoline<
855 P: IsA<SearchBar>,
856 F: Fn(&P) + 'static,
857 >(
858 this: *mut ffi::GtkSearchBar,
859 _param_spec: glib::ffi::gpointer,
860 f: glib::ffi::gpointer,
861 ) {
862 let f: &F = &*(f as *const F);
863 f(SearchBar::from_glib_borrow(this).unsafe_cast_ref())
864 }
865 unsafe {
866 let f: Box_<F> = Box_::new(f);
867 connect_raw(
868 self.as_ptr() as *mut _,
869 b"notify::search-mode-enabled\0".as_ptr() as *const _,
870 Some(transmute::<_, unsafe extern "C" fn()>(
871 notify_search_mode_enabled_trampoline::<Self, F> as *const (),
872 )),
873 Box_::into_raw(f),
874 )
875 }
876 }
877
878 #[doc(alias = "show-close-button")]
879 fn connect_show_close_button_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
880 unsafe extern "C" fn notify_show_close_button_trampoline<
881 P: IsA<SearchBar>,
882 F: Fn(&P) + 'static,
883 >(
884 this: *mut ffi::GtkSearchBar,
885 _param_spec: glib::ffi::gpointer,
886 f: glib::ffi::gpointer,
887 ) {
888 let f: &F = &*(f as *const F);
889 f(SearchBar::from_glib_borrow(this).unsafe_cast_ref())
890 }
891 unsafe {
892 let f: Box_<F> = Box_::new(f);
893 connect_raw(
894 self.as_ptr() as *mut _,
895 b"notify::show-close-button\0".as_ptr() as *const _,
896 Some(transmute::<_, unsafe extern "C" fn()>(
897 notify_show_close_button_trampoline::<Self, F> as *const (),
898 )),
899 Box_::into_raw(f),
900 )
901 }
902 }
903}
904
905impl<O: IsA<SearchBar>> SearchBarExt for O {}
906
907impl fmt::Display for SearchBar {
908 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
909 f.write_str("SearchBar")
910 }
911}