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