gsk4/auto/
stroke.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::{ffi, LineCap, LineJoin};
use glib::translate::*;

glib::wrapper! {
    /// A [`Stroke`][crate::Stroke] struct collects the parameters that influence
    /// the operation of stroking a path.
    #[derive(Debug, PartialOrd, Ord, Hash)]
    pub struct Stroke(Boxed<ffi::GskStroke>);

    match fn {
        copy => |ptr| ffi::gsk_stroke_copy(ptr),
        free => |ptr| ffi::gsk_stroke_free(ptr),
        type_ => || ffi::gsk_stroke_get_type(),
    }
}

impl Stroke {
    /// Creates a new [`Stroke`][crate::Stroke] with the given @line_width.
    /// ## `line_width`
    /// line width of the stroke. Must be > 0
    ///
    /// # Returns
    ///
    /// a new [`Stroke`][crate::Stroke]
    #[doc(alias = "gsk_stroke_new")]
    pub fn new(line_width: f32) -> Stroke {
        assert_initialized_main_thread!();
        unsafe { from_glib_full(ffi::gsk_stroke_new(line_width)) }
    }

    /// Gets the dash array in use or `NULL` if dashing is disabled.
    ///
    /// # Returns
    ///
    ///
    ///   The dash array or `NULL` if the dash array is empty.
    #[doc(alias = "gsk_stroke_get_dash")]
    #[doc(alias = "get_dash")]
    pub fn dash(&self) -> Vec<f32> {
        unsafe {
            let mut n_dash = std::mem::MaybeUninit::uninit();
            let ret = FromGlibContainer::from_glib_none_num(
                ffi::gsk_stroke_get_dash(self.to_glib_none().0, n_dash.as_mut_ptr()),
                n_dash.assume_init() as _,
            );
            ret
        }
    }

    /// Returns the dash_offset of a [`Stroke`][crate::Stroke].
    ///
    /// # Returns
    ///
    /// the dash_offset
    #[doc(alias = "gsk_stroke_get_dash_offset")]
    #[doc(alias = "get_dash_offset")]
    pub fn dash_offset(&self) -> f32 {
        unsafe { ffi::gsk_stroke_get_dash_offset(self.to_glib_none().0) }
    }

    /// Gets the line cap used.
    ///
    /// See [`LineCap`][crate::LineCap] for details.
    ///
    /// # Returns
    ///
    /// The line cap
    #[doc(alias = "gsk_stroke_get_line_cap")]
    #[doc(alias = "get_line_cap")]
    pub fn line_cap(&self) -> LineCap {
        unsafe { from_glib(ffi::gsk_stroke_get_line_cap(self.to_glib_none().0)) }
    }

    /// Gets the line join used.
    ///
    /// See [`LineJoin`][crate::LineJoin] for details.
    ///
    /// # Returns
    ///
    /// The line join
    #[doc(alias = "gsk_stroke_get_line_join")]
    #[doc(alias = "get_line_join")]
    pub fn line_join(&self) -> LineJoin {
        unsafe { from_glib(ffi::gsk_stroke_get_line_join(self.to_glib_none().0)) }
    }

    /// Gets the line width used.
    ///
    /// # Returns
    ///
    /// The line width
    #[doc(alias = "gsk_stroke_get_line_width")]
    #[doc(alias = "get_line_width")]
    pub fn line_width(&self) -> f32 {
        unsafe { ffi::gsk_stroke_get_line_width(self.to_glib_none().0) }
    }

    /// Returns the miter limit of a [`Stroke`][crate::Stroke].
    ///
    /// # Returns
    ///
    /// the miter limit
    #[doc(alias = "gsk_stroke_get_miter_limit")]
    #[doc(alias = "get_miter_limit")]
    pub fn miter_limit(&self) -> f32 {
        unsafe { ffi::gsk_stroke_get_miter_limit(self.to_glib_none().0) }
    }

    /// Sets the dash pattern to use by this stroke.
    ///
    /// A dash pattern is specified by an array of alternating non-negative
    /// values. Each value provides the length of alternate "on" and "off"
    /// portions of the stroke.
    ///
    /// Each "on" segment will have caps applied as if the segment were a
    /// separate contour. In particular, it is valid to use an "on" length
    /// of 0 with `GSK_LINE_CAP_ROUND` or `GSK_LINE_CAP_SQUARE` to draw dots
    /// or squares along a path.
    ///
    /// If @n_dash is 0, if all elements in @dash are 0, or if there are
    /// negative values in @dash, then dashing is disabled.
    ///
    /// If @n_dash is 1, an alternating "on" and "off" pattern with the
    /// single dash length provided is assumed.
    ///
    /// If @n_dash is uneven, the dash array will be used with the first
    /// element in @dash defining an "on" or "off" in alternating passes
    /// through the array.
    ///
    /// You can specify a starting offset into the dash with
    /// [`set_dash_offset()`][Self::set_dash_offset()].
    /// ## `dash`
    ///
    ///   the array of dashes
    #[doc(alias = "gsk_stroke_set_dash")]
    pub fn set_dash(&self, dash: &[f32]) {
        let n_dash = dash.len() as _;
        unsafe {
            ffi::gsk_stroke_set_dash(
                mut_override(self.to_glib_none().0),
                dash.to_glib_none().0,
                n_dash,
            );
        }
    }

    /// Sets the offset into the dash pattern where dashing should begin.
    ///
    /// This is an offset into the length of the path, not an index into
    /// the array values of the dash array.
    ///
    /// See [`set_dash()`][Self::set_dash()] for more details on dashing.
    /// ## `offset`
    /// offset into the dash pattern
    #[doc(alias = "gsk_stroke_set_dash_offset")]
    pub fn set_dash_offset(&self, offset: f32) {
        unsafe {
            ffi::gsk_stroke_set_dash_offset(mut_override(self.to_glib_none().0), offset);
        }
    }

    /// Sets the line cap to be used when stroking.
    ///
    /// See [`LineCap`][crate::LineCap] for details.
    /// ## `line_cap`
    /// the [`LineCap`][crate::LineCap]
    #[doc(alias = "gsk_stroke_set_line_cap")]
    pub fn set_line_cap(&self, line_cap: LineCap) {
        unsafe {
            ffi::gsk_stroke_set_line_cap(mut_override(self.to_glib_none().0), line_cap.into_glib());
        }
    }

    /// Sets the line join to be used when stroking.
    ///
    /// See [`LineJoin`][crate::LineJoin] for details.
    /// ## `line_join`
    /// The line join to use
    #[doc(alias = "gsk_stroke_set_line_join")]
    pub fn set_line_join(&self, line_join: LineJoin) {
        unsafe {
            ffi::gsk_stroke_set_line_join(
                mut_override(self.to_glib_none().0),
                line_join.into_glib(),
            );
        }
    }

    /// Sets the line width to be used when stroking.
    ///
    /// The line width must be > 0.
    /// ## `line_width`
    /// width of the line in pixels
    #[doc(alias = "gsk_stroke_set_line_width")]
    pub fn set_line_width(&self, line_width: f32) {
        unsafe {
            ffi::gsk_stroke_set_line_width(mut_override(self.to_glib_none().0), line_width);
        }
    }

    /// Sets the limit for the distance from the corner where sharp
    /// turns of joins get cut off.
    ///
    /// The miter limit is in units of line width and must be non-negative.
    ///
    /// For joins of type `GSK_LINE_JOIN_MITER` that exceed the miter
    /// limit, the join gets rendered as if it was of type
    /// `GSK_LINE_JOIN_BEVEL`.
    /// ## `limit`
    /// the miter limit
    #[doc(alias = "gsk_stroke_set_miter_limit")]
    pub fn set_miter_limit(&self, limit: f32) {
        unsafe {
            ffi::gsk_stroke_set_miter_limit(mut_override(self.to_glib_none().0), limit);
        }
    }

    /// A helper function that sets the stroke parameters
    /// of @cr from the values found in @self.
    /// ## `cr`
    /// the cairo context to configure
    #[doc(alias = "gsk_stroke_to_cairo")]
    pub fn to_cairo(&self, cr: &cairo::Context) {
        unsafe {
            ffi::gsk_stroke_to_cairo(self.to_glib_none().0, mut_override(cr.to_glib_none().0));
        }
    }

    #[doc(alias = "gsk_stroke_equal")]
    fn equal(&self, stroke2: &Stroke) -> bool {
        assert_initialized_main_thread!();
        unsafe {
            from_glib(ffi::gsk_stroke_equal(
                ToGlibPtr::<*const ffi::GskStroke>::to_glib_none(self).0
                    as glib::ffi::gconstpointer,
                ToGlibPtr::<*const ffi::GskStroke>::to_glib_none(stroke2).0
                    as glib::ffi::gconstpointer,
            ))
        }
    }
}

impl PartialEq for Stroke {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        self.equal(other)
    }
}

impl Eq for Stroke {}