Skip to content

Commit ba3ed35

Browse files
committed
- Adjust JsonRPC Panel Design
1 parent 92c068d commit ba3ed35

File tree

1 file changed

+80
-24
lines changed

1 file changed

+80
-24
lines changed

Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs

Lines changed: 80 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -340,10 +340,13 @@ public virtual async Task InitAsync(PluginInitContext context)
340340
this.context = context;
341341
await InitSettingAsync();
342342
}
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);
347350
private JsonRpcConfigurationModel _settingsTemplate;
348351

349352
public Control CreateSettingPanel()
@@ -355,20 +358,25 @@ public Control CreateSettingPanel()
355358
{
356359
Margin = settingPanelMargin
357360
};
358-
ColumnDefinition gridCol1 = new ColumnDefinition() { Width = GridLength.Auto };
361+
ColumnDefinition gridCol1 = new ColumnDefinition();
359362
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);
361366
mainPanel.ColumnDefinitions.Add(gridCol1);
362367
mainPanel.ColumnDefinitions.Add(gridCol2);
363-
364368
settingWindow.Content = mainPanel;
365369
int rowCount = 0;
366370
foreach (var (type, attribute) in _settingsTemplate.Body)
367371
{
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+
};
372380
RowDefinition gridRow = new RowDefinition();
373381
mainPanel.RowDefinitions.Add(gridRow);
374382
var name = new TextBlock()
@@ -378,8 +386,27 @@ public Control CreateSettingPanel()
378386
Margin = settingLabelMargin,
379387
TextWrapping = TextWrapping.WrapWithOverflow
380388
};
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);
383410

384411
FrameworkElement contentControl;
385412

@@ -391,24 +418,28 @@ public Control CreateSettingPanel()
391418
{
392419
Text = attribute.Description.Replace("\\r\\n", "\r\n"),
393420
Margin = settingTextBlockMargin,
394-
VerticalAlignment = VerticalAlignment.Center,
421+
VerticalAlignment = VerticalAlignment.Stretch,
395422
HorizontalAlignment = HorizontalAlignment.Left,
396423
TextAlignment = TextAlignment.Left,
397424
TextWrapping = TextWrapping.WrapWithOverflow
398425
};
399426
Grid.SetColumn(contentControl, 0);
400427
Grid.SetColumnSpan(contentControl, 2);
401428
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);
402434
break;
403435
}
404436
case "input":
405437
{
406438
var textBox = new TextBox()
407439
{
408-
Width = 300,
409440
Text = Settings[attribute.Name] as string ?? string.Empty,
410441
Margin = settingControlMargin,
411-
HorizontalAlignment = HorizontalAlignment.Left,
442+
HorizontalAlignment = HorizontalAlignment.Stretch,
412443
ToolTip = attribute.Description
413444
};
414445
textBox.TextChanged += (_, _) =>
@@ -418,18 +449,23 @@ public Control CreateSettingPanel()
418449
contentControl = textBox;
419450
Grid.SetColumn(contentControl, 1);
420451
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);
421457
break;
422458
}
423459
case "textarea":
424460
{
425461
var textBox = new TextBox()
426462
{
427-
Width = 300,
428463
Height = 120,
429464
Margin = settingControlMargin,
465+
VerticalAlignment = VerticalAlignment.Center,
430466
TextWrapping = TextWrapping.WrapWithOverflow,
431467
AcceptsReturn = true,
432-
HorizontalAlignment = HorizontalAlignment.Left,
468+
HorizontalAlignment = HorizontalAlignment.Stretch,
433469
Text = Settings[attribute.Name] as string ?? string.Empty,
434470
ToolTip = attribute.Description
435471
};
@@ -440,17 +476,21 @@ public Control CreateSettingPanel()
440476
contentControl = textBox;
441477
Grid.SetColumn(contentControl, 1);
442478
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);
443484
break;
444485
}
445486
case "passwordBox":
446487
{
447488
var passwordBox = new PasswordBox()
448489
{
449-
Width = 300,
450490
Margin = settingControlMargin,
451491
Password = Settings[attribute.Name] as string ?? string.Empty,
452492
PasswordChar = attribute.passwordChar == default ? '*' : attribute.passwordChar,
453-
HorizontalAlignment = HorizontalAlignment.Left,
493+
HorizontalAlignment = HorizontalAlignment.Stretch,
454494
ToolTip = attribute.Description
455495
};
456496
passwordBox.PasswordChanged += (sender, _) =>
@@ -460,6 +500,11 @@ public Control CreateSettingPanel()
460500
contentControl = passwordBox;
461501
Grid.SetColumn(contentControl, 1);
462502
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);
463508
break;
464509
}
465510
case "dropdown":
@@ -469,7 +514,7 @@ public Control CreateSettingPanel()
469514
ItemsSource = attribute.Options,
470515
SelectedItem = Settings[attribute.Name],
471516
Margin = settingControlMargin,
472-
HorizontalAlignment = HorizontalAlignment.Left,
517+
HorizontalAlignment = HorizontalAlignment.Right,
473518
ToolTip = attribute.Description
474519
};
475520
comboBox.SelectionChanged += (sender, _) =>
@@ -479,14 +524,19 @@ public Control CreateSettingPanel()
479524
contentControl = comboBox;
480525
Grid.SetColumn(contentControl, 1);
481526
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);
482532
break;
483533
}
484534
case "checkbox":
485535
var checkBox = new CheckBox
486536
{
487537
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,
490540
ToolTip = attribute.Description
491541
};
492542
checkBox.Click += (sender, _) =>
@@ -496,15 +546,21 @@ public Control CreateSettingPanel()
496546
contentControl = checkBox;
497547
Grid.SetColumn(contentControl, 1);
498548
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);
499554
break;
500555
default:
501556
continue;
502557
}
503558
if (type != "textBlock")
504559
_settingControls[attribute.Name] = contentControl;
505-
mainPanel.Children.Add(name);
560+
mainPanel.Children.Add(panel);
506561
mainPanel.Children.Add(contentControl);
507562
rowCount++;
563+
508564
}
509565
return settingWindow;
510566
}

0 commit comments

Comments
 (0)