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, ffi};
6use glib::{
7 prelude::*,
8 signal::{SignalHandlerId, connect_raw},
9 translate::*,
10};
11use std::boxed::Box as Box_;
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 | Writable
43 ///
44 ///
45 /// #### `show-close-button`
46 /// Readable | Writable | Construct
47 /// <details><summary><h4>Container</h4></summary>
48 ///
49 ///
50 /// #### `border-width`
51 /// Readable | Writable
52 ///
53 ///
54 /// #### `child`
55 /// Writable
56 ///
57 ///
58 /// #### `resize-mode`
59 /// Readable | Writable
60 /// </details>
61 /// <details><summary><h4>Widget</h4></summary>
62 ///
63 ///
64 /// #### `app-paintable`
65 /// Readable | Writable
66 ///
67 ///
68 /// #### `can-default`
69 /// Readable | Writable
70 ///
71 ///
72 /// #### `can-focus`
73 /// Readable | Writable
74 ///
75 ///
76 /// #### `composite-child`
77 /// Readable
78 ///
79 ///
80 /// #### `double-buffered`
81 /// Whether the widget is double buffered.
82 ///
83 /// Readable | Writable
84 ///
85 ///
86 /// #### `events`
87 /// Readable | Writable
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 | Writable
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 | Writable
105 ///
106 ///
107 /// #### `halign`
108 /// How to distribute horizontal space if widget gets extra space, see [`Align`][crate::Align]
109 ///
110 /// Readable | Writable
111 ///
112 ///
113 /// #### `has-default`
114 /// Readable | Writable
115 ///
116 ///
117 /// #### `has-focus`
118 /// Readable | Writable
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 | Writable
133 ///
134 ///
135 /// #### `height-request`
136 /// Readable | Writable
137 ///
138 ///
139 /// #### `hexpand`
140 /// Whether to expand horizontally. See [`WidgetExt::set_hexpand()`][crate::prelude::WidgetExt::set_hexpand()].
141 ///
142 /// Readable | Writable
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 | Writable
149 ///
150 ///
151 /// #### `is-focus`
152 /// Readable | Writable
153 ///
154 ///
155 /// #### `margin`
156 /// Sets all four sides' margin at once. If read, returns max
157 /// margin on any side.
158 ///
159 /// Readable | Writable
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 | Writable
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 | Writable
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 | Writable
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 | Writable
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 | Writable
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 | Writable
222 ///
223 ///
224 /// #### `name`
225 /// Readable | Writable
226 ///
227 ///
228 /// #### `no-show-all`
229 /// Readable | Writable
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 | Writable
239 ///
240 ///
241 /// #### `parent`
242 /// Readable | Writable
243 ///
244 ///
245 /// #### `receives-default`
246 /// Readable | Writable
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 | Writable
258 ///
259 ///
260 /// #### `style`
261 /// The style of the widget, which contains information about how it will look (colors, etc).
262 ///
263 /// Readable | Writable
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 | Writable
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 | Writable
296 ///
297 ///
298 /// #### `valign`
299 /// How to distribute vertical space if widget gets extra space, see [`Align`][crate::Align]
300 ///
301 /// Readable | Writable
302 ///
303 ///
304 /// #### `vexpand`
305 /// Whether to expand vertically. See [`WidgetExt::set_vexpand()`][crate::prelude::WidgetExt::set_vexpand()].
306 ///
307 /// Readable | Writable
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 | Writable
314 ///
315 ///
316 /// #### `visible`
317 /// Readable | Writable
318 ///
319 ///
320 /// #### `width-request`
321 /// Readable | Writable
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 assert_initialized_main_thread!();
693 self.builder.build()
694 }
695}
696
697/// Trait containing all [`struct@SearchBar`] methods.
698///
699/// # Implementors
700///
701/// [`SearchBar`][struct@crate::SearchBar]
702pub trait SearchBarExt: IsA<SearchBar> + 'static {
703 /// Connects the [`Entry`][crate::Entry] widget passed as the one to be used in
704 /// this search bar. The entry should be a descendant of the search bar.
705 /// This is only required if the entry isn’t the direct child of the
706 /// search bar (as in our main example).
707 /// ## `entry`
708 /// a [`Entry`][crate::Entry]
709 #[doc(alias = "gtk_search_bar_connect_entry")]
710 fn connect_entry(&self, entry: &impl IsA<Entry>) {
711 unsafe {
712 ffi::gtk_search_bar_connect_entry(
713 self.as_ref().to_glib_none().0,
714 entry.as_ref().to_glib_none().0,
715 );
716 }
717 }
718
719 /// Returns whether the search mode is on or off.
720 ///
721 /// # Returns
722 ///
723 /// whether search mode is toggled on
724 #[doc(alias = "gtk_search_bar_get_search_mode")]
725 #[doc(alias = "get_search_mode")]
726 fn is_search_mode(&self) -> bool {
727 unsafe {
728 from_glib(ffi::gtk_search_bar_get_search_mode(
729 self.as_ref().to_glib_none().0,
730 ))
731 }
732 }
733
734 /// Returns whether the close button is shown.
735 ///
736 /// # Returns
737 ///
738 /// whether the close button is shown
739 #[doc(alias = "gtk_search_bar_get_show_close_button")]
740 #[doc(alias = "get_show_close_button")]
741 #[doc(alias = "show-close-button")]
742 fn shows_close_button(&self) -> bool {
743 unsafe {
744 from_glib(ffi::gtk_search_bar_get_show_close_button(
745 self.as_ref().to_glib_none().0,
746 ))
747 }
748 }
749
750 ///
751 /// static gboolean
752 /// on_key_press_event (GtkWidget *widget,
753 /// GdkEvent *event,
754 /// gpointer user_data)
755 /// {
756 /// GtkSearchBar *bar = GTK_SEARCH_BAR (user_data);
757 /// return gtk_search_bar_handle_event (bar, event);
758 /// }
759 ///
760 /// static void
761 /// create_toplevel (void)
762 /// {
763 /// GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
764 /// GtkWindow *search_bar = gtk_search_bar_new ();
765 ///
766 /// // Add more widgets to the window...
767 ///
768 /// g_signal_connect (window,
769 /// "key-press-event",
770 /// G_CALLBACK (on_key_press_event),
771 /// search_bar);
772 /// }
773 /// ]|
774 /// ## `event`
775 /// a `GdkEvent` containing key press events
776 ///
777 /// # Returns
778 ///
779 /// `GDK_EVENT_STOP` if the key press event resulted
780 /// in text being entered in the search entry (and revealing
781 /// the search bar if necessary), `GDK_EVENT_PROPAGATE` otherwise.
782 #[doc(alias = "gtk_search_bar_handle_event")]
783 fn handle_event(&self, event: &gdk::Event) -> bool {
784 unsafe {
785 from_glib(ffi::gtk_search_bar_handle_event(
786 self.as_ref().to_glib_none().0,
787 mut_override(event.to_glib_none().0),
788 ))
789 }
790 }
791
792 /// Switches the search mode on or off.
793 /// ## `search_mode`
794 /// the new state of the search mode
795 #[doc(alias = "gtk_search_bar_set_search_mode")]
796 fn set_search_mode(&self, search_mode: bool) {
797 unsafe {
798 ffi::gtk_search_bar_set_search_mode(
799 self.as_ref().to_glib_none().0,
800 search_mode.into_glib(),
801 );
802 }
803 }
804
805 /// Shows or hides the close button. Applications that
806 /// already have a “search” toggle button should not show a close
807 /// button in their search bar, as it duplicates the role of the
808 /// toggle button.
809 /// ## `visible`
810 /// whether the close button will be shown or not
811 #[doc(alias = "gtk_search_bar_set_show_close_button")]
812 #[doc(alias = "show-close-button")]
813 fn set_show_close_button(&self, visible: bool) {
814 unsafe {
815 ffi::gtk_search_bar_set_show_close_button(
816 self.as_ref().to_glib_none().0,
817 visible.into_glib(),
818 );
819 }
820 }
821
822 #[doc(alias = "search-mode-enabled")]
823 fn is_search_mode_enabled(&self) -> bool {
824 ObjectExt::property(self.as_ref(), "search-mode-enabled")
825 }
826
827 #[doc(alias = "search-mode-enabled")]
828 fn set_search_mode_enabled(&self, search_mode_enabled: bool) {
829 ObjectExt::set_property(self.as_ref(), "search-mode-enabled", search_mode_enabled)
830 }
831
832 #[doc(alias = "search-mode-enabled")]
833 fn connect_search_mode_enabled_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
834 unsafe extern "C" fn notify_search_mode_enabled_trampoline<
835 P: IsA<SearchBar>,
836 F: Fn(&P) + 'static,
837 >(
838 this: *mut ffi::GtkSearchBar,
839 _param_spec: glib::ffi::gpointer,
840 f: glib::ffi::gpointer,
841 ) {
842 unsafe {
843 let f: &F = &*(f as *const F);
844 f(SearchBar::from_glib_borrow(this).unsafe_cast_ref())
845 }
846 }
847 unsafe {
848 let f: Box_<F> = Box_::new(f);
849 connect_raw(
850 self.as_ptr() as *mut _,
851 c"notify::search-mode-enabled".as_ptr(),
852 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
853 notify_search_mode_enabled_trampoline::<Self, F> as *const (),
854 )),
855 Box_::into_raw(f),
856 )
857 }
858 }
859
860 #[doc(alias = "show-close-button")]
861 fn connect_show_close_button_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
862 unsafe extern "C" fn notify_show_close_button_trampoline<
863 P: IsA<SearchBar>,
864 F: Fn(&P) + 'static,
865 >(
866 this: *mut ffi::GtkSearchBar,
867 _param_spec: glib::ffi::gpointer,
868 f: glib::ffi::gpointer,
869 ) {
870 unsafe {
871 let f: &F = &*(f as *const F);
872 f(SearchBar::from_glib_borrow(this).unsafe_cast_ref())
873 }
874 }
875 unsafe {
876 let f: Box_<F> = Box_::new(f);
877 connect_raw(
878 self.as_ptr() as *mut _,
879 c"notify::show-close-button".as_ptr(),
880 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
881 notify_show_close_button_trampoline::<Self, F> as *const (),
882 )),
883 Box_::into_raw(f),
884 )
885 }
886 }
887}
888
889impl<O: IsA<SearchBar>> SearchBarExt for O {}