File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -58,8 +58,18 @@ impl ListChoice {
5858
5959 pub fn render ( & mut self , app : & mut App , frame : & mut Frame ) {
6060 let area = frame. area ( ) ;
61- let dialog_area = center_widget ( area. width / 3 , area. height / 4 , area) ;
62-
61+
62+ // Calculate height dynamically: choices count + 2 (borders)
63+ let dialog_height = ( self . choices . len ( ) as u16 + 2 ) . min ( area. height ) ;
64+
65+ // Calculate width dynamically: longest choice + padding
66+ let max_choice_width = self . choices . iter ( ) . map ( |s| s. len ( ) ) . max ( ) . unwrap_or ( 0 ) as u16 ;
67+ let dialog_width = ( max_choice_width + 12 ) . max ( area. width / 3 ) . min ( area. width ) ;
68+
69+ // Calculate centered position, then shift it upwards dynamically based on height (roughly 2 lines for standard heights)
70+ let mut dialog_area = center_widget ( dialog_width, dialog_height, area) ;
71+ dialog_area. y = dialog_area. y . saturating_sub ( ( area. height / 12 ) . max ( 1 ) ) ;
72+
6373 let block = Block :: new ( )
6474 . title ( Line :: raw ( self . title . clone ( ) ) . centered ( ) )
6575 . borders ( Borders :: ALL )
You can’t perform that action at this time.
0 commit comments