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 /// Reveals a search entry when search is started.
18 ///
19 /// <picture>
20 /// <source srcset="search-bar-dark.png" media="(prefers-color-scheme: dark)">
21 /// <img alt="An example GtkSearchBar" src="search-bar.png">
22 /// </picture>
23 ///
24 /// It can also contain additional widgets, such as drop-down menus,
25 /// or buttons. The search bar would appear when a search is started
26 /// through typing on the keyboard, or the application’s search mode
27 /// is toggled on.
28 ///
29 /// For keyboard presses to start a search, the search bar must be told
30 /// of a widget to capture key events from through
31 /// [`set_key_capture_widget()`][Self::set_key_capture_widget()]. This widget will
32 /// typically be the top-level window, or a parent container of the
33 /// search bar. Common shortcuts such as Ctrl+F should be handled as an
34 /// application action, or through the menu items.
35 ///
36 /// You will also need to tell the search bar about which entry you
37 /// are using as your search entry using [`connect_entry()`][Self::connect_entry()].
38 ///
39 /// ## Creating a search bar
40 ///
41 /// The following example shows you how to create a more complex search
42 /// entry.
43 ///
44 /// [A simple example](https://gitlab.gnome.org/GNOME/gtk/tree/main/examples/search-bar.c)
45 ///
46 /// # Shortcuts and Gestures
47 ///
48 /// [`SearchBar`][crate::SearchBar] supports the following keyboard shortcuts:
49 ///
50 /// - <kbd>Escape</kbd> hides the search bar.
51 ///
52 /// # CSS nodes
53 ///
54 /// ```text
55 /// searchbar
56 /// ╰── revealer
57 /// ╰── box
58 /// ├── [child]
59 /// ╰── [button.close]
60 /// ```
61 ///
62 /// [`SearchBar`][crate::SearchBar] has a main CSS node with name searchbar. It has a child
63 /// node with name revealer that contains a node with name box. The box node
64 /// contains both the CSS node of the child widget as well as an optional button
65 /// node which gets the .close style class applied.
66 ///
67 /// # Accessibility
68 ///
69 /// [`SearchBar`][crate::SearchBar] uses the [enum@Gtk.AccessibleRole.search] role.
70 ///
71 /// ## Properties
72 ///
73 ///
74 /// #### `child`
75 /// The child widget.
76 ///
77 /// Readable | Writeable | Construct
78 ///
79 ///
80 /// #### `key-capture-widget`
81 /// The key capture widget.
82 ///
83 /// Readable | Writeable | Construct
84 ///
85 ///
86 /// #### `search-mode-enabled`
87 /// Whether the search mode is on and the search bar shown.
88 ///
89 /// Readable | Writeable
90 ///
91 ///
92 /// #### `show-close-button`
93 /// Whether to show the close button in the search bar.
94 ///
95 /// Readable | Writeable | Construct
96 /// <details><summary><h4>Widget</h4></summary>
97 ///
98 ///
99 /// #### `can-focus`
100 /// Whether the widget or any of its descendents can accept
101 /// the input focus.
102 ///
103 /// This property is meant to be set by widget implementations,
104 /// typically in their instance init function.
105 ///
106 /// Readable | Writeable
107 ///
108 ///
109 /// #### `can-target`
110 /// Whether the widget can receive pointer events.
111 ///
112 /// Readable | Writeable
113 ///
114 ///
115 /// #### `css-classes`
116 /// A list of css classes applied to this widget.
117 ///
118 /// Readable | Writeable
119 ///
120 ///
121 /// #### `css-name`
122 /// The name of this widget in the CSS tree.
123 ///
124 /// This property is meant to be set by widget implementations,
125 /// typically in their instance init function.
126 ///
127 /// Readable | Writeable | Construct Only
128 ///
129 ///
130 /// #### `cursor`
131 /// The cursor used by @widget.
132 ///
133 /// Readable | Writeable
134 ///
135 ///
136 /// #### `focus-on-click`
137 /// Whether the widget should grab focus when it is clicked with the mouse.
138 ///
139 /// This property is only relevant for widgets that can take focus.
140 ///
141 /// Readable | Writeable
142 ///
143 ///
144 /// #### `focusable`
145 /// Whether this widget itself will accept the input focus.
146 ///
147 /// Readable | Writeable
148 ///
149 ///
150 /// #### `halign`
151 /// How to distribute horizontal space if widget gets extra space.
152 ///
153 /// Readable | Writeable
154 ///
155 ///
156 /// #### `has-default`
157 /// Whether the widget is the default widget.
158 ///
159 /// Readable
160 ///
161 ///
162 /// #### `has-focus`
163 /// Whether the widget has the input focus.
164 ///
165 /// Readable
166 ///
167 ///
168 /// #### `has-tooltip`
169 /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
170 /// signal on @widget.
171 ///
172 /// A true value indicates that @widget can have a tooltip, in this case
173 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
174 /// determine whether it will provide a tooltip or not.
175 ///
176 /// Readable | Writeable
177 ///
178 ///
179 /// #### `height-request`
180 /// Overrides for height request of the widget.
181 ///
182 /// If this is -1, the natural request will be used.
183 ///
184 /// Readable | Writeable
185 ///
186 ///
187 /// #### `hexpand`
188 /// Whether to expand horizontally.
189 ///
190 /// Readable | Writeable
191 ///
192 ///
193 /// #### `hexpand-set`
194 /// Whether to use the `hexpand` property.
195 ///
196 /// Readable | Writeable
197 ///
198 ///
199 /// #### `layout-manager`
200 /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
201 /// the preferred size of the widget, and allocate its children.
202 ///
203 /// This property is meant to be set by widget implementations,
204 /// typically in their instance init function.
205 ///
206 /// Readable | Writeable
207 ///
208 ///
209 /// #### `limit-events`
210 /// Makes this widget act like a modal dialog, with respect to
211 /// event delivery.
212 ///
213 /// Global event controllers will not handle events with targets
214 /// inside the widget, unless they are set up to ignore propagation
215 /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
216 ///
217 /// Readable | Writeable
218 ///
219 ///
220 /// #### `margin-bottom`
221 /// Margin on bottom side of widget.
222 ///
223 /// This property adds margin outside of the widget's normal size
224 /// request, the margin will be added in addition to the size from
225 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
226 ///
227 /// Readable | Writeable
228 ///
229 ///
230 /// #### `margin-end`
231 /// Margin on end of widget, horizontally.
232 ///
233 /// This property supports left-to-right and right-to-left text
234 /// directions.
235 ///
236 /// This property adds margin outside of the widget's normal size
237 /// request, the margin will be added in addition to the size from
238 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
239 ///
240 /// Readable | Writeable
241 ///
242 ///
243 /// #### `margin-start`
244 /// Margin on start of widget, horizontally.
245 ///
246 /// This property supports left-to-right and right-to-left text
247 /// directions.
248 ///
249 /// This property adds margin outside of the widget's normal size
250 /// request, the margin will be added in addition to the size from
251 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
252 ///
253 /// Readable | Writeable
254 ///
255 ///
256 /// #### `margin-top`
257 /// Margin on top side of widget.
258 ///
259 /// This property adds margin outside of the widget's normal size
260 /// request, the margin will be added in addition to the size from
261 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
262 ///
263 /// Readable | Writeable
264 ///
265 ///
266 /// #### `name`
267 /// The name of the widget.
268 ///
269 /// Readable | Writeable
270 ///
271 ///
272 /// #### `opacity`
273 /// The requested opacity of the widget.
274 ///
275 /// Readable | Writeable
276 ///
277 ///
278 /// #### `overflow`
279 /// How content outside the widget's content area is treated.
280 ///
281 /// This property is meant to be set by widget implementations,
282 /// typically in their instance init function.
283 ///
284 /// Readable | Writeable
285 ///
286 ///
287 /// #### `parent`
288 /// The parent widget of this widget.
289 ///
290 /// Readable
291 ///
292 ///
293 /// #### `receives-default`
294 /// Whether the widget will receive the default action when it is focused.
295 ///
296 /// Readable | Writeable
297 ///
298 ///
299 /// #### `root`
300 /// The [`Root`][crate::Root] widget of the widget tree containing this widget.
301 ///
302 /// This will be `NULL` if the widget is not contained in a root widget.
303 ///
304 /// Readable
305 ///
306 ///
307 /// #### `scale-factor`
308 /// The scale factor of the widget.
309 ///
310 /// Readable
311 ///
312 ///
313 /// #### `sensitive`
314 /// Whether the widget responds to input.
315 ///
316 /// Readable | Writeable
317 ///
318 ///
319 /// #### `tooltip-markup`
320 /// Sets the text of tooltip to be the given string, which is marked up
321 /// with Pango markup.
322 ///
323 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
324 ///
325 /// This is a convenience property which will take care of getting the
326 /// tooltip shown if the given string is not `NULL`:
327 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
328 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
329 /// the default signal handler.
330 ///
331 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
332 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
333 ///
334 /// Readable | Writeable
335 ///
336 ///
337 /// #### `tooltip-text`
338 /// Sets the text of tooltip to be the given string.
339 ///
340 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
341 ///
342 /// This is a convenience property which will take care of getting the
343 /// tooltip shown if the given string is not `NULL`:
344 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
345 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
346 /// the default signal handler.
347 ///
348 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
349 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
350 ///
351 /// Readable | Writeable
352 ///
353 ///
354 /// #### `valign`
355 /// How to distribute vertical space if widget gets extra space.
356 ///
357 /// Readable | Writeable
358 ///
359 ///
360 /// #### `vexpand`
361 /// Whether to expand vertically.
362 ///
363 /// Readable | Writeable
364 ///
365 ///
366 /// #### `vexpand-set`
367 /// Whether to use the `vexpand` property.
368 ///
369 /// Readable | Writeable
370 ///
371 ///
372 /// #### `visible`
373 /// Whether the widget is visible.
374 ///
375 /// Readable | Writeable
376 ///
377 ///
378 /// #### `width-request`
379 /// Overrides for width request of the widget.
380 ///
381 /// If this is -1, the natural request will be used.
382 ///
383 /// Readable | Writeable
384 /// </details>
385 /// <details><summary><h4>Accessible</h4></summary>
386 ///
387 ///
388 /// #### `accessible-role`
389 /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
390 ///
391 /// The accessible role cannot be changed once set.
392 ///
393 /// Readable | Writeable
394 /// </details>
395 ///
396 /// # Implements
397 ///
398 /// [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`AccessibleExt`][trait@crate::prelude::AccessibleExt], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ConstraintTargetExt`][trait@crate::prelude::ConstraintTargetExt], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`AccessibleExtManual`][trait@crate::prelude::AccessibleExtManual]
399 #[doc(alias = "GtkSearchBar")]
400 pub struct SearchBar(Object<ffi::GtkSearchBar>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget;
401
402 match fn {
403 type_ => || ffi::gtk_search_bar_get_type(),
404 }
405}
406
407impl SearchBar {
408 /// Creates a [`SearchBar`][crate::SearchBar].
409 ///
410 /// You will need to tell it about which widget is going to be your text
411 /// entry using [`connect_entry()`][Self::connect_entry()].
412 ///
413 /// # Returns
414 ///
415 /// a new [`SearchBar`][crate::SearchBar]
416 #[doc(alias = "gtk_search_bar_new")]
417 pub fn new() -> SearchBar {
418 assert_initialized_main_thread!();
419 unsafe { Widget::from_glib_none(ffi::gtk_search_bar_new()).unsafe_cast() }
420 }
421
422 // rustdoc-stripper-ignore-next
423 /// Creates a new builder-pattern struct instance to construct [`SearchBar`] objects.
424 ///
425 /// This method returns an instance of [`SearchBarBuilder`](crate::builders::SearchBarBuilder) which can be used to create [`SearchBar`] objects.
426 pub fn builder() -> SearchBarBuilder {
427 SearchBarBuilder::new()
428 }
429
430 /// Connects the [`Editable`][crate::Editable] widget passed as the one to be used in
431 /// this search bar.
432 ///
433 /// The entry should be a descendant of the search bar. Calling this
434 /// function manually is only required if the entry isn’t the direct
435 /// child of the search bar (as in our main example).
436 /// ## `entry`
437 /// a [`Editable`][crate::Editable]
438 #[doc(alias = "gtk_search_bar_connect_entry")]
439 pub fn connect_entry(&self, entry: &impl IsA<Editable>) {
440 unsafe {
441 ffi::gtk_search_bar_connect_entry(
442 self.to_glib_none().0,
443 entry.as_ref().to_glib_none().0,
444 );
445 }
446 }
447
448 /// Gets the child widget of @self.
449 ///
450 /// # Returns
451 ///
452 /// the child widget of @self
453 #[doc(alias = "gtk_search_bar_get_child")]
454 #[doc(alias = "get_child")]
455 pub fn child(&self) -> Option<Widget> {
456 unsafe { from_glib_none(ffi::gtk_search_bar_get_child(self.to_glib_none().0)) }
457 }
458
459 /// Gets the widget that @self is capturing key events from.
460 ///
461 /// # Returns
462 ///
463 /// The key capture widget.
464 #[doc(alias = "gtk_search_bar_get_key_capture_widget")]
465 #[doc(alias = "get_key_capture_widget")]
466 #[doc(alias = "key-capture-widget")]
467 pub fn key_capture_widget(&self) -> Option<Widget> {
468 unsafe {
469 from_glib_none(ffi::gtk_search_bar_get_key_capture_widget(
470 self.to_glib_none().0,
471 ))
472 }
473 }
474
475 /// Returns whether the search mode is on or off.
476 ///
477 /// # Returns
478 ///
479 /// whether search mode is toggled on
480 #[doc(alias = "gtk_search_bar_get_search_mode")]
481 #[doc(alias = "get_search_mode")]
482 #[doc(alias = "search-mode-enabled")]
483 pub fn is_search_mode(&self) -> bool {
484 unsafe { from_glib(ffi::gtk_search_bar_get_search_mode(self.to_glib_none().0)) }
485 }
486
487 /// Returns whether the close button is shown.
488 ///
489 /// # Returns
490 ///
491 /// whether the close button is shown
492 #[doc(alias = "gtk_search_bar_get_show_close_button")]
493 #[doc(alias = "get_show_close_button")]
494 #[doc(alias = "show-close-button")]
495 pub fn shows_close_button(&self) -> bool {
496 unsafe {
497 from_glib(ffi::gtk_search_bar_get_show_close_button(
498 self.to_glib_none().0,
499 ))
500 }
501 }
502
503 /// Sets the child widget of @self.
504 /// ## `child`
505 /// the child widget
506 #[doc(alias = "gtk_search_bar_set_child")]
507 #[doc(alias = "child")]
508 pub fn set_child(&self, child: Option<&impl IsA<Widget>>) {
509 unsafe {
510 ffi::gtk_search_bar_set_child(
511 self.to_glib_none().0,
512 child.map(|p| p.as_ref()).to_glib_none().0,
513 );
514 }
515 }
516
517 /// Sets @widget as the widget that @self will capture key events
518 /// from.
519 ///
520 /// If key events are handled by the search bar, the bar will
521 /// be shown, and the entry populated with the entered text.
522 ///
523 /// Note that despite the name of this function, the events
524 /// are only 'captured' in the bubble phase, which means that
525 /// editable child widgets of @widget will receive text input
526 /// before it gets captured. If that is not desired, you can
527 /// capture and forward the events yourself with
528 /// [`EventControllerKey::forward()`][crate::EventControllerKey::forward()].
529 /// ## `widget`
530 /// a [`Widget`][crate::Widget]
531 #[doc(alias = "gtk_search_bar_set_key_capture_widget")]
532 #[doc(alias = "key-capture-widget")]
533 pub fn set_key_capture_widget(&self, widget: Option<&impl IsA<Widget>>) {
534 unsafe {
535 ffi::gtk_search_bar_set_key_capture_widget(
536 self.to_glib_none().0,
537 widget.map(|p| p.as_ref()).to_glib_none().0,
538 );
539 }
540 }
541
542 /// Switches the search mode on or off.
543 /// ## `search_mode`
544 /// the new state of the search mode
545 #[doc(alias = "gtk_search_bar_set_search_mode")]
546 #[doc(alias = "search-mode-enabled")]
547 pub fn set_search_mode(&self, search_mode: bool) {
548 unsafe {
549 ffi::gtk_search_bar_set_search_mode(self.to_glib_none().0, search_mode.into_glib());
550 }
551 }
552
553 /// Shows or hides the close button.
554 ///
555 /// Applications that already have a “search” toggle button should not
556 /// show a close button in their search bar, as it duplicates the role
557 /// of the toggle button.
558 /// ## `visible`
559 /// whether the close button will be shown or not
560 #[doc(alias = "gtk_search_bar_set_show_close_button")]
561 #[doc(alias = "show-close-button")]
562 pub fn set_show_close_button(&self, visible: bool) {
563 unsafe {
564 ffi::gtk_search_bar_set_show_close_button(self.to_glib_none().0, visible.into_glib());
565 }
566 }
567
568 #[doc(alias = "child")]
569 pub fn connect_child_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
570 unsafe extern "C" fn notify_child_trampoline<F: Fn(&SearchBar) + 'static>(
571 this: *mut ffi::GtkSearchBar,
572 _param_spec: glib::ffi::gpointer,
573 f: glib::ffi::gpointer,
574 ) {
575 let f: &F = &*(f as *const F);
576 f(&from_glib_borrow(this))
577 }
578 unsafe {
579 let f: Box_<F> = Box_::new(f);
580 connect_raw(
581 self.as_ptr() as *mut _,
582 c"notify::child".as_ptr() as *const _,
583 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
584 notify_child_trampoline::<F> as *const (),
585 )),
586 Box_::into_raw(f),
587 )
588 }
589 }
590
591 #[doc(alias = "key-capture-widget")]
592 pub fn connect_key_capture_widget_notify<F: Fn(&Self) + 'static>(
593 &self,
594 f: F,
595 ) -> SignalHandlerId {
596 unsafe extern "C" fn notify_key_capture_widget_trampoline<F: Fn(&SearchBar) + 'static>(
597 this: *mut ffi::GtkSearchBar,
598 _param_spec: glib::ffi::gpointer,
599 f: glib::ffi::gpointer,
600 ) {
601 let f: &F = &*(f as *const F);
602 f(&from_glib_borrow(this))
603 }
604 unsafe {
605 let f: Box_<F> = Box_::new(f);
606 connect_raw(
607 self.as_ptr() as *mut _,
608 c"notify::key-capture-widget".as_ptr() as *const _,
609 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
610 notify_key_capture_widget_trampoline::<F> as *const (),
611 )),
612 Box_::into_raw(f),
613 )
614 }
615 }
616
617 #[doc(alias = "search-mode-enabled")]
618 pub fn connect_search_mode_enabled_notify<F: Fn(&Self) + 'static>(
619 &self,
620 f: F,
621 ) -> SignalHandlerId {
622 unsafe extern "C" fn notify_search_mode_enabled_trampoline<F: Fn(&SearchBar) + 'static>(
623 this: *mut ffi::GtkSearchBar,
624 _param_spec: glib::ffi::gpointer,
625 f: glib::ffi::gpointer,
626 ) {
627 let f: &F = &*(f as *const F);
628 f(&from_glib_borrow(this))
629 }
630 unsafe {
631 let f: Box_<F> = Box_::new(f);
632 connect_raw(
633 self.as_ptr() as *mut _,
634 c"notify::search-mode-enabled".as_ptr() as *const _,
635 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
636 notify_search_mode_enabled_trampoline::<F> as *const (),
637 )),
638 Box_::into_raw(f),
639 )
640 }
641 }
642
643 #[doc(alias = "show-close-button")]
644 pub fn connect_show_close_button_notify<F: Fn(&Self) + 'static>(
645 &self,
646 f: F,
647 ) -> SignalHandlerId {
648 unsafe extern "C" fn notify_show_close_button_trampoline<F: Fn(&SearchBar) + 'static>(
649 this: *mut ffi::GtkSearchBar,
650 _param_spec: glib::ffi::gpointer,
651 f: glib::ffi::gpointer,
652 ) {
653 let f: &F = &*(f as *const F);
654 f(&from_glib_borrow(this))
655 }
656 unsafe {
657 let f: Box_<F> = Box_::new(f);
658 connect_raw(
659 self.as_ptr() as *mut _,
660 c"notify::show-close-button".as_ptr() as *const _,
661 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
662 notify_show_close_button_trampoline::<F> as *const (),
663 )),
664 Box_::into_raw(f),
665 )
666 }
667 }
668}
669
670impl Default for SearchBar {
671 fn default() -> Self {
672 Self::new()
673 }
674}
675
676// rustdoc-stripper-ignore-next
677/// A [builder-pattern] type to construct [`SearchBar`] objects.
678///
679/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
680#[must_use = "The builder must be built to be used"]
681pub struct SearchBarBuilder {
682 builder: glib::object::ObjectBuilder<'static, SearchBar>,
683}
684
685impl SearchBarBuilder {
686 fn new() -> Self {
687 Self {
688 builder: glib::object::Object::builder(),
689 }
690 }
691
692 /// The child widget.
693 pub fn child(self, child: &impl IsA<Widget>) -> Self {
694 Self {
695 builder: self.builder.property("child", child.clone().upcast()),
696 }
697 }
698
699 /// The key capture widget.
700 pub fn key_capture_widget(self, key_capture_widget: &impl IsA<Widget>) -> Self {
701 Self {
702 builder: self
703 .builder
704 .property("key-capture-widget", key_capture_widget.clone().upcast()),
705 }
706 }
707
708 /// Whether the search mode is on and the search bar shown.
709 pub fn search_mode_enabled(self, search_mode_enabled: bool) -> Self {
710 Self {
711 builder: self
712 .builder
713 .property("search-mode-enabled", search_mode_enabled),
714 }
715 }
716
717 /// Whether to show the close button in the search bar.
718 pub fn show_close_button(self, show_close_button: bool) -> Self {
719 Self {
720 builder: self
721 .builder
722 .property("show-close-button", show_close_button),
723 }
724 }
725
726 /// Whether the widget or any of its descendents can accept
727 /// the input focus.
728 ///
729 /// This property is meant to be set by widget implementations,
730 /// typically in their instance init function.
731 pub fn can_focus(self, can_focus: bool) -> Self {
732 Self {
733 builder: self.builder.property("can-focus", can_focus),
734 }
735 }
736
737 /// Whether the widget can receive pointer events.
738 pub fn can_target(self, can_target: bool) -> Self {
739 Self {
740 builder: self.builder.property("can-target", can_target),
741 }
742 }
743
744 /// A list of css classes applied to this widget.
745 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
746 Self {
747 builder: self.builder.property("css-classes", css_classes.into()),
748 }
749 }
750
751 /// The name of this widget in the CSS tree.
752 ///
753 /// This property is meant to be set by widget implementations,
754 /// typically in their instance init function.
755 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
756 Self {
757 builder: self.builder.property("css-name", css_name.into()),
758 }
759 }
760
761 /// The cursor used by @widget.
762 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
763 Self {
764 builder: self.builder.property("cursor", cursor.clone()),
765 }
766 }
767
768 /// Whether the widget should grab focus when it is clicked with the mouse.
769 ///
770 /// This property is only relevant for widgets that can take focus.
771 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
772 Self {
773 builder: self.builder.property("focus-on-click", focus_on_click),
774 }
775 }
776
777 /// Whether this widget itself will accept the input focus.
778 pub fn focusable(self, focusable: bool) -> Self {
779 Self {
780 builder: self.builder.property("focusable", focusable),
781 }
782 }
783
784 /// How to distribute horizontal space if widget gets extra space.
785 pub fn halign(self, halign: Align) -> Self {
786 Self {
787 builder: self.builder.property("halign", halign),
788 }
789 }
790
791 /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
792 /// signal on @widget.
793 ///
794 /// A true value indicates that @widget can have a tooltip, in this case
795 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
796 /// determine whether it will provide a tooltip or not.
797 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
798 Self {
799 builder: self.builder.property("has-tooltip", has_tooltip),
800 }
801 }
802
803 /// Overrides for height request of the widget.
804 ///
805 /// If this is -1, the natural request will be used.
806 pub fn height_request(self, height_request: i32) -> Self {
807 Self {
808 builder: self.builder.property("height-request", height_request),
809 }
810 }
811
812 /// Whether to expand horizontally.
813 pub fn hexpand(self, hexpand: bool) -> Self {
814 Self {
815 builder: self.builder.property("hexpand", hexpand),
816 }
817 }
818
819 /// Whether to use the `hexpand` property.
820 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
821 Self {
822 builder: self.builder.property("hexpand-set", hexpand_set),
823 }
824 }
825
826 /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
827 /// the preferred size of the widget, and allocate its children.
828 ///
829 /// This property is meant to be set by widget implementations,
830 /// typically in their instance init function.
831 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
832 Self {
833 builder: self
834 .builder
835 .property("layout-manager", layout_manager.clone().upcast()),
836 }
837 }
838
839 /// Makes this widget act like a modal dialog, with respect to
840 /// event delivery.
841 ///
842 /// Global event controllers will not handle events with targets
843 /// inside the widget, unless they are set up to ignore propagation
844 /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
845 #[cfg(feature = "v4_18")]
846 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
847 pub fn limit_events(self, limit_events: bool) -> Self {
848 Self {
849 builder: self.builder.property("limit-events", limit_events),
850 }
851 }
852
853 /// Margin on bottom side of widget.
854 ///
855 /// This property adds margin outside of the widget's normal size
856 /// request, the margin will be added in addition to the size from
857 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
858 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
859 Self {
860 builder: self.builder.property("margin-bottom", margin_bottom),
861 }
862 }
863
864 /// Margin on end of widget, horizontally.
865 ///
866 /// This property supports left-to-right and right-to-left text
867 /// directions.
868 ///
869 /// This property adds margin outside of the widget's normal size
870 /// request, the margin will be added in addition to the size from
871 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
872 pub fn margin_end(self, margin_end: i32) -> Self {
873 Self {
874 builder: self.builder.property("margin-end", margin_end),
875 }
876 }
877
878 /// Margin on start of widget, horizontally.
879 ///
880 /// This property supports left-to-right and right-to-left text
881 /// directions.
882 ///
883 /// This property adds margin outside of the widget's normal size
884 /// request, the margin will be added in addition to the size from
885 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
886 pub fn margin_start(self, margin_start: i32) -> Self {
887 Self {
888 builder: self.builder.property("margin-start", margin_start),
889 }
890 }
891
892 /// Margin on top side of widget.
893 ///
894 /// This property adds margin outside of the widget's normal size
895 /// request, the margin will be added in addition to the size from
896 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
897 pub fn margin_top(self, margin_top: i32) -> Self {
898 Self {
899 builder: self.builder.property("margin-top", margin_top),
900 }
901 }
902
903 /// The name of the widget.
904 pub fn name(self, name: impl Into<glib::GString>) -> Self {
905 Self {
906 builder: self.builder.property("name", name.into()),
907 }
908 }
909
910 /// The requested opacity of the widget.
911 pub fn opacity(self, opacity: f64) -> Self {
912 Self {
913 builder: self.builder.property("opacity", opacity),
914 }
915 }
916
917 /// How content outside the widget's content area is treated.
918 ///
919 /// This property is meant to be set by widget implementations,
920 /// typically in their instance init function.
921 pub fn overflow(self, overflow: Overflow) -> Self {
922 Self {
923 builder: self.builder.property("overflow", overflow),
924 }
925 }
926
927 /// Whether the widget will receive the default action when it is focused.
928 pub fn receives_default(self, receives_default: bool) -> Self {
929 Self {
930 builder: self.builder.property("receives-default", receives_default),
931 }
932 }
933
934 /// Whether the widget responds to input.
935 pub fn sensitive(self, sensitive: bool) -> Self {
936 Self {
937 builder: self.builder.property("sensitive", sensitive),
938 }
939 }
940
941 /// Sets the text of tooltip to be the given string, which is marked up
942 /// with Pango markup.
943 ///
944 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
945 ///
946 /// This is a convenience property which will take care of getting the
947 /// tooltip shown if the given string is not `NULL`:
948 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
949 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
950 /// the default signal handler.
951 ///
952 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
953 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
954 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
955 Self {
956 builder: self
957 .builder
958 .property("tooltip-markup", tooltip_markup.into()),
959 }
960 }
961
962 /// Sets the text of tooltip to be the given string.
963 ///
964 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
965 ///
966 /// This is a convenience property which will take care of getting the
967 /// tooltip shown if the given string is not `NULL`:
968 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
969 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
970 /// the default signal handler.
971 ///
972 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
973 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
974 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
975 Self {
976 builder: self.builder.property("tooltip-text", tooltip_text.into()),
977 }
978 }
979
980 /// How to distribute vertical space if widget gets extra space.
981 pub fn valign(self, valign: Align) -> Self {
982 Self {
983 builder: self.builder.property("valign", valign),
984 }
985 }
986
987 /// Whether to expand vertically.
988 pub fn vexpand(self, vexpand: bool) -> Self {
989 Self {
990 builder: self.builder.property("vexpand", vexpand),
991 }
992 }
993
994 /// Whether to use the `vexpand` property.
995 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
996 Self {
997 builder: self.builder.property("vexpand-set", vexpand_set),
998 }
999 }
1000
1001 /// Whether the widget is visible.
1002 pub fn visible(self, visible: bool) -> Self {
1003 Self {
1004 builder: self.builder.property("visible", visible),
1005 }
1006 }
1007
1008 /// Overrides for width request of the widget.
1009 ///
1010 /// If this is -1, the natural request will be used.
1011 pub fn width_request(self, width_request: i32) -> Self {
1012 Self {
1013 builder: self.builder.property("width-request", width_request),
1014 }
1015 }
1016
1017 /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
1018 ///
1019 /// The accessible role cannot be changed once set.
1020 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
1021 Self {
1022 builder: self.builder.property("accessible-role", accessible_role),
1023 }
1024 }
1025
1026 // rustdoc-stripper-ignore-next
1027 /// Build the [`SearchBar`].
1028 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
1029 pub fn build(self) -> SearchBar {
1030 assert_initialized_main_thread!();
1031 self.builder.build()
1032 }
1033}