@@ -10,40 +10,64 @@ pub struct Border {
1010 /// The width of the border.
1111 pub width : f32 ,
1212
13- /// The radius of the border.
13+ /// The [`Radius`] of the border.
1414 pub radius : Radius ,
1515}
1616
17+ /// Creates a new [`Border`] with the given [`Radius`].
18+ ///
19+ /// ```
20+ /// # use iced_core::border::{self, Border};
21+ /// #
22+ /// assert_eq!(border::rounded(10), Border::default().rounded(10));
23+ /// ```
24+ pub fn rounded ( radius : impl Into < Radius > ) -> Border {
25+ Border :: default ( ) . rounded ( radius)
26+ }
27+
28+ /// Creates a new [`Border`] with the given [`Color`].
29+ ///
30+ /// ```
31+ /// # use iced_core::border::{self, Border};
32+ /// # use iced_core::Color;
33+ /// #
34+ /// assert_eq!(border::color(Color::BLACK), Border::default().color(Color::BLACK));
35+ /// ```
36+ pub fn color ( color : impl Into < Color > ) -> Border {
37+ Border :: default ( ) . color ( color)
38+ }
39+
40+ /// Creates a new [`Border`] with the given `width`.
41+ ///
42+ /// ```
43+ /// # use iced_core::border::{self, Border};
44+ /// # use iced_core::Color;
45+ /// #
46+ /// assert_eq!(border::width(10), Border::default().width(10));
47+ /// ```
48+ pub fn width ( width : impl Into < Pixels > ) -> Border {
49+ Border :: default ( ) . width ( width)
50+ }
51+
1752impl Border {
18- /// Creates a new default rounded [`Border`] with the given [`Radius`].
19- ///
20- /// ```
21- /// # use iced_core::Border;
22- /// #
23- /// assert_eq!(Border::rounded(10), Border::default().with_radius(10));
24- /// ```
25- pub fn rounded ( radius : impl Into < Radius > ) -> Self {
26- Self :: default ( ) . with_radius ( radius)
27- }
28-
29- /// Updates the [`Color`] of the [`Border`].
30- pub fn with_color ( self , color : impl Into < Color > ) -> Self {
53+ /// Sets the [`Color`] of the [`Border`].
54+ pub fn color ( self , color : impl Into < Color > ) -> Self {
3155 Self {
3256 color : color. into ( ) ,
3357 ..self
3458 }
3559 }
3660
37- /// Updates the [`Radius`] of the [`Border`].
38- pub fn with_radius ( self , radius : impl Into < Radius > ) -> Self {
61+ /// Sets the [`Radius`] of the [`Border`].
62+ pub fn rounded ( self , radius : impl Into < Radius > ) -> Self {
3963 Self {
4064 radius : radius. into ( ) ,
4165 ..self
4266 }
4367 }
4468
45- /// Updates the width of the [`Border`].
46- pub fn with_width ( self , width : impl Into < Pixels > ) -> Self {
69+ /// Sets the width of the [`Border`].
70+ pub fn width ( self , width : impl Into < Pixels > ) -> Self {
4771 Self {
4872 width : width. into ( ) . 0 ,
4973 ..self
@@ -54,11 +78,160 @@ impl Border {
5478/// The border radii for the corners of a graphics primitive in the order:
5579/// top-left, top-right, bottom-right, bottom-left.
5680#[ derive( Debug , Clone , Copy , PartialEq , Default ) ]
57- pub struct Radius ( [ f32 ; 4 ] ) ;
81+ pub struct Radius {
82+ /// Top left radius
83+ pub top_left : f32 ,
84+ /// Top right radius
85+ pub top_right : f32 ,
86+ /// Bottom right radius
87+ pub bottom_right : f32 ,
88+ /// Bottom left radius
89+ pub bottom_left : f32 ,
90+ }
91+
92+ /// Creates a new [`Radius`] with the same value for each corner.
93+ pub fn radius ( value : impl Into < Pixels > ) -> Radius {
94+ Radius :: new ( value)
95+ }
96+
97+ /// Creates a new [`Radius`] with the given top left value.
98+ pub fn top_left ( value : impl Into < Pixels > ) -> Radius {
99+ Radius :: default ( ) . top_left ( value)
100+ }
101+
102+ /// Creates a new [`Radius`] with the given top right value.
103+ pub fn top_right ( value : impl Into < Pixels > ) -> Radius {
104+ Radius :: default ( ) . top_right ( value)
105+ }
106+
107+ /// Creates a new [`Radius`] with the given bottom right value.
108+ pub fn bottom_right ( value : impl Into < Pixels > ) -> Radius {
109+ Radius :: default ( ) . bottom_right ( value)
110+ }
111+
112+ /// Creates a new [`Radius`] with the given bottom left value.
113+ pub fn bottom_left ( value : impl Into < Pixels > ) -> Radius {
114+ Radius :: default ( ) . bottom_left ( value)
115+ }
116+
117+ /// Creates a new [`Radius`] with the given value as top left and top right.
118+ pub fn top ( value : impl Into < Pixels > ) -> Radius {
119+ Radius :: default ( ) . top ( value)
120+ }
121+
122+ /// Creates a new [`Radius`] with the given value as bottom left and bottom right.
123+ pub fn bottom ( value : impl Into < Pixels > ) -> Radius {
124+ Radius :: default ( ) . bottom ( value)
125+ }
126+
127+ /// Creates a new [`Radius`] with the given value as top left and bottom left.
128+ pub fn left ( value : impl Into < Pixels > ) -> Radius {
129+ Radius :: default ( ) . left ( value)
130+ }
131+
132+ /// Creates a new [`Radius`] with the given value as top right and bottom right.
133+ pub fn right ( value : impl Into < Pixels > ) -> Radius {
134+ Radius :: default ( ) . right ( value)
135+ }
136+
137+ impl Radius {
138+ /// Creates a new [`Radius`] with the same value for each corner.
139+ pub fn new ( value : impl Into < Pixels > ) -> Self {
140+ let value = value. into ( ) . 0 ;
141+
142+ Self {
143+ top_left : value,
144+ top_right : value,
145+ bottom_right : value,
146+ bottom_left : value,
147+ }
148+ }
149+
150+ /// Sets the top left value of the [`Radius`].
151+ pub fn top_left ( self , value : impl Into < Pixels > ) -> Self {
152+ Self {
153+ top_left : value. into ( ) . 0 ,
154+ ..self
155+ }
156+ }
157+
158+ /// Sets the top right value of the [`Radius`].
159+ pub fn top_right ( self , value : impl Into < Pixels > ) -> Self {
160+ Self {
161+ top_right : value. into ( ) . 0 ,
162+ ..self
163+ }
164+ }
165+
166+ /// Sets the bottom right value of the [`Radius`].
167+ pub fn bottom_right ( self , value : impl Into < Pixels > ) -> Self {
168+ Self {
169+ bottom_right : value. into ( ) . 0 ,
170+ ..self
171+ }
172+ }
173+
174+ /// Sets the bottom left value of the [`Radius`].
175+ pub fn bottom_left ( self , value : impl Into < Pixels > ) -> Self {
176+ Self {
177+ bottom_left : value. into ( ) . 0 ,
178+ ..self
179+ }
180+ }
181+
182+ /// Sets the top left and top right values of the [`Radius`].
183+ pub fn top ( self , value : impl Into < Pixels > ) -> Self {
184+ let value = value. into ( ) . 0 ;
185+
186+ Self {
187+ top_left : value,
188+ top_right : value,
189+ ..self
190+ }
191+ }
192+
193+ /// Sets the bottom left and bottom right values of the [`Radius`].
194+ pub fn bottom ( self , value : impl Into < Pixels > ) -> Self {
195+ let value = value. into ( ) . 0 ;
196+
197+ Self {
198+ bottom_left : value,
199+ bottom_right : value,
200+ ..self
201+ }
202+ }
203+
204+ /// Sets the top left and bottom left values of the [`Radius`].
205+ pub fn left ( self , value : impl Into < Pixels > ) -> Self {
206+ let value = value. into ( ) . 0 ;
207+
208+ Self {
209+ top_left : value,
210+ bottom_left : value,
211+ ..self
212+ }
213+ }
214+
215+ /// Sets the top right and bottom right values of the [`Radius`].
216+ pub fn right ( self , value : impl Into < Pixels > ) -> Self {
217+ let value = value. into ( ) . 0 ;
218+
219+ Self {
220+ top_right : value,
221+ bottom_right : value,
222+ ..self
223+ }
224+ }
225+ }
58226
59227impl From < f32 > for Radius {
60- fn from ( w : f32 ) -> Self {
61- Self ( [ w; 4 ] )
228+ fn from ( radius : f32 ) -> Self {
229+ Self {
230+ top_left : radius,
231+ top_right : radius,
232+ bottom_right : radius,
233+ bottom_left : radius,
234+ }
62235 }
63236}
64237
@@ -80,14 +253,13 @@ impl From<i32> for Radius {
80253 }
81254}
82255
83- impl From < [ f32 ; 4 ] > for Radius {
84- fn from ( radi : [ f32 ; 4 ] ) -> Self {
85- Self ( radi)
86- }
87- }
88-
89256impl From < Radius > for [ f32 ; 4 ] {
90257 fn from ( radi : Radius ) -> Self {
91- radi. 0
258+ [
259+ radi. top_left ,
260+ radi. top_right ,
261+ radi. bottom_right ,
262+ radi. bottom_left ,
263+ ]
92264 }
93265}
0 commit comments