Skip to main content

gtk4/auto/
separator.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
5#[cfg(feature = "v4_10")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
7use crate::Accessible;
8use crate::{
9    AccessibleRole, Align, Buildable, ConstraintTarget, LayoutManager, Orientable, Orientation,
10    Overflow, Widget, ffi,
11};
12use glib::{prelude::*, translate::*};
13
14#[cfg(feature = "v4_10")]
15#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
16glib::wrapper! {
17    /// Draws a horizontal or vertical line to separate other widgets.
18    ///
19    /// <picture>
20    ///   <source srcset="separator-dark.png" media="(prefers-color-scheme: dark)">
21    ///   <img alt="An example GtkSeparator" src="separator.png">
22    /// </picture>
23    ///
24    /// A [`Separator`][crate::Separator] can be used to group the widgets within a window.
25    /// It displays a line with a shadow to make it appear sunken into the
26    /// interface.
27    ///
28    /// # CSS nodes
29    ///
30    /// [`Separator`][crate::Separator] has a single CSS node with name separator. The node
31    /// gets one of the .horizontal or .vertical style classes.
32    ///
33    /// # Accessibility
34    ///
35    /// [`Separator`][crate::Separator] uses the [enum@Gtk.AccessibleRole.separator] role.
36    ///
37    /// # Implements
38    ///
39    /// [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`AccessibleExt`][trait@crate::prelude::AccessibleExt], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ConstraintTargetExt`][trait@crate::prelude::ConstraintTargetExt], [`OrientableExt`][trait@crate::prelude::OrientableExt], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`AccessibleExtManual`][trait@crate::prelude::AccessibleExtManual]
40    #[doc(alias = "GtkSeparator")]
41    pub struct Separator(Object<ffi::GtkSeparator>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget, Orientable;
42
43    match fn {
44        type_ => || ffi::gtk_separator_get_type(),
45    }
46}
47
48#[cfg(not(feature = "v4_10"))]
49glib::wrapper! {
50    #[doc(alias = "GtkSeparator")]
51    pub struct Separator(Object<ffi::GtkSeparator>) @extends Widget, @implements Buildable, ConstraintTarget, Orientable;
52
53    match fn {
54        type_ => || ffi::gtk_separator_get_type(),
55    }
56}
57
58impl Separator {
59    /// Creates a new [`Separator`][crate::Separator] with the given orientation.
60    /// ## `orientation`
61    /// the separator’s orientation.
62    ///
63    /// # Returns
64    ///
65    /// a new [`Separator`][crate::Separator].
66    #[doc(alias = "gtk_separator_new")]
67    pub fn new(orientation: Orientation) -> Separator {
68        assert_initialized_main_thread!();
69        unsafe {
70            Widget::from_glib_none(ffi::gtk_separator_new(orientation.into_glib())).unsafe_cast()
71        }
72    }
73
74    // rustdoc-stripper-ignore-next
75    /// Creates a new builder-pattern struct instance to construct [`Separator`] objects.
76    ///
77    /// This method returns an instance of [`SeparatorBuilder`](crate::builders::SeparatorBuilder) which can be used to create [`Separator`] objects.
78    pub fn builder() -> SeparatorBuilder {
79        SeparatorBuilder::new()
80    }
81}
82
83impl Default for Separator {
84    fn default() -> Self {
85        glib::object::Object::new::<Self>()
86    }
87}
88
89// rustdoc-stripper-ignore-next
90/// A [builder-pattern] type to construct [`Separator`] objects.
91///
92/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
93#[must_use = "The builder must be built to be used"]
94pub struct SeparatorBuilder {
95    builder: glib::object::ObjectBuilder<'static, Separator>,
96}
97
98impl SeparatorBuilder {
99    fn new() -> Self {
100        Self {
101            builder: glib::object::Object::builder(),
102        }
103    }
104
105    /// Whether the widget or any of its descendents can accept
106    /// the input focus.
107    ///
108    /// This property is meant to be set by widget implementations,
109    /// typically in their instance init function.
110    pub fn can_focus(self, can_focus: bool) -> Self {
111        Self {
112            builder: self.builder.property("can-focus", can_focus),
113        }
114    }
115
116    /// Whether the widget can receive pointer events.
117    pub fn can_target(self, can_target: bool) -> Self {
118        Self {
119            builder: self.builder.property("can-target", can_target),
120        }
121    }
122
123    /// A list of css classes applied to this widget.
124    pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
125        Self {
126            builder: self.builder.property("css-classes", css_classes.into()),
127        }
128    }
129
130    /// The name of this widget in the CSS tree.
131    ///
132    /// This property is meant to be set by widget implementations,
133    /// typically in their instance init function.
134    pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
135        Self {
136            builder: self.builder.property("css-name", css_name.into()),
137        }
138    }
139
140    /// The cursor used by @widget.
141    pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
142        Self {
143            builder: self.builder.property("cursor", cursor.clone()),
144        }
145    }
146
147    /// Whether the widget should grab focus when it is clicked with the mouse.
148    ///
149    /// This property is only relevant for widgets that can take focus.
150    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
151        Self {
152            builder: self.builder.property("focus-on-click", focus_on_click),
153        }
154    }
155
156    /// Whether this widget itself will accept the input focus.
157    pub fn focusable(self, focusable: bool) -> Self {
158        Self {
159            builder: self.builder.property("focusable", focusable),
160        }
161    }
162
163    /// How to distribute horizontal space if widget gets extra space.
164    pub fn halign(self, halign: Align) -> Self {
165        Self {
166            builder: self.builder.property("halign", halign),
167        }
168    }
169
170    /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
171    /// signal on @widget.
172    ///
173    /// A true value indicates that @widget can have a tooltip, in this case
174    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
175    /// determine whether it will provide a tooltip or not.
176    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
177        Self {
178            builder: self.builder.property("has-tooltip", has_tooltip),
179        }
180    }
181
182    /// Overrides for height request of the widget.
183    ///
184    /// If this is -1, the natural request will be used.
185    pub fn height_request(self, height_request: i32) -> Self {
186        Self {
187            builder: self.builder.property("height-request", height_request),
188        }
189    }
190
191    /// Whether to expand horizontally.
192    pub fn hexpand(self, hexpand: bool) -> Self {
193        Self {
194            builder: self.builder.property("hexpand", hexpand),
195        }
196    }
197
198    /// Whether to use the `hexpand` property.
199    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
200        Self {
201            builder: self.builder.property("hexpand-set", hexpand_set),
202        }
203    }
204
205    /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
206    /// the preferred size of the widget, and allocate its children.
207    ///
208    /// This property is meant to be set by widget implementations,
209    /// typically in their instance init function.
210    pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
211        Self {
212            builder: self
213                .builder
214                .property("layout-manager", layout_manager.clone().upcast()),
215        }
216    }
217
218    /// Makes this widget act like a modal dialog, with respect to
219    /// event delivery.
220    ///
221    /// Global event controllers will not handle events with targets
222    /// inside the widget, unless they are set up to ignore propagation
223    /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
224    #[cfg(feature = "v4_18")]
225    #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
226    pub fn limit_events(self, limit_events: bool) -> Self {
227        Self {
228            builder: self.builder.property("limit-events", limit_events),
229        }
230    }
231
232    /// Margin on bottom side of widget.
233    ///
234    /// This property adds margin outside of the widget's normal size
235    /// request, the margin will be added in addition to the size from
236    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
237    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
238        Self {
239            builder: self.builder.property("margin-bottom", margin_bottom),
240        }
241    }
242
243    /// Margin on end of widget, horizontally.
244    ///
245    /// This property supports left-to-right and right-to-left text
246    /// directions.
247    ///
248    /// This property adds margin outside of the widget's normal size
249    /// request, the margin will be added in addition to the size from
250    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
251    pub fn margin_end(self, margin_end: i32) -> Self {
252        Self {
253            builder: self.builder.property("margin-end", margin_end),
254        }
255    }
256
257    /// Margin on start of widget, horizontally.
258    ///
259    /// This property supports left-to-right and right-to-left text
260    /// directions.
261    ///
262    /// This property adds margin outside of the widget's normal size
263    /// request, the margin will be added in addition to the size from
264    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
265    pub fn margin_start(self, margin_start: i32) -> Self {
266        Self {
267            builder: self.builder.property("margin-start", margin_start),
268        }
269    }
270
271    /// Margin on top side of widget.
272    ///
273    /// This property adds margin outside of the widget's normal size
274    /// request, the margin will be added in addition to the size from
275    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
276    pub fn margin_top(self, margin_top: i32) -> Self {
277        Self {
278            builder: self.builder.property("margin-top", margin_top),
279        }
280    }
281
282    /// The name of the widget.
283    pub fn name(self, name: impl Into<glib::GString>) -> Self {
284        Self {
285            builder: self.builder.property("name", name.into()),
286        }
287    }
288
289    /// The requested opacity of the widget.
290    pub fn opacity(self, opacity: f64) -> Self {
291        Self {
292            builder: self.builder.property("opacity", opacity),
293        }
294    }
295
296    /// How content outside the widget's content area is treated.
297    ///
298    /// This property is meant to be set by widget implementations,
299    /// typically in their instance init function.
300    pub fn overflow(self, overflow: Overflow) -> Self {
301        Self {
302            builder: self.builder.property("overflow", overflow),
303        }
304    }
305
306    /// Whether the widget will receive the default action when it is focused.
307    pub fn receives_default(self, receives_default: bool) -> Self {
308        Self {
309            builder: self.builder.property("receives-default", receives_default),
310        }
311    }
312
313    /// Whether the widget responds to input.
314    pub fn sensitive(self, sensitive: bool) -> Self {
315        Self {
316            builder: self.builder.property("sensitive", sensitive),
317        }
318    }
319
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    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
334        Self {
335            builder: self
336                .builder
337                .property("tooltip-markup", tooltip_markup.into()),
338        }
339    }
340
341    /// Sets the text of tooltip to be the given string.
342    ///
343    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
344    ///
345    /// This is a convenience property which will take care of getting the
346    /// tooltip shown if the given string is not `NULL`:
347    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
348    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
349    /// the default signal handler.
350    ///
351    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
352    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
353    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
354        Self {
355            builder: self.builder.property("tooltip-text", tooltip_text.into()),
356        }
357    }
358
359    /// How to distribute vertical space if widget gets extra space.
360    pub fn valign(self, valign: Align) -> Self {
361        Self {
362            builder: self.builder.property("valign", valign),
363        }
364    }
365
366    /// Whether to expand vertically.
367    pub fn vexpand(self, vexpand: bool) -> Self {
368        Self {
369            builder: self.builder.property("vexpand", vexpand),
370        }
371    }
372
373    /// Whether to use the `vexpand` property.
374    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
375        Self {
376            builder: self.builder.property("vexpand-set", vexpand_set),
377        }
378    }
379
380    /// Whether the widget is visible.
381    pub fn visible(self, visible: bool) -> Self {
382        Self {
383            builder: self.builder.property("visible", visible),
384        }
385    }
386
387    /// Overrides for width request of the widget.
388    ///
389    /// If this is -1, the natural request will be used.
390    pub fn width_request(self, width_request: i32) -> Self {
391        Self {
392            builder: self.builder.property("width-request", width_request),
393        }
394    }
395
396    /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
397    ///
398    /// The accessible role cannot be changed once set.
399    pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
400        Self {
401            builder: self.builder.property("accessible-role", accessible_role),
402        }
403    }
404
405    /// The orientation of the orientable.
406    pub fn orientation(self, orientation: Orientation) -> Self {
407        Self {
408            builder: self.builder.property("orientation", orientation),
409        }
410    }
411
412    // rustdoc-stripper-ignore-next
413    /// Build the [`Separator`].
414    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
415    pub fn build(self) -> Separator {
416        assert_initialized_main_thread!();
417        self.builder.build()
418    }
419}