@@ -65,6 +65,26 @@ impl<'a> Tui<'a> {
6565 height
6666 }
6767
68+ fn calc_offset ( & self ) -> ( ( usize , usize ) , ( usize , usize , usize ) ) {
69+ let list_total = self . proc_list . collected . len ( ) ;
70+ let list_offset = self . stat . list_offset ;
71+
72+ let horizontal_total = self . proc_list . fields . len ( ) ;
73+ let mut horizontal_offset = self . stat . horizontal_offset ;
74+ let column = if horizontal_offset >= horizontal_total {
75+ horizontal_offset -= horizontal_total - 1 ;
76+ horizontal_total - 1
77+ } else {
78+ let o = horizontal_offset;
79+ horizontal_offset = 0 ;
80+ o
81+ } ;
82+ (
83+ ( list_offset, list_total) ,
84+ ( column, horizontal_total, horizontal_offset * 8 ) ,
85+ )
86+ }
87+
6888 fn render_header ( & self , area : Rect , buf : & mut Buffer ) {
6989 let constraints = vec ! [ Constraint :: Length ( 1 ) ; self . calc_header_height( ) as usize ] ;
7090 let colorful = self . stat . colorful ;
@@ -386,20 +406,30 @@ impl<'a> Tui<'a> {
386406 _ => Constraint :: Length ( 0 ) ,
387407 } ;
388408
409+ let ( list_offset, column_offset) = self . calc_offset ( ) ;
410+
389411 let constraints: Vec < Constraint > = self
390412 . proc_list
391413 . fields
392414 . iter ( )
393415 . map ( |field| build_constraint ( field) )
416+ . skip ( column_offset. 0 )
394417 . collect ( ) ;
395418
396- self . stat . list_offset = min ( self . stat . list_offset , self . proc_list . collected . len ( ) - 1 ) ;
397-
398- let header =
399- Row :: new ( self . proc_list . fields . clone ( ) ) . style ( Style :: default ( ) . bg_secondary ( colorful) ) ;
419+ let header = Row :: new ( self . proc_list . fields . clone ( ) . split_off ( column_offset. 0 ) )
420+ . style ( Style :: default ( ) . bg_secondary ( colorful) ) ;
400421
401422 let rows = self . proc_list . collected . iter ( ) . map ( |item| {
402- let cells = item. iter ( ) . enumerate ( ) . map ( |( n, c) | {
423+ let cells = item. iter ( ) . enumerate ( ) . skip ( column_offset. 0 ) . map ( |( n, c) | {
424+ let c = if column_offset. 2 > 0 {
425+ if c. len ( ) < column_offset. 2 {
426+ ""
427+ } else {
428+ & c[ column_offset. 2 ..]
429+ }
430+ } else {
431+ c
432+ } ;
403433 if highlight_sorted && n == highlight_column {
404434 Cell :: from ( Span :: styled (
405435 c,
@@ -410,13 +440,13 @@ impl<'a> Tui<'a> {
410440 } ,
411441 ) )
412442 } else {
413- Cell :: from ( c. as_str ( ) )
443+ Cell :: from ( c)
414444 }
415445 } ) ;
416446 Row :: new ( cells) . height ( 1 )
417447 } ) ;
418448
419- let mut state = TableState :: default ( ) . with_offset ( self . stat . list_offset ) ;
449+ let mut state = TableState :: default ( ) . with_offset ( list_offset. 0 ) ;
420450
421451 let table = Table :: new ( rows, constraints) . header ( header) ;
422452 StatefulWidget :: render ( table, area, buf, & mut state) ;
@@ -425,6 +455,7 @@ impl<'a> Tui<'a> {
425455
426456impl Widget for Tui < ' _ > {
427457 fn render ( mut self , area : Rect , buf : & mut Buffer ) {
458+ self . stat . list_offset = min ( self . stat . list_offset , self . proc_list . collected . len ( ) - 1 ) ;
428459 let layout = Layout :: new (
429460 Direction :: Vertical ,
430461 [
0 commit comments