@@ -17,6 +17,8 @@ use crate::data::{DataContainer, SerialDirection};
17
17
18
18
const MAX_FPS : f64 = 24.0 ;
19
19
20
+ const DEFAULT_FONT_ID : FontId = FontId :: new ( 14.0 , FontFamily :: Monospace ) ;
21
+
20
22
#[ derive( Clone ) ]
21
23
pub enum Print {
22
24
EMPTY ,
@@ -133,6 +135,25 @@ impl MyApp {
133
135
index : 0 ,
134
136
}
135
137
}
138
+
139
+ fn console_text ( & self , packet : & crate :: data:: Packet ) -> Option < String > {
140
+ match ( self . show_sent_cmds , self . show_timestamps , & packet. direction ) {
141
+ ( true , true , _) => Some ( format ! (
142
+ "[{}] t + {:.3}s: {}" ,
143
+ packet. direction,
144
+ packet. time as f32 / 1000.0 ,
145
+ packet. payload
146
+ ) ) ,
147
+ ( true , false , _) => Some ( format ! ( "[{}]: {}" , packet. direction, packet. payload) ) ,
148
+ ( false , true , SerialDirection :: Receive ) => Some ( format ! (
149
+ "t + {:.3}s: {}" ,
150
+ packet. time as f32 / 1000.0 ,
151
+ packet. payload
152
+ ) ) ,
153
+ ( false , false , SerialDirection :: Receive ) => Some ( packet. payload . clone ( ) ) ,
154
+ ( _, _, _) => None ,
155
+ }
156
+ }
136
157
}
137
158
138
159
impl eframe:: App for MyApp {
@@ -218,46 +239,21 @@ impl eframe::App for MyApp {
218
239
. show_rows ( ui, row_height, num_rows,
219
240
|ui, row_range| {
220
241
for row in row_range {
221
- let packet = self . data . raw_traffic [ row] . clone ( ) ;
242
+ let packet = & self . data . raw_traffic [ row] ;
222
243
let color = if self . dark_mode {
223
244
egui:: Color32 :: WHITE
224
245
} else {
225
246
egui:: Color32 :: BLACK
226
247
} ;
227
- ui. horizontal_wrapped ( |ui| {
228
- let text;
229
- if self . show_sent_cmds {
230
- if self . show_timestamps {
231
- text = format ! ( "[{}] t + {:.3}s: {}" ,
232
- packet. direction,
233
- packet. time as f32 / 1000.0 ,
234
- packet. payload) ;
235
- ui. label ( RichText :: new ( text) . color ( color) . font (
236
- FontId :: new ( 14.0 , FontFamily :: Monospace ) ) ) ;
237
- } else {
238
- text = format ! ( "[{}]: {}" ,
239
- packet. direction,
240
- packet. payload) ;
241
- ui. label ( RichText :: new ( text) . color ( color) . font (
242
- FontId :: new ( 14.0 , FontFamily :: Monospace ) ) ) ;
243
- }
244
- } else {
245
- if packet. direction == SerialDirection :: Receive {
246
- if self . show_timestamps {
247
- text = format ! ( "t + {:.3}s: {}" ,
248
- packet. time as f32 / 1000.0 ,
249
- packet. payload) ;
250
- ui. label ( RichText :: new ( text) . color ( color) . font (
251
- FontId :: new ( 14.0 , FontFamily :: Monospace ) ) ) ;
252
- } else {
253
- text = format ! ( "{}" ,
254
- packet. payload) ;
255
- ui. label ( RichText :: new ( text) . color ( color) . font (
256
- FontId :: new ( 14.0 , FontFamily :: Monospace ) ) ) ;
257
- }
258
- }
259
- }
260
- } ) ;
248
+ ui. horizontal_wrapped ( |ui| {
249
+ if let Some ( text) = self . console_text ( packet) {
250
+ ui. label (
251
+ RichText :: new ( text)
252
+ . color ( color)
253
+ . font ( DEFAULT_FONT_ID ) ,
254
+ ) ;
255
+ }
256
+ } ) ;
261
257
}
262
258
} ) ;
263
259
let mut text_triggered = false ;
0 commit comments