@@ -8,7 +8,7 @@ use crossterm::{
8
8
use ratatui:: { backend:: CrosstermBackend , Terminal } ;
9
9
10
10
use crate :: {
11
- cli:: Args , state:: { EachFrameImpl , State } , tui:: { Event , Tui } , ui:: ui, widget:: AsWeatherWidget
11
+ cli:: Args , state:: { EachFrameImpl , ShouldRender , State } , tui:: { Event , Tui } , ui:: ui, widget:: AsWeatherWidget
12
12
} ;
13
13
14
14
#[ derive( Copy , Clone ) ]
@@ -21,6 +21,7 @@ pub struct App<T> {
21
21
tui : Tui ,
22
22
state : State < T > ,
23
23
should_quit : bool ,
24
+ should_render : ShouldRender ,
24
25
args : Args ,
25
26
frame_in_second : usize ,
26
27
runtime_info : AppRuntimeInfo ,
46
47
args,
47
48
tui : Tui :: new ( args. fps as f64 , args. tps as f64 ) ?,
48
49
should_quit : false ,
50
+ should_render : ShouldRender :: Render ,
49
51
frame_in_second : 0 ,
50
52
runtime_info : AppRuntimeInfo { fps : 0 } ,
51
53
} )
64
66
Key ( key) => self . handle_keyboard ( key) ,
65
67
Tick => self . on_tick ( ) ,
66
68
Timer => self . on_timer ( ) ,
67
- Resize ( columns, rows) => self . state . on_resize ( columns, rows) ,
69
+ Resize ( columns, rows) => self . on_resize ( columns, rows) ,
68
70
} ;
69
71
} ;
70
72
83
85
}
84
86
}
85
87
88
+ fn on_resize ( & mut self , columns : u16 , rows : u16 ) {
89
+ self . state . on_resize ( columns, rows) ;
90
+ self . should_render = ShouldRender :: Render ;
91
+ }
92
+
86
93
fn on_tick ( & mut self ) {
87
- self . state . tick ( ) ;
94
+ self . should_render = self . should_render . or ( self . state . tick ( ) ) ;
88
95
self . frame_in_second = self . frame_in_second . saturating_add ( 1 ) ;
89
96
}
90
97
@@ -93,14 +100,19 @@ where
93
100
self . on_tick ( )
94
101
}
95
102
96
- self . terminal . draw ( |f| ui ( f, & mut self . state , self . args , self . runtime_info ) ) ?;
103
+ if self . should_render . is_render ( ) {
104
+ self . should_render = ShouldRender :: Skip ;
105
+ self . terminal . draw ( |f| ui ( f, & mut self . state , self . args , self . runtime_info ) ) ?;
106
+ }
107
+
97
108
Ok ( ( ) )
98
109
}
99
110
100
111
fn on_timer ( & mut self ) {
101
112
self . state . tick_timer ( ) ;
102
113
self . runtime_info . fps = self . frame_in_second ;
103
114
self . frame_in_second = 0 ;
115
+ self . should_render = ShouldRender :: Render ;
104
116
}
105
117
}
106
118
0 commit comments