@@ -340,10 +340,13 @@ public virtual async Task InitAsync(PluginInitContext context)
340
340
this . context = context ;
341
341
await InitSettingAsync ( ) ;
342
342
}
343
- private static readonly Thickness settingControlMargin = new ( 0 , 6 , 0 , 6 ) ;
344
- private static readonly Thickness settingPanelMargin = new ( 70 , 18 , 18 , 18 ) ;
345
- private static readonly Thickness settingTextBlockMargin = new ( 0 , 6 , 0 , 6 ) ;
346
- private static readonly Thickness settingLabelMargin = new ( 0 , 0 , 18 , 0 ) ;
343
+ private static readonly Thickness settingControlMargin = new ( 0 , 9 , 18 , 9 ) ;
344
+ private static readonly Thickness settingCheckboxMargin = new ( 0 , 9 , 9 , 9 ) ;
345
+ private static readonly Thickness settingPanelMargin = new ( 0 , 0 , 0 , 0 ) ;
346
+ private static readonly Thickness settingTextBlockMargin = new ( 70 , 17 , 18 , 0 ) ;
347
+ private static readonly Thickness settingLabelMargin = new ( 70 , 0 , 18 , 0 ) ;
348
+ private static readonly Thickness settingDescMargin = new ( 70 , 0 , 18 , 0 ) ;
349
+ private static readonly Thickness settingSepMargin = new ( 0 , 0 , 0 , 2 ) ;
347
350
private JsonRpcConfigurationModel _settingsTemplate ;
348
351
349
352
public Control CreateSettingPanel ( )
@@ -355,20 +358,25 @@ public Control CreateSettingPanel()
355
358
{
356
359
Margin = settingPanelMargin
357
360
} ;
358
- ColumnDefinition gridCol1 = new ColumnDefinition ( ) { Width = GridLength . Auto } ;
361
+ ColumnDefinition gridCol1 = new ColumnDefinition ( ) ;
359
362
ColumnDefinition gridCol2 = new ColumnDefinition ( ) ;
360
- gridCol2 . Width = new GridLength ( 75 , GridUnitType . Star ) ;
363
+
364
+ gridCol1 . Width = new GridLength ( 70 , GridUnitType . Star ) ;
365
+ gridCol2 . Width = new GridLength ( 30 , GridUnitType . Star ) ;
361
366
mainPanel . ColumnDefinitions . Add ( gridCol1 ) ;
362
367
mainPanel . ColumnDefinitions . Add ( gridCol2 ) ;
363
-
364
368
settingWindow . Content = mainPanel ;
365
369
int rowCount = 0 ;
366
370
foreach ( var ( type , attribute ) in _settingsTemplate . Body )
367
371
{
368
- //var panel = new StackPanel
369
- //{
370
- //Orientation = Orientation.Horizontal, Margin = settingControlMargin
371
- //};
372
+ Separator sep = new Separator ( ) ;
373
+ sep . VerticalAlignment = VerticalAlignment . Top ;
374
+ sep . Margin = settingSepMargin ;
375
+ sep . SetResourceReference ( Separator . BackgroundProperty , "Color03B" ) ; /* for theme change */
376
+ var panel = new StackPanel
377
+ {
378
+ Orientation = Orientation . Vertical , VerticalAlignment = VerticalAlignment . Center
379
+ } ;
372
380
RowDefinition gridRow = new RowDefinition ( ) ;
373
381
mainPanel . RowDefinitions . Add ( gridRow ) ;
374
382
var name = new TextBlock ( )
@@ -378,8 +386,27 @@ public Control CreateSettingPanel()
378
386
Margin = settingLabelMargin ,
379
387
TextWrapping = TextWrapping . WrapWithOverflow
380
388
} ;
381
- Grid . SetColumn ( name , 0 ) ;
382
- Grid . SetRow ( name , rowCount ) ;
389
+ var desc = new TextBlock ( )
390
+ {
391
+ Text = attribute . Description , FontSize = 12 ,
392
+ VerticalAlignment = VerticalAlignment . Center , Margin = settingDescMargin ,
393
+ TextWrapping = TextWrapping . WrapWithOverflow
394
+ } ;
395
+ desc . SetResourceReference ( TextBlock . ForegroundProperty , "Color04B" ) ;
396
+
397
+ if ( attribute . Description == null ) /* if no description, hide */
398
+ desc . Visibility = Visibility . Collapsed ;
399
+
400
+
401
+ if ( type != "textBlock" ) /* if textBlock, hide desc */
402
+ {
403
+ panel . Children . Add ( name ) ;
404
+ panel . Children . Add ( desc ) ;
405
+ }
406
+
407
+
408
+ Grid . SetColumn ( panel , 0 ) ;
409
+ Grid . SetRow ( panel , rowCount ) ;
383
410
384
411
FrameworkElement contentControl ;
385
412
@@ -391,24 +418,28 @@ public Control CreateSettingPanel()
391
418
{
392
419
Text = attribute . Description . Replace ( "\\ r\\ n" , "\r \n " ) ,
393
420
Margin = settingTextBlockMargin ,
394
- VerticalAlignment = VerticalAlignment . Center ,
421
+ VerticalAlignment = VerticalAlignment . Stretch ,
395
422
HorizontalAlignment = HorizontalAlignment . Left ,
396
423
TextAlignment = TextAlignment . Left ,
397
424
TextWrapping = TextWrapping . WrapWithOverflow
398
425
} ;
399
426
Grid . SetColumn ( contentControl , 0 ) ;
400
427
Grid . SetColumnSpan ( contentControl , 2 ) ;
401
428
Grid . SetRow ( contentControl , rowCount ) ;
429
+ if ( rowCount != 0 )
430
+ mainPanel . Children . Add ( sep ) ;
431
+ Grid . SetRow ( sep , rowCount ) ;
432
+ Grid . SetColumn ( sep , 0 ) ;
433
+ Grid . SetColumnSpan ( sep , 2 ) ;
402
434
break ;
403
435
}
404
436
case "input" :
405
437
{
406
438
var textBox = new TextBox ( )
407
439
{
408
- Width = 300 ,
409
440
Text = Settings [ attribute . Name ] as string ?? string . Empty ,
410
441
Margin = settingControlMargin ,
411
- HorizontalAlignment = HorizontalAlignment . Left ,
442
+ HorizontalAlignment = HorizontalAlignment . Stretch ,
412
443
ToolTip = attribute . Description
413
444
} ;
414
445
textBox . TextChanged += ( _ , _ ) =>
@@ -418,18 +449,23 @@ public Control CreateSettingPanel()
418
449
contentControl = textBox ;
419
450
Grid . SetColumn ( contentControl , 1 ) ;
420
451
Grid . SetRow ( contentControl , rowCount ) ;
452
+ if ( rowCount != 0 )
453
+ mainPanel . Children . Add ( sep ) ;
454
+ Grid . SetRow ( sep , rowCount ) ;
455
+ Grid . SetColumn ( sep , 0 ) ;
456
+ Grid . SetColumnSpan ( sep , 2 ) ;
421
457
break ;
422
458
}
423
459
case "textarea" :
424
460
{
425
461
var textBox = new TextBox ( )
426
462
{
427
- Width = 300 ,
428
463
Height = 120 ,
429
464
Margin = settingControlMargin ,
465
+ VerticalAlignment = VerticalAlignment . Center ,
430
466
TextWrapping = TextWrapping . WrapWithOverflow ,
431
467
AcceptsReturn = true ,
432
- HorizontalAlignment = HorizontalAlignment . Left ,
468
+ HorizontalAlignment = HorizontalAlignment . Stretch ,
433
469
Text = Settings [ attribute . Name ] as string ?? string . Empty ,
434
470
ToolTip = attribute . Description
435
471
} ;
@@ -440,17 +476,21 @@ public Control CreateSettingPanel()
440
476
contentControl = textBox ;
441
477
Grid . SetColumn ( contentControl , 1 ) ;
442
478
Grid . SetRow ( contentControl , rowCount ) ;
479
+ if ( rowCount != 0 )
480
+ mainPanel . Children . Add ( sep ) ;
481
+ Grid . SetRow ( sep , rowCount ) ;
482
+ Grid . SetColumn ( sep , 0 ) ;
483
+ Grid . SetColumnSpan ( sep , 2 ) ;
443
484
break ;
444
485
}
445
486
case "passwordBox" :
446
487
{
447
488
var passwordBox = new PasswordBox ( )
448
489
{
449
- Width = 300 ,
450
490
Margin = settingControlMargin ,
451
491
Password = Settings [ attribute . Name ] as string ?? string . Empty ,
452
492
PasswordChar = attribute . passwordChar == default ? '*' : attribute . passwordChar ,
453
- HorizontalAlignment = HorizontalAlignment . Left ,
493
+ HorizontalAlignment = HorizontalAlignment . Stretch ,
454
494
ToolTip = attribute . Description
455
495
} ;
456
496
passwordBox . PasswordChanged += ( sender , _ ) =>
@@ -460,6 +500,11 @@ public Control CreateSettingPanel()
460
500
contentControl = passwordBox ;
461
501
Grid . SetColumn ( contentControl , 1 ) ;
462
502
Grid . SetRow ( contentControl , rowCount ) ;
503
+ if ( rowCount != 0 )
504
+ mainPanel . Children . Add ( sep ) ;
505
+ Grid . SetRow ( sep , rowCount ) ;
506
+ Grid . SetColumn ( sep , 0 ) ;
507
+ Grid . SetColumnSpan ( sep , 2 ) ;
463
508
break ;
464
509
}
465
510
case "dropdown" :
@@ -469,7 +514,7 @@ public Control CreateSettingPanel()
469
514
ItemsSource = attribute . Options ,
470
515
SelectedItem = Settings [ attribute . Name ] ,
471
516
Margin = settingControlMargin ,
472
- HorizontalAlignment = HorizontalAlignment . Left ,
517
+ HorizontalAlignment = HorizontalAlignment . Right ,
473
518
ToolTip = attribute . Description
474
519
} ;
475
520
comboBox . SelectionChanged += ( sender , _ ) =>
@@ -479,14 +524,19 @@ public Control CreateSettingPanel()
479
524
contentControl = comboBox ;
480
525
Grid . SetColumn ( contentControl , 1 ) ;
481
526
Grid . SetRow ( contentControl , rowCount ) ;
527
+ if ( rowCount != 0 )
528
+ mainPanel . Children . Add ( sep ) ;
529
+ Grid . SetRow ( sep , rowCount ) ;
530
+ Grid . SetColumn ( sep , 0 ) ;
531
+ Grid . SetColumnSpan ( sep , 2 ) ;
482
532
break ;
483
533
}
484
534
case "checkbox" :
485
535
var checkBox = new CheckBox
486
536
{
487
537
IsChecked = Settings [ attribute . Name ] is bool isChecked ? isChecked : bool . Parse ( attribute . DefaultValue ) ,
488
- Margin = settingControlMargin ,
489
- HorizontalAlignment = HorizontalAlignment . Left ,
538
+ Margin = settingCheckboxMargin ,
539
+ HorizontalAlignment = HorizontalAlignment . Right ,
490
540
ToolTip = attribute . Description
491
541
} ;
492
542
checkBox . Click += ( sender , _ ) =>
@@ -496,15 +546,21 @@ public Control CreateSettingPanel()
496
546
contentControl = checkBox ;
497
547
Grid . SetColumn ( contentControl , 1 ) ;
498
548
Grid . SetRow ( contentControl , rowCount ) ;
549
+ if ( rowCount != 0 )
550
+ mainPanel . Children . Add ( sep ) ;
551
+ Grid . SetRow ( sep , rowCount ) ;
552
+ Grid . SetColumn ( sep , 0 ) ;
553
+ Grid . SetColumnSpan ( sep , 2 ) ;
499
554
break ;
500
555
default :
501
556
continue ;
502
557
}
503
558
if ( type != "textBlock" )
504
559
_settingControls [ attribute . Name ] = contentControl ;
505
- mainPanel . Children . Add ( name ) ;
560
+ mainPanel . Children . Add ( panel ) ;
506
561
mainPanel . Children . Add ( contentControl ) ;
507
562
rowCount ++ ;
563
+
508
564
}
509
565
return settingWindow ;
510
566
}
0 commit comments