From 101955fc01d037615d48e3622dabf8d7ded28c13 Mon Sep 17 00:00:00 2001 From: DB p Date: Fri, 9 Dec 2022 17:46:11 +0900 Subject: [PATCH] - Adjust JsonRPCplugin Panel Layout - Adjust System Plugin Setting Panel Margin --- Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs | 75 +++++++++++++------ .../Flow.Launcher.Plugin.Sys/SysSettings.xaml | 70 +++++++++-------- .../SysSettings.xaml.cs | 13 ++++ 3 files changed, 105 insertions(+), 53 deletions(-) diff --git a/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs b/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs index e3efcd296..28a79da5b 100644 --- a/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs +++ b/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs @@ -340,9 +340,10 @@ namespace Flow.Launcher.Core.Plugin this.context = context; await InitSettingAsync(); } - private static readonly Thickness settingControlMargin = new(10, 4, 10, 4); - private static readonly Thickness settingPanelMargin = new(15, 20, 15, 20); - private static readonly Thickness settingTextBlockMargin = new(10, 4, 10, 4); + private static readonly Thickness settingControlMargin = new(0, 6, 0, 6); + private static readonly Thickness settingPanelMargin = new(70, 18, 18, 18); + private static readonly Thickness settingTextBlockMargin = new(0, 6, 0, 6); + private static readonly Thickness settingLabelMargin = new(0, 0, 18, 0); private JsonRpcConfigurationModel _settingsTemplate; public Control CreateSettingPanel() @@ -350,26 +351,35 @@ namespace Flow.Launcher.Core.Plugin if (Settings == null) return new(); var settingWindow = new UserControl(); - var mainPanel = new StackPanel + var mainPanel = new Grid { - Margin = settingPanelMargin, Orientation = Orientation.Vertical + Margin = settingPanelMargin }; + ColumnDefinition gridCol1 = new ColumnDefinition() { Width = GridLength.Auto }; + ColumnDefinition gridCol2 = new ColumnDefinition(); + gridCol2.Width = new GridLength(75, GridUnitType.Star); + mainPanel.ColumnDefinitions.Add(gridCol1); + mainPanel.ColumnDefinitions.Add(gridCol2); + settingWindow.Content = mainPanel; - + int rowCount = 0; foreach (var (type, attribute) in _settingsTemplate.Body) { - var panel = new StackPanel - { - Orientation = Orientation.Horizontal, Margin = settingControlMargin - }; + //var panel = new StackPanel + //{ + //Orientation = Orientation.Horizontal, Margin = settingControlMargin + //}; + RowDefinition gridRow = new RowDefinition(); + mainPanel.RowDefinitions.Add(gridRow); var name = new TextBlock() { Text = attribute.Label, - Width = 120, VerticalAlignment = VerticalAlignment.Center, - Margin = settingControlMargin, + Margin = settingLabelMargin, TextWrapping = TextWrapping.WrapWithOverflow }; + Grid.SetColumn(name, 0); + Grid.SetRow(name, rowCount); FrameworkElement contentControl; @@ -381,10 +391,15 @@ namespace Flow.Launcher.Core.Plugin { Text = attribute.Description.Replace("\\r\\n", "\r\n"), Margin = settingTextBlockMargin, - MaxWidth = 500, + VerticalAlignment = VerticalAlignment.Center, + HorizontalAlignment = HorizontalAlignment.Left, + TextAlignment = TextAlignment.Left, TextWrapping = TextWrapping.WrapWithOverflow }; - break; + Grid.SetColumn(contentControl, 0); + Grid.SetColumnSpan(contentControl, 2); + Grid.SetRow(contentControl, rowCount); + break; } case "input": { @@ -393,6 +408,7 @@ namespace Flow.Launcher.Core.Plugin Width = 300, Text = Settings[attribute.Name] as string ?? string.Empty, Margin = settingControlMargin, + HorizontalAlignment = HorizontalAlignment.Left, ToolTip = attribute.Description }; textBox.TextChanged += (_, _) => @@ -400,7 +416,9 @@ namespace Flow.Launcher.Core.Plugin Settings[attribute.Name] = textBox.Text; }; contentControl = textBox; - break; + Grid.SetColumn(contentControl, 1); + Grid.SetRow(contentControl, rowCount); + break; } case "textarea": { @@ -411,6 +429,7 @@ namespace Flow.Launcher.Core.Plugin Margin = settingControlMargin, TextWrapping = TextWrapping.WrapWithOverflow, AcceptsReturn = true, + HorizontalAlignment = HorizontalAlignment.Left, Text = Settings[attribute.Name] as string ?? string.Empty, ToolTip = attribute.Description }; @@ -419,7 +438,9 @@ namespace Flow.Launcher.Core.Plugin Settings[attribute.Name] = ((TextBox)sender).Text; }; contentControl = textBox; - break; + Grid.SetColumn(contentControl, 1); + Grid.SetRow(contentControl, rowCount); + break; } case "passwordBox": { @@ -429,6 +450,7 @@ namespace Flow.Launcher.Core.Plugin Margin = settingControlMargin, Password = Settings[attribute.Name] as string ?? string.Empty, PasswordChar = attribute.passwordChar == default ? '*' : attribute.passwordChar, + HorizontalAlignment = HorizontalAlignment.Left, ToolTip = attribute.Description }; passwordBox.PasswordChanged += (sender, _) => @@ -436,7 +458,9 @@ namespace Flow.Launcher.Core.Plugin Settings[attribute.Name] = ((PasswordBox)sender).Password; }; contentControl = passwordBox; - break; + Grid.SetColumn(contentControl, 1); + Grid.SetRow(contentControl, rowCount); + break; } case "dropdown": { @@ -445,6 +469,7 @@ namespace Flow.Launcher.Core.Plugin ItemsSource = attribute.Options, SelectedItem = Settings[attribute.Name], Margin = settingControlMargin, + HorizontalAlignment = HorizontalAlignment.Left, ToolTip = attribute.Description }; comboBox.SelectionChanged += (sender, _) => @@ -452,13 +477,16 @@ namespace Flow.Launcher.Core.Plugin Settings[attribute.Name] = (string)((ComboBox)sender).SelectedItem; }; contentControl = comboBox; - break; + Grid.SetColumn(contentControl, 1); + Grid.SetRow(contentControl, rowCount); + break; } case "checkbox": var checkBox = new CheckBox { IsChecked = Settings[attribute.Name] is bool isChecked ? isChecked : bool.Parse(attribute.DefaultValue), Margin = settingControlMargin, + HorizontalAlignment = HorizontalAlignment.Left, ToolTip = attribute.Description }; checkBox.Click += (sender, _) => @@ -466,15 +494,20 @@ namespace Flow.Launcher.Core.Plugin Settings[attribute.Name] = ((CheckBox)sender).IsChecked; }; contentControl = checkBox; + Grid.SetColumn(contentControl, 1); + Grid.SetRow(contentControl, rowCount); break; default: continue; } if (type != "textBlock") _settingControls[attribute.Name] = contentControl; - panel.Children.Add(name); - panel.Children.Add(contentControl); - mainPanel.Children.Add(panel); + //panel.Children.Add(name); + //panel.Children.Add(contentControl); + //mainPanel.Children.Add(panel); + mainPanel.Children.Add(name); + mainPanel.Children.Add(contentControl); + rowCount++; } return settingWindow; } diff --git a/Plugins/Flow.Launcher.Plugin.Sys/SysSettings.xaml b/Plugins/Flow.Launcher.Plugin.Sys/SysSettings.xaml index 66aa34b2a..f806900de 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/SysSettings.xaml +++ b/Plugins/Flow.Launcher.Plugin.Sys/SysSettings.xaml @@ -1,33 +1,39 @@ - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Plugins/Flow.Launcher.Plugin.Sys/SysSettings.xaml.cs b/Plugins/Flow.Launcher.Plugin.Sys/SysSettings.xaml.cs index cdcc977a9..b5f1531c3 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/SysSettings.xaml.cs +++ b/Plugins/Flow.Launcher.Plugin.Sys/SysSettings.xaml.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Windows; using System.Windows.Controls; namespace Flow.Launcher.Plugin.Sys @@ -14,5 +15,17 @@ namespace Flow.Launcher.Plugin.Sys lbxCommands.Items.Add(Result); } } + private void ListView_SizeChanged(object sender, SizeChangedEventArgs e) + { + ListView listView = sender as ListView; + GridView gView = listView.View as GridView; + + var workingWidth = listView.ActualWidth - SystemParameters.VerticalScrollBarWidth; // take into account vertical scrollbar + var col1 = 0.3; + var col2 = 0.7; + + gView.Columns[0].Width = workingWidth * col1; + gView.Columns[1].Width = workingWidth * col2; + } } }