@@ -5,30 +5,6 @@ use ratatui::{
5
5
widgets:: Widget ,
6
6
} ;
7
7
8
- #[ derive( Clone ) ]
9
- #[ derive( Debug ) ]
10
- #[ derive( Default ) ]
11
- #[ derive( PartialEq , Eq ) ]
12
- pub struct Buttons < ' a > {
13
- buttons : Vec < Button < ' a > > ,
14
- states : Vec < ButtonState > ,
15
- }
16
-
17
- impl < ' a > Buttons < ' a > {
18
- fn new < T > ( labels : Vec < T > ) -> Self
19
- where
20
- T : Into < Line < ' a > > ,
21
- {
22
- let size = labels. len ( ) ;
23
- let mut buttons = Vec :: with_capacity ( size) ;
24
- for i in labels {
25
- buttons. push ( Button :: new ( i) ) ;
26
- }
27
- let states = vec ! [ ButtonState :: Normal ; size] ;
28
- Self { buttons, states }
29
- }
30
- }
31
-
32
8
#[ derive( Clone ) ]
33
9
#[ derive( Debug ) ]
34
10
#[ derive( PartialEq , Eq ) ]
@@ -38,6 +14,20 @@ pub struct Button<'a> {
38
14
state : ButtonState ,
39
15
}
40
16
17
+ #[ derive( Clone ) ]
18
+ #[ derive( Debug ) ]
19
+ pub struct ButtonStates {
20
+ pub states : Vec < ButtonState > ,
21
+ }
22
+
23
+ impl Default for ButtonStates {
24
+ fn default ( ) -> Self {
25
+ Self {
26
+ states : vec ! [ ButtonState :: Selected , ButtonState :: Normal ] ,
27
+ }
28
+ }
29
+ }
30
+
41
31
impl < ' a > Button < ' a > {
42
32
const fn colors ( & self ) -> ( Color , Color , Color , Color ) {
43
33
let theme = self . theme ;
@@ -98,33 +88,54 @@ pub struct Theme {
98
88
highlight : Color ,
99
89
shadow : Color ,
100
90
}
101
- pub const CYAN : Theme = Theme {
102
- text : Color :: Cyan ,
103
- background : Color :: LightCyan ,
104
- shadow : Color :: DarkGray ,
105
- highlight : Color :: Blue ,
106
- } ;
107
-
108
- pub const BLUE : Theme = Theme {
109
- text : Color :: Rgb ( 16 , 24 , 48 ) ,
110
- background : Color :: Rgb ( 48 , 72 , 144 ) ,
111
- highlight : Color :: Rgb ( 64 , 96 , 192 ) ,
112
- shadow : Color :: Rgb ( 32 , 48 , 96 ) ,
113
- } ;
114
91
115
- pub const RED : Theme = Theme {
116
- text : Color :: Rgb ( 48 , 16 , 16 ) ,
117
- background : Color :: Rgb ( 144 , 48 , 48 ) ,
118
- highlight : Color :: Rgb ( 192 , 64 , 64 ) ,
119
- shadow : Color :: Rgb ( 96 , 32 , 32 ) ,
120
- } ;
92
+ impl Theme {
93
+ pub const fn test_color ( ) -> Self {
94
+ let ( r, g, b) = ( 21 , 21 , 16 ) ;
95
+ Self {
96
+ text : Color :: Rgb ( r, g, b) ,
97
+ shadow : Color :: Rgb ( r * 2 , g * 2 , b * 2 ) ,
98
+ background : Color :: Rgb ( r * 3 , g * 3 , b * 3 ) ,
99
+ highlight : Color :: Rgb ( r * 6 , g * 6 , b * 6 ) ,
100
+ }
101
+ }
102
+ pub const fn blue ( ) -> Self {
103
+ let ( r, g, b) = ( 16 , 24 , 48 ) ;
104
+ Self {
105
+ text : Color :: Rgb ( r, g, b) ,
106
+ shadow : Color :: Rgb ( r * 2 , g * 2 , b * 2 ) ,
107
+ background : Color :: Rgb ( r * 3 , g * 3 , b * 3 ) ,
108
+ highlight : Color :: Rgb ( r * 5 , g * 5 , b * 5 ) ,
109
+ }
110
+ }
121
111
122
- pub const GREEN : Theme = Theme {
123
- text : Color :: Rgb ( 16 , 48 , 16 ) ,
124
- background : Color :: Rgb ( 48 , 144 , 48 ) ,
125
- highlight : Color :: Rgb ( 64 , 192 , 64 ) ,
126
- shadow : Color :: Rgb ( 32 , 96 , 32 ) ,
127
- } ;
112
+ pub const fn red ( ) -> Self {
113
+ let ( r, g, b) = ( 48 , 16 , 16 ) ;
114
+ Self {
115
+ text : Color :: Rgb ( r, g, b) ,
116
+ shadow : Color :: Rgb ( r * 2 , g * 2 , b * 2 ) ,
117
+ background : Color :: Rgb ( r * 3 , g * 3 , b * 3 ) ,
118
+ highlight : Color :: Rgb ( r * 4 , g * 4 , b * 4 ) ,
119
+ }
120
+ }
121
+ pub const fn green ( ) -> Self {
122
+ let ( r, g, b) = ( 16 , 48 , 16 ) ;
123
+ Self {
124
+ text : Color :: Rgb ( r, g, b) ,
125
+ shadow : Color :: Rgb ( r * 2 , g * 2 , b * 2 ) ,
126
+ background : Color :: Rgb ( r * 3 , g * 3 , b * 3 ) ,
127
+ highlight : Color :: Rgb ( r * 4 , g * 4 , b * 4 ) ,
128
+ }
129
+ }
130
+ pub const fn submit_color ( ) -> Self {
131
+ Self {
132
+ text : Color :: Blue ,
133
+ background : Color :: Reset ,
134
+ highlight : Color :: Rgb ( 64 , 96 , 192 ) ,
135
+ shadow : Color :: Rgb ( 32 , 48 , 96 ) ,
136
+ }
137
+ }
138
+ }
128
139
129
140
impl < ' a > Button < ' a > {
130
141
pub fn new < T > ( label : T ) -> Self
@@ -133,7 +144,7 @@ impl<'a> Button<'a> {
133
144
{
134
145
Self {
135
146
label : label. into ( ) ,
136
- theme : BLUE ,
147
+ theme : Theme :: blue ( ) ,
137
148
state : ButtonState :: Normal ,
138
149
}
139
150
}
0 commit comments