@@ -2,7 +2,8 @@ mod utils;
22
33use crate :: {
44 components:: {
5- CommandBlocking , CommandInfo , Component , ScrollType ,
5+ CommandBlocking , CommandInfo , Component , DrawableComponent ,
6+ ScrollType ,
67 } ,
78 keys,
89 strings:: commands,
@@ -72,50 +73,6 @@ impl Revlog {
7273 }
7374 }
7475
75- ///
76- pub fn prepare_draw ( & mut self , area : Rect ) {
77- self . current_height = area. height . saturating_sub ( 2 ) ;
78- }
79-
80- ///
81- pub fn draw < B : Backend > ( & self , f : & mut Frame < B > , area : Rect ) {
82- let height = area. height as usize ;
83- let selection =
84- self . selection . saturating_sub ( self . items . index_offset ) ;
85- let height_d2 = height as usize / 2 ;
86- let min = selection. saturating_sub ( height_d2) ;
87-
88- let mut txt = Vec :: new ( ) ;
89- for ( idx, e) in self . items . items . iter ( ) . enumerate ( ) {
90- let tag = if let Some ( tag_name) = self . tags . get ( & e. hash ) {
91- tag_name. as_str ( )
92- } else {
93- ""
94- } ;
95- Self :: add_entry ( e, idx == selection, & mut txt, tag) ;
96- }
97-
98- let title = format ! (
99- "commit {}/{}" ,
100- self . selection, self . selection_max
101- ) ;
102-
103- f. render_widget (
104- Paragraph :: new (
105- txt. iter ( )
106- . skip ( min * ELEMENTS_PER_LINE )
107- . take ( height * ELEMENTS_PER_LINE ) ,
108- )
109- . block (
110- Block :: default ( )
111- . borders ( Borders :: ALL )
112- . title ( title. as_str ( ) ) ,
113- )
114- . alignment ( Alignment :: Left ) ,
115- area,
116- ) ;
117- }
118-
11976 ///
12077 pub fn any_work_pending ( & self ) -> bool {
12178 self . git_log . is_pending ( )
@@ -273,6 +230,48 @@ impl Revlog {
273230 }
274231}
275232
233+ impl DrawableComponent for Revlog {
234+ fn draw < B : Backend > ( & mut self , f : & mut Frame < B > , area : Rect ) {
235+ self . current_height = area. height . saturating_sub ( 2 ) ;
236+
237+ let height = area. height as usize ;
238+ let selection =
239+ self . selection . saturating_sub ( self . items . index_offset ) ;
240+ let height_d2 = height as usize / 2 ;
241+ let min = selection. saturating_sub ( height_d2) ;
242+
243+ let mut txt = Vec :: new ( ) ;
244+ for ( idx, e) in self . items . items . iter ( ) . enumerate ( ) {
245+ let tag = if let Some ( tag_name) = self . tags . get ( & e. hash ) {
246+ tag_name. as_str ( )
247+ } else {
248+ ""
249+ } ;
250+ Self :: add_entry ( e, idx == selection, & mut txt, tag) ;
251+ }
252+
253+ let title = format ! (
254+ "commit {}/{}" ,
255+ self . selection, self . selection_max
256+ ) ;
257+
258+ f. render_widget (
259+ Paragraph :: new (
260+ txt. iter ( )
261+ . skip ( min * ELEMENTS_PER_LINE )
262+ . take ( height * ELEMENTS_PER_LINE ) ,
263+ )
264+ . block (
265+ Block :: default ( )
266+ . borders ( Borders :: ALL )
267+ . title ( title. as_str ( ) ) ,
268+ )
269+ . alignment ( Alignment :: Left ) ,
270+ area,
271+ ) ;
272+ }
273+ }
274+
276275impl Component for Revlog {
277276 fn event ( & mut self , ev : Event ) -> bool {
278277 if self . visible {
0 commit comments