@@ -4,17 +4,18 @@ use crate::RGBA;
4
4
use glib:: { translate:: * , IntoGStr } ;
5
5
use std:: { fmt, str:: FromStr } ;
6
6
7
- #[ derive( Debug , Default ) ]
7
+ #[ derive( Debug ) ]
8
8
// rustdoc-stripper-ignore-next
9
9
/// A [builder-pattern] type to construct [`RGBA`] objects.
10
10
///
11
11
/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
12
12
#[ must_use = "The builder must be built to be used" ]
13
- pub struct RGBABuilder {
14
- red : Option < f32 > ,
15
- green : Option < f32 > ,
16
- blue : Option < f32 > ,
17
- alpha : Option < f32 > ,
13
+ pub struct RGBABuilder ( RGBA ) ;
14
+
15
+ impl Default for RGBABuilder {
16
+ fn default ( ) -> Self {
17
+ Self ( RGBA :: WHITE )
18
+ }
18
19
}
19
20
20
21
impl RGBABuilder {
@@ -25,43 +26,30 @@ impl RGBABuilder {
25
26
}
26
27
27
28
pub fn blue ( mut self , blue : f32 ) -> Self {
28
- self . blue = Some ( blue) ;
29
+ self . 0 . set_blue ( blue) ;
29
30
self
30
31
}
31
32
32
33
pub fn green ( mut self , green : f32 ) -> Self {
33
- self . green = Some ( green) ;
34
+ self . 0 . set_green ( green) ;
34
35
self
35
36
}
36
37
37
38
pub fn red ( mut self , red : f32 ) -> Self {
38
- self . red = Some ( red) ;
39
+ self . 0 . set_red ( red) ;
39
40
self
40
41
}
41
42
42
43
pub fn alpha ( mut self , alpha : f32 ) -> Self {
43
- self . alpha = Some ( alpha) ;
44
+ self . 0 . set_alpha ( alpha) ;
44
45
self
45
46
}
46
47
47
48
// rustdoc-stripper-ignore-next
48
49
/// Build the [`RGBA`].
49
50
#[ must_use = "The RGBA returned by this builder should probably be used" ]
50
51
pub fn build ( self ) -> RGBA {
51
- let mut rgba = RGBA :: WHITE ;
52
- if let Some ( blue) = self . blue {
53
- rgba. set_blue ( blue) ;
54
- }
55
- if let Some ( red) = self . red {
56
- rgba. set_red ( red) ;
57
- }
58
- if let Some ( green) = self . green {
59
- rgba. set_green ( green) ;
60
- }
61
- if let Some ( alpha) = self . alpha {
62
- rgba. set_alpha ( alpha) ;
63
- }
64
- rgba
52
+ self . 0
65
53
}
66
54
}
67
55
0 commit comments