@@ -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- impl 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- }
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+ }
2851
29- /// Updates the [`Color`] of the [`Border`].
30- pub fn with_color ( self , color : impl Into < Color > ) -> Self {
52+ impl Border {
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,96 @@ 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+ impl Radius {
118+ /// Creates a new [`Radius`] with the same value for each corner.
119+ pub fn new ( value : impl Into < Pixels > ) -> Self {
120+ let value = value. into ( ) . 0 ;
121+
122+ Self {
123+ top_left : value,
124+ top_right : value,
125+ bottom_right : value,
126+ bottom_left : value,
127+ }
128+ }
129+
130+ /// Sets the top left value of the [`Radius`].
131+ pub fn top_left ( self , value : impl Into < Pixels > ) -> Self {
132+ Self {
133+ top_left : value. into ( ) . 0 ,
134+ ..self
135+ }
136+ }
137+
138+ /// Sets the top right value of the [`Radius`].
139+ pub fn top_right ( self , value : impl Into < Pixels > ) -> Self {
140+ Self {
141+ top_right : value. into ( ) . 0 ,
142+ ..self
143+ }
144+ }
145+
146+ /// Sets the bottom right value of the [`Radius`].
147+ pub fn bottom_right ( self , value : impl Into < Pixels > ) -> Self {
148+ Self {
149+ bottom_right : value. into ( ) . 0 ,
150+ ..self
151+ }
152+ }
153+
154+ /// Sets the bottom left value of the [`Radius`].
155+ pub fn bottom_left ( self , value : impl Into < Pixels > ) -> Self {
156+ Self {
157+ bottom_left : value. into ( ) . 0 ,
158+ ..self
159+ }
160+ }
161+ }
58162
59163impl From < f32 > for Radius {
60- fn from ( w : f32 ) -> Self {
61- Self ( [ w; 4 ] )
164+ fn from ( radius : f32 ) -> Self {
165+ Self {
166+ top_left : radius,
167+ top_right : radius,
168+ bottom_right : radius,
169+ bottom_left : radius,
170+ }
62171 }
63172}
64173
@@ -80,14 +189,13 @@ impl From<i32> for Radius {
80189 }
81190}
82191
83- impl From < [ f32 ; 4 ] > for Radius {
84- fn from ( radi : [ f32 ; 4 ] ) -> Self {
85- Self ( radi)
86- }
87- }
88-
89192impl From < Radius > for [ f32 ; 4 ] {
90193 fn from ( radi : Radius ) -> Self {
91- radi. 0
194+ [
195+ radi. top_left ,
196+ radi. top_right ,
197+ radi. bottom_right ,
198+ radi. bottom_left ,
199+ ]
92200 }
93201}
0 commit comments