@@ -2,6 +2,7 @@ use super::config::Config;
2
2
use super :: rstk_ext:: * ;
3
3
use rstk:: * ;
4
4
use std:: collections:: HashMap ;
5
+ use std:: sync:: { Arc , Mutex } ;
5
6
6
7
// Ratio to easily adjust the dimension of the gui
7
8
const GUI_RATIO : f64 = 0.8 ;
@@ -10,6 +11,9 @@ const GUI_RATIO: f64 = 0.8;
10
11
pub struct ToolKit {
11
12
themes : HashMap < & ' static str , Style > ,
12
13
window : Option < rstk:: TkTopLevel > ,
14
+ idle_state_widget : Option < rstk:: TkButton > ,
15
+ new_idle_state : Arc < Mutex < bool > > ,
16
+ curr_idle_state : bool ,
13
17
config : Config ,
14
18
}
15
19
@@ -52,24 +56,24 @@ impl ToolKit {
52
56
self . themes . insert ( "TButton" , style) ;
53
57
54
58
let style = Style {
55
- name : "exit .toolkit.TButton" ,
59
+ name : "idle .toolkit.TButton" ,
56
60
background : "#e03131" . to_owned ( ) ,
57
61
foreground : "#1e1e1e" . to_owned ( ) ,
58
62
font_size : ( 12.0 * GUI_RATIO ) as u64 ,
59
63
font_family : font_family. to_string ( ) ,
60
64
font_weight : "bold" . to_owned ( ) ,
61
65
} ;
62
- self . themes . insert ( "TEButton " , style) ;
66
+ self . themes . insert ( "TIButton " , style) ;
63
67
64
68
let style = Style {
65
- name : "iconify .toolkit.TButton" ,
69
+ name : "running .toolkit.TButton" ,
66
70
background : "#1971c2" . to_owned ( ) ,
67
71
foreground : "#1e1e1e" . to_owned ( ) ,
68
72
font_size : ( 12.0 * GUI_RATIO ) as u64 ,
69
73
font_family : font_family. to_string ( ) ,
70
74
font_weight : "bold" . to_owned ( ) ,
71
75
} ;
72
- self . themes . insert ( "TIButton " , style) ;
76
+ self . themes . insert ( "TRButton " , style) ;
73
77
74
78
let style = Style {
75
79
name : "toolkit.TNotebook" ,
@@ -111,31 +115,23 @@ impl ToolKit {
111
115
label. text ( "AFRIM Toolkit" ) ;
112
116
label. style ( & self . themes [ "TLabel" ] ) ;
113
117
label. pack ( ) . side ( PackSide :: Left ) . layout ( ) ;
114
- // Header iconify button
115
- let button = rstk:: make_button ( & frame) ;
116
- button. text ( "x" ) ;
117
- button. width ( ( 4.0 * GUI_RATIO ) as i64 ) ;
118
- button. style ( & self . themes [ "TEButton" ] ) ;
119
- button. command ( rstk:: end_wish) ;
120
- button
121
- . pack ( )
122
- . side ( PackSide :: Right )
123
- . padx ( ( 5.0 * GUI_RATIO ) as u64 )
124
- . layout ( ) ;
125
- // Header exit button
118
+ // Header idle state button
126
119
let button = rstk:: make_button ( & frame) ;
127
- button. text ( "- " ) ;
120
+ button. text ( "State " ) ;
128
121
{
129
- let window = window. clone ( ) ;
130
- button. command ( move || window. iconify ( ) ) ;
122
+ let idle_state = Arc :: clone ( & self . new_idle_state ) ;
123
+ button. command ( move || {
124
+ let mut idle_state = idle_state. lock ( ) . unwrap ( ) ;
125
+
126
+ * idle_state = !* idle_state;
127
+ } ) ;
131
128
}
132
- button. width ( ( 4.0 * GUI_RATIO ) as i64 ) ;
133
- button. style ( & self . themes [ "TIButton" ] ) ;
134
129
button
135
130
. pack ( )
136
131
. side ( PackSide :: Right )
137
132
. padx ( ( 5.0 * GUI_RATIO ) as u64 )
138
133
. layout ( ) ;
134
+ self . idle_state_widget = Some ( button) ;
139
135
// We build the header
140
136
frame
141
137
. pack ( )
@@ -288,4 +284,32 @@ impl ToolKit {
288
284
self . build_theme ( ) ;
289
285
self . build_window ( ) ;
290
286
}
287
+
288
+ pub fn new_idle_state ( & mut self ) -> Option < bool > {
289
+ let curr_idle_state = self . curr_idle_state ;
290
+ let new_idle_state = * self . new_idle_state . lock ( ) . unwrap ( ) ;
291
+ let toggle = curr_idle_state != new_idle_state;
292
+
293
+ if toggle {
294
+ self . curr_idle_state = new_idle_state;
295
+
296
+ return Some ( self . curr_idle_state ) ;
297
+ }
298
+
299
+ None
300
+ }
301
+
302
+ pub fn set_idle_state ( & mut self , state : bool ) {
303
+ self . curr_idle_state = state;
304
+ * self . new_idle_state . lock ( ) . unwrap ( ) = state;
305
+ let idle_state_widget = self . idle_state_widget . as_ref ( ) . unwrap ( ) ;
306
+
307
+ if state {
308
+ idle_state_widget. text ( "IDLE" ) ;
309
+ idle_state_widget. style ( & self . themes [ "TIButton" ] ) ;
310
+ } else {
311
+ idle_state_widget. text ( "Running" ) ;
312
+ idle_state_widget. style ( & self . themes [ "TRButton" ] ) ;
313
+ }
314
+ }
291
315
}
0 commit comments