@@ -2,9 +2,9 @@ use crate::bluetooth::Controller;
22use ratatui:: {
33 Frame ,
44 layout:: { Alignment , Constraint , Layout , Rect } ,
5- style:: { Color , Modifier , Style , Stylize } ,
6- text:: { Line , Span } ,
7- widgets:: { Block , BorderType , Borders , Clear , Padding , Paragraph , TableState } ,
5+ style:: { Color , Style , Stylize } ,
6+ text:: Line ,
7+ widgets:: { Block , BorderType , Clear , Padding , Paragraph , TableState } ,
88} ;
99use tui_input:: Input ;
1010
@@ -16,21 +16,9 @@ pub fn render_set_alias(
1616 frame : & mut Frame ,
1717 area : Rect ,
1818) {
19- let block = Layout :: vertical ( [
20- Constraint :: Fill ( 1 ) ,
21- Constraint :: Length ( 6 ) ,
22- Constraint :: Fill ( 1 ) ,
23- ] )
24- . split ( area) ;
19+ let center_cutout = area. centered ( Constraint :: Max ( 70 ) , Constraint :: Length ( 6 ) ) ;
2520
26- let block = Layout :: horizontal ( [
27- Constraint :: Fill ( 1 ) ,
28- Constraint :: Max ( 70 ) ,
29- Constraint :: Fill ( 1 ) ,
30- ] )
31- . split ( block[ 1 ] ) [ 1 ] ;
32-
33- let ( text_block, alias_block) = {
21+ let ( text_block, alias_input_block) = {
3422 let chunks = Layout :: vertical (
3523 [
3624 Constraint :: Length ( 1 ) ,
@@ -40,7 +28,7 @@ pub fn render_set_alias(
4028 ]
4129 . as_ref ( ) ,
4230 )
43- . split ( block ) ;
31+ . split ( center_cutout ) ;
4432
4533 let area1 = Layout :: horizontal (
4634 [
@@ -65,45 +53,33 @@ pub fn render_set_alias(
6553 ( area1[ 1 ] , area2[ 1 ] )
6654 } ;
6755
68- frame. render_widget ( Clear , block ) ;
56+ frame. render_widget ( Clear , center_cutout ) ;
6957 frame. render_widget (
70- Block :: new ( )
71- . borders ( Borders :: ALL )
58+ Block :: bordered ( )
7259 . border_type ( BorderType :: Thick )
73- . style ( Style :: default ( ) . green ( ) )
74- . border_style ( Style :: default ( ) . fg ( Color :: Green ) ) ,
75- block,
60+ . border_style ( Style :: default ( ) . green ( ) ) ,
61+ center_cutout,
7662 ) ;
7763
7864 if let Some ( selected_controller) = controller_state. selected ( ) {
7965 let controller = & controllers[ selected_controller] ;
8066 if let Some ( index) = paired_devices_state. selected ( ) {
8167 let name = controller. paired_devices [ index] . alias . as_str ( ) ;
8268
83- let text = Line :: from ( vec ! [
84- Span :: from( "Enter the new name for " ) ,
85- Span :: styled(
86- name,
87- Style :: default ( ) . add_modifier( Modifier :: BOLD | Modifier :: ITALIC ) ,
88- ) ,
89- ] ) ;
69+ let message_line =
70+ Line :: from ( vec ! [ "Enter the new name for " . into( ) , name. bold( ) . italic( ) ] ) ;
9071
91- let msg = Paragraph :: new ( text)
92- . alignment ( Alignment :: Center )
93- . style ( Style :: default ( ) . fg ( Color :: White ) )
72+ let message_paragraph = Paragraph :: new ( message_line)
73+ . centered ( )
9474 . block ( Block :: new ( ) . padding ( Padding :: horizontal ( 2 ) ) ) ;
9575
96- let alias = Paragraph :: new ( new_alias. value ( ) )
76+ let alias_input = Paragraph :: new ( new_alias. value ( ) )
9777 . alignment ( Alignment :: Left )
9878 . style ( Style :: default ( ) . fg ( Color :: White ) )
99- . block (
100- Block :: new ( )
101- . bg ( Color :: DarkGray )
102- . padding ( Padding :: horizontal ( 2 ) ) ,
103- ) ;
79+ . block ( Block :: new ( ) . on_dark_gray ( ) . padding ( Padding :: horizontal ( 2 ) ) ) ;
10480
105- frame. render_widget ( msg , text_block) ;
106- frame. render_widget ( alias , alias_block ) ;
81+ frame. render_widget ( message_paragraph , text_block) ;
82+ frame. render_widget ( alias_input , alias_input_block ) ;
10783 }
10884 }
10985}
0 commit comments