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