gsk4/auto/stroke.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::{ffi, LineCap, LineJoin};
6use glib::translate::*;
7
8glib::wrapper! {
9 /// Collects the parameters that influence the operation of stroking a path.
10 #[derive(Debug, PartialOrd, Ord, Hash)]
11 pub struct Stroke(Boxed<ffi::GskStroke>);
12
13 match fn {
14 copy => |ptr| ffi::gsk_stroke_copy(ptr),
15 free => |ptr| ffi::gsk_stroke_free(ptr),
16 type_ => || ffi::gsk_stroke_get_type(),
17 }
18}
19
20impl Stroke {
21 /// Creates a new [`Stroke`][crate::Stroke] with the given @line_width.
22 /// ## `line_width`
23 /// line width of the stroke. Must be > 0
24 ///
25 /// # Returns
26 ///
27 /// a new [`Stroke`][crate::Stroke]
28 #[doc(alias = "gsk_stroke_new")]
29 pub fn new(line_width: f32) -> Stroke {
30 assert_initialized_main_thread!();
31 unsafe { from_glib_full(ffi::gsk_stroke_new(line_width)) }
32 }
33
34 /// Gets the dash array in use.
35 ///
36 /// # Returns
37 ///
38 ///
39 /// the dash array or `NULL` if the dash array is empty
40 #[doc(alias = "gsk_stroke_get_dash")]
41 #[doc(alias = "get_dash")]
42 pub fn dash(&self) -> Vec<f32> {
43 unsafe {
44 let mut n_dash = std::mem::MaybeUninit::uninit();
45 let ret = FromGlibContainer::from_glib_none_num(
46 ffi::gsk_stroke_get_dash(self.to_glib_none().0, n_dash.as_mut_ptr()),
47 n_dash.assume_init() as _,
48 );
49 ret
50 }
51 }
52
53 /// Gets the dash offset.
54 ///
55 /// # Returns
56 ///
57 /// the dash offset
58 #[doc(alias = "gsk_stroke_get_dash_offset")]
59 #[doc(alias = "get_dash_offset")]
60 pub fn dash_offset(&self) -> f32 {
61 unsafe { ffi::gsk_stroke_get_dash_offset(self.to_glib_none().0) }
62 }
63
64 /// Gets the line cap used.
65 ///
66 /// See [`LineCap`][crate::LineCap] for details.
67 ///
68 /// # Returns
69 ///
70 /// the line cap
71 #[doc(alias = "gsk_stroke_get_line_cap")]
72 #[doc(alias = "get_line_cap")]
73 pub fn line_cap(&self) -> LineCap {
74 unsafe { from_glib(ffi::gsk_stroke_get_line_cap(self.to_glib_none().0)) }
75 }
76
77 /// Gets the line join used.
78 ///
79 /// See [`LineJoin`][crate::LineJoin] for details.
80 ///
81 /// # Returns
82 ///
83 /// the line join
84 #[doc(alias = "gsk_stroke_get_line_join")]
85 #[doc(alias = "get_line_join")]
86 pub fn line_join(&self) -> LineJoin {
87 unsafe { from_glib(ffi::gsk_stroke_get_line_join(self.to_glib_none().0)) }
88 }
89
90 /// Gets the line width used.
91 ///
92 /// # Returns
93 ///
94 /// the line width
95 #[doc(alias = "gsk_stroke_get_line_width")]
96 #[doc(alias = "get_line_width")]
97 pub fn line_width(&self) -> f32 {
98 unsafe { ffi::gsk_stroke_get_line_width(self.to_glib_none().0) }
99 }
100
101 /// Gets the miter limit.
102 ///
103 /// # Returns
104 ///
105 /// the miter limit
106 #[doc(alias = "gsk_stroke_get_miter_limit")]
107 #[doc(alias = "get_miter_limit")]
108 pub fn miter_limit(&self) -> f32 {
109 unsafe { ffi::gsk_stroke_get_miter_limit(self.to_glib_none().0) }
110 }
111
112 /// Sets the dash pattern to use.
113 ///
114 /// A dash pattern is specified by an array of alternating non-negative
115 /// values. Each value provides the length of alternate "on" and "off"
116 /// portions of the stroke.
117 ///
118 /// Each "on" segment will have caps applied as if the segment were a
119 /// separate contour. In particular, it is valid to use an "on" length
120 /// of 0 with [enum@Gsk.LineCap.round] or [enum@Gsk.LineCap.square]
121 /// to draw dots or squares along a path.
122 ///
123 /// If @n_dash is 0, if all elements in @dash are 0, or if there are
124 /// negative values in @dash, then dashing is disabled.
125 ///
126 /// If @n_dash is 1, an alternating "on" and "off" pattern with the
127 /// single dash length provided is assumed.
128 ///
129 /// If @n_dash is uneven, the dash array will be used with the first
130 /// element in @dash defining an "on" or "off" in alternating passes
131 /// through the array.
132 ///
133 /// You can specify a starting offset into the dash with
134 /// [`set_dash_offset()`][Self::set_dash_offset()].
135 /// ## `dash`
136 ///
137 /// the array of dashes
138 #[doc(alias = "gsk_stroke_set_dash")]
139 pub fn set_dash(&self, dash: &[f32]) {
140 let n_dash = dash.len() as _;
141 unsafe {
142 ffi::gsk_stroke_set_dash(
143 mut_override(self.to_glib_none().0),
144 dash.to_glib_none().0,
145 n_dash,
146 );
147 }
148 }
149
150 /// Sets the offset into the dash pattern where dashing should begin.
151 ///
152 /// This is an offset into the length of the path, not an index into
153 /// the array values of the dash array.
154 ///
155 /// See [`set_dash()`][Self::set_dash()] for more details on dashing.
156 /// ## `offset`
157 /// offset into the dash pattern
158 #[doc(alias = "gsk_stroke_set_dash_offset")]
159 pub fn set_dash_offset(&self, offset: f32) {
160 unsafe {
161 ffi::gsk_stroke_set_dash_offset(mut_override(self.to_glib_none().0), offset);
162 }
163 }
164
165 /// Sets the line cap to be used when stroking.
166 ///
167 /// See [`LineCap`][crate::LineCap] for details.
168 /// ## `line_cap`
169 /// the line cap
170 #[doc(alias = "gsk_stroke_set_line_cap")]
171 pub fn set_line_cap(&self, line_cap: LineCap) {
172 unsafe {
173 ffi::gsk_stroke_set_line_cap(mut_override(self.to_glib_none().0), line_cap.into_glib());
174 }
175 }
176
177 /// Sets the line join to be used when stroking.
178 ///
179 /// See [`LineJoin`][crate::LineJoin] for details.
180 /// ## `line_join`
181 /// the line join to use
182 #[doc(alias = "gsk_stroke_set_line_join")]
183 pub fn set_line_join(&self, line_join: LineJoin) {
184 unsafe {
185 ffi::gsk_stroke_set_line_join(
186 mut_override(self.to_glib_none().0),
187 line_join.into_glib(),
188 );
189 }
190 }
191
192 /// Sets the line width to be used when stroking.
193 ///
194 /// The line width must be > 0.
195 /// ## `line_width`
196 /// width of the line in pixels
197 #[doc(alias = "gsk_stroke_set_line_width")]
198 pub fn set_line_width(&self, line_width: f32) {
199 unsafe {
200 ffi::gsk_stroke_set_line_width(mut_override(self.to_glib_none().0), line_width);
201 }
202 }
203
204 /// Sets the miter limit to be used when stroking.
205 ///
206 /// The miter limit is the distance from the corner where sharp
207 /// turns of joins get cut off.
208 ///
209 /// The limit is specfied in units of line width and must be non-negative.
210 ///
211 /// For joins of type [enum@Gsk.LineJoin.miter] that exceed the miter limit,
212 /// the join gets rendered as if it was of type [enum@Gsk.LineJoin.bevel].
213 /// ## `limit`
214 /// the miter limit
215 #[doc(alias = "gsk_stroke_set_miter_limit")]
216 pub fn set_miter_limit(&self, limit: f32) {
217 unsafe {
218 ffi::gsk_stroke_set_miter_limit(mut_override(self.to_glib_none().0), limit);
219 }
220 }
221
222 /// A helper function that sets the stroke parameters
223 /// of a cairo context from a [`Stroke`][crate::Stroke].
224 /// ## `cr`
225 /// the cairo context to configure
226 #[doc(alias = "gsk_stroke_to_cairo")]
227 pub fn to_cairo(&self, cr: &cairo::Context) {
228 unsafe {
229 ffi::gsk_stroke_to_cairo(self.to_glib_none().0, mut_override(cr.to_glib_none().0));
230 }
231 }
232
233 #[doc(alias = "gsk_stroke_equal")]
234 fn equal(&self, stroke2: &Stroke) -> bool {
235 assert_initialized_main_thread!();
236 unsafe {
237 from_glib(ffi::gsk_stroke_equal(
238 ToGlibPtr::<*const ffi::GskStroke>::to_glib_none(self).0
239 as glib::ffi::gconstpointer,
240 ToGlibPtr::<*const ffi::GskStroke>::to_glib_none(stroke2).0
241 as glib::ffi::gconstpointer,
242 ))
243 }
244 }
245}
246
247impl PartialEq for Stroke {
248 #[inline]
249 fn eq(&self, other: &Self) -> bool {
250 self.equal(other)
251 }
252}
253
254impl Eq for Stroke {}