@@ -5,10 +5,10 @@ use tunet_helper::NetState;
55use tunet_model:: { Action , Model , UpdateMsg } ;
66use tunet_settings:: SettingsReader ;
77use winio:: {
8- init, start, App , BrushPen , Button , ButtonEvent , Canvas , Child , Color , ComboBox , ComboBoxEvent ,
9- Component , ComponentSender , Edit , Enable , Grid , HAlign , Label , Layoutable , Margin , MessageBox ,
10- MessageBoxButton , MessageBoxResponse , MessageBoxStyle , Monitor , Point , Rect , Size ,
11- SolidColorBrush , VAlign , Visible , Window , WindowEvent ,
8+ init, layout , start, App , BrushPen , Button , ButtonEvent , Canvas , Child , Color , ComboBox ,
9+ ComboBoxEvent , Component , ComponentSender , Edit , Enable , Grid , HAlign , Label , Layoutable ,
10+ Margin , MessageBox , MessageBoxButton , MessageBoxResponse , MessageBoxStyle , Monitor , Point ,
11+ Rect , Size , SolidColorBrush , VAlign , Visible , Window , WindowEvent ,
1212} ;
1313
1414fn main ( ) {
@@ -319,159 +319,47 @@ impl Component for MainModel {
319319 }
320320
321321 fn render ( & mut self , _sender : & ComponentSender < Self > ) {
322- let margin = Margin :: new_all_same ( 4.0 ) ;
323-
324322 let csize = self . window . client_size ( ) ;
325323 {
326- let mut grid =
327- Grid :: from_str ( "1*,1*,1*" , "auto,auto,1*,auto,auto,auto,auto,auto" ) . unwrap ( ) ;
328- grid. push ( & mut self . state_combo )
329- . column ( 0 )
330- . column_span ( 3 )
331- . row ( 0 )
332- . margin ( margin)
333- . finish ( ) ;
334-
335- grid. push ( & mut self . canvas )
336- . column ( 0 )
337- . column_span ( 3 )
338- . row ( 1 )
339- . row_span ( 3 )
340- . margin ( margin)
341- . finish ( ) ;
342-
343- grid. push ( & mut self . hidden )
344- . column ( 0 )
345- . column_span ( 3 )
346- . row ( 1 )
347- . margin ( margin)
348- . finish ( ) ;
349-
350- let mut flux_grid = Grid :: from_str ( "1*" , "1*,1*,1*,1*,1*" ) . unwrap ( ) ;
351- flux_grid
352- . push ( & mut self . username )
353- . column ( 0 )
354- . row ( 0 )
355- . margin ( margin)
356- . finish ( ) ;
357- flux_grid
358- . push ( & mut self . flux )
359- . column ( 0 )
360- . row ( 1 )
361- . margin ( margin)
362- . finish ( ) ;
363- flux_grid
364- . push ( & mut self . online_time )
365- . column ( 0 )
366- . row ( 2 )
367- . margin ( margin)
368- . finish ( ) ;
369- flux_grid
370- . push ( & mut self . balance )
371- . column ( 0 )
372- . row ( 3 )
373- . margin ( margin)
374- . finish ( ) ;
375- flux_grid
376- . push ( & mut self . status )
377- . column ( 0 )
378- . row ( 4 )
379- . margin ( margin)
380- . finish ( ) ;
381-
382- grid. push ( & mut flux_grid)
383- . column ( 0 )
384- . column_span ( 3 )
385- . row ( 2 )
386- . halign ( HAlign :: Center )
387- . valign ( VAlign :: Center )
388- . finish ( ) ;
389-
390- grid. push ( & mut self . log )
391- . column ( 0 )
392- . column_span ( 3 )
393- . row ( 3 )
394- . margin ( margin)
395- . finish ( ) ;
396-
397- grid. push ( & mut self . login_button )
398- . column ( 0 )
399- . row ( 4 )
400- . margin ( margin)
401- . finish ( ) ;
402- grid. push ( & mut self . logout_button )
403- . column ( 1 )
404- . row ( 4 )
405- . margin ( margin)
406- . finish ( ) ;
407- grid. push ( & mut self . refresh_button )
408- . column ( 2 )
409- . row ( 4 )
410- . margin ( margin)
411- . finish ( ) ;
412-
413- let mut cred_grid = Grid :: from_str ( "auto,1*,auto" , "1*,1*" ) . unwrap ( ) ;
324+ let margin = Margin :: new_all_same ( 4.0 ) ;
414325 let mut label_margin = margin;
415326 label_margin. right = 0.0 ;
416327 let mut input_margin = margin;
417328 input_margin. left = 0.0 ;
418- cred_grid
419- . push ( & mut self . username_label )
420- . column ( 0 )
421- . row ( 0 )
422- . valign ( VAlign :: Center )
423- . margin ( label_margin)
424- . finish ( ) ;
425- cred_grid
426- . push ( & mut self . password_label )
427- . column ( 0 )
428- . row ( 1 )
429- . valign ( VAlign :: Center )
430- . margin ( label_margin)
431- . finish ( ) ;
432- cred_grid
433- . push ( & mut self . username_input )
434- . column ( 1 )
435- . row ( 0 )
436- . margin ( input_margin)
437- . finish ( ) ;
438- cred_grid
439- . push ( & mut self . password_input )
440- . column ( 1 )
441- . row ( 1 )
442- . margin ( input_margin)
443- . finish ( ) ;
444- cred_grid
445- . push ( & mut self . cred_button )
446- . column ( 2 )
447- . row ( 0 )
448- . margin ( margin)
449- . finish ( ) ;
450- cred_grid
451- . push ( & mut self . del_button )
452- . column ( 2 )
453- . row ( 1 )
454- . margin ( margin)
455- . finish ( ) ;
456329
457- grid. push ( & mut cred_grid)
458- . column ( 0 )
459- . column_span ( 3 )
460- . row ( 5 )
461- . finish ( ) ;
330+ let mut flux_grid = layout ! {
331+ Grid :: from_str( "1*" , "1*,1*,1*,1*,1*" ) . unwrap( ) ,
332+ self . username => { column: 0 , row: 0 , margin: margin } ,
333+ self . flux => { column: 0 , row: 1 , margin: margin } ,
334+ self . online_time => { column: 0 , row: 2 , margin: margin } ,
335+ self . balance => { column: 0 , row: 3 , margin: margin } ,
336+ self . status => { column: 0 , row: 4 , margin: margin } ,
337+ } ;
338+
339+ let mut cred_grid = layout ! {
340+ Grid :: from_str( "auto,1*,auto" , "1*,1*" ) . unwrap( ) ,
341+ self . username_label => { column: 0 , row: 0 , valign: VAlign :: Center , margin: label_margin } ,
342+ self . password_label => { column: 0 , row: 1 , valign: VAlign :: Center , margin: label_margin } ,
343+ self . username_input => { column: 1 , row: 0 , margin: input_margin } ,
344+ self . password_input => { column: 1 , row: 1 , margin: input_margin } ,
345+ self . cred_button => { column: 2 , row: 0 , margin: margin } ,
346+ self . del_button => { column: 2 , row: 1 , margin: margin } ,
347+ } ;
462348
463- grid. push ( & mut self . info1 )
464- . column ( 0 )
465- . column_span ( 3 )
466- . row ( 6 )
467- . margin ( margin)
468- . finish ( ) ;
469- grid. push ( & mut self . info2 )
470- . column ( 0 )
471- . column_span ( 3 )
472- . row ( 7 )
473- . margin ( margin)
474- . finish ( ) ;
349+ let mut grid = layout ! {
350+ Grid :: from_str( "1*,1*,1*" , "auto,auto,1*,auto,auto,auto,auto,auto" ) . unwrap( ) ,
351+ self . state_combo => { column: 0 , column_span: 3 , row: 0 , margin: margin } ,
352+ self . hidden => { column: 0 , column_span: 3 , row: 1 , margin: margin } ,
353+ self . canvas => { column: 0 , column_span: 3 , row: 1 , row_span: 3 , margin: margin } ,
354+ flux_grid => { column: 0 , column_span: 3 , row: 2 , halign: HAlign :: Center , valign: VAlign :: Center } ,
355+ self . log => { column: 0 , column_span: 3 , row: 3 , margin: margin } ,
356+ self . login_button => { column: 0 , row: 4 , margin: margin } ,
357+ self . logout_button => { column: 1 , row: 4 , margin: margin } ,
358+ self . refresh_button => { column: 2 , row: 4 , margin: margin } ,
359+ cred_grid => { column: 0 , column_span: 3 , row: 5 } ,
360+ self . info1 => { column: 0 , column_span: 3 , row: 6 , margin: margin } ,
361+ self . info2 => { column: 0 , column_span: 3 , row: 7 , margin: margin } ,
362+ } ;
475363
476364 grid. set_size ( csize) ;
477365 }
0 commit comments