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