Skip to content

Commit

Permalink
Add "Min dynamic height" option for the main window
Browse files Browse the repository at this point in the history
Add "Min dynamic width" option for the main window
Add "Vertical text alignment" option for the main window
Add "Min width" option for popups
Add "Min height" option for popups
  • Loading branch information
rampaa committed Oct 6, 2024
1 parent 0918362 commit 4046c39
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 17 deletions.
38 changes: 34 additions & 4 deletions JL.Windows/ConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,15 @@ internal static class ConfigManager
public static bool AlwaysShowMainTextBoxCaret { get; set; } // = false;
public static double MainWindowMaxDynamicWidth { get; set; } = 800;
public static double MainWindowMaxDynamicHeight { get; set; } = 269;
public static double MainWindowMinDynamicWidth { get; set; } = 100;
public static double MainWindowMinDynamicHeight { get; set; } = 50;
private static bool TextBoxApplyDropShadowEffect { get; set; } = true;
private static bool HorizontallyCenterMainWindowText { get; set; } // = false;
public static bool MergeSequentialTextsWhenTheyMatch { get; private set; } // = false;
public static double MaxDelayBetweenCopiesForMergingMatchingSequentialTextsInMilliseconds { get; private set; } = 5000;
public static bool TextBoxUseCustomLineHeight { get; private set; } // = false;
public static double TextBoxCustomLineHeight { get; private set; } = 75;
private static VerticalAlignment MainWindowTextVerticalAlignment { get; set; } = VerticalAlignment.Top;

#endregion

Expand All @@ -75,6 +78,8 @@ internal static class ConfigManager
public static FontFamily PopupFont { get; private set; } = new("Meiryo");
public static double PopupMaxWidth { get; set; } = 700;
public static double PopupMaxHeight { get; set; } = 520;
public static double PopupMinWidth { get; set; } // = 0;
public static double PopupMinHeight { get; set; } // = 0;
public static bool PopupDynamicHeight { get; private set; } = true;
public static bool PopupDynamicWidth { get; private set; } = true;
public static bool FixedPopupPositioning { get; private set; } // = false;
Expand Down Expand Up @@ -189,11 +194,11 @@ public static void ApplyPreferences()
string? themeStr = ConfigDBManager.GetSettingValue(connection, "Theme");
if (themeStr is null)
{
themeStr = "Dark";
themeStr = nameof(SkinType.Dark);
ConfigDBManager.InsertSetting(connection, "Theme", themeStr);
}

SkinType skinType = themeStr is "Dark" ? SkinType.Dark : SkinType.Default;
SkinType skinType = themeStr is nameof(SkinType.Dark) ? SkinType.Dark : SkinType.Default;
if (s_theme != skinType)
{
s_theme = skinType;
Expand Down Expand Up @@ -250,6 +255,9 @@ public static void ApplyPreferences()
MineMouseButton = ConfigDBManager.GetValueFromConfig(connection, MineMouseButton, nameof(MineMouseButton), Enum.TryParse);
CopyPrimarySpellingToClipboardMouseButton = ConfigDBManager.GetValueFromConfig(connection, CopyPrimarySpellingToClipboardMouseButton, nameof(CopyPrimarySpellingToClipboardMouseButton), Enum.TryParse);

MainWindowTextVerticalAlignment = ConfigDBManager.GetValueFromConfig(connection, MainWindowTextVerticalAlignment, nameof(MainWindowTextVerticalAlignment), Enum.TryParse);
MainWindow.Instance.MainTextBox.VerticalContentAlignment = MainWindowTextVerticalAlignment;

AutoAdjustFontSizesOnResolutionChange = ConfigDBManager.GetValueFromConfig(connection, AutoAdjustFontSizesOnResolutionChange, nameof(AutoAdjustFontSizesOnResolutionChange), bool.TryParse);
HighlightLongestMatch = ConfigDBManager.GetValueFromConfig(connection, HighlightLongestMatch, nameof(HighlightLongestMatch), bool.TryParse);
AutoPlayAudio = ConfigDBManager.GetValueFromConfig(connection, AutoPlayAudio, nameof(AutoPlayAudio), bool.TryParse);
Expand Down Expand Up @@ -385,6 +393,8 @@ public static void ApplyPreferences()

PopupMaxWidth = ConfigDBManager.GetNumberWithDecimalPointFromConfig(connection, PopupMaxWidth, nameof(PopupMaxWidth), double.TryParse);
PopupMaxHeight = ConfigDBManager.GetNumberWithDecimalPointFromConfig(connection, PopupMaxHeight, nameof(PopupMaxHeight), double.TryParse);
PopupMinWidth = ConfigDBManager.GetNumberWithDecimalPointFromConfig(connection, PopupMinWidth, nameof(PopupMinWidth), double.TryParse);
PopupMinHeight = ConfigDBManager.GetNumberWithDecimalPointFromConfig(connection, PopupMinHeight, nameof(PopupMinHeight), double.TryParse);

FixedPopupXPosition = ConfigDBManager.GetNumberWithDecimalPointFromConfig(connection, FixedPopupXPosition, nameof(FixedPopupXPosition), double.TryParse);
FixedPopupYPosition = ConfigDBManager.GetNumberWithDecimalPointFromConfig(connection, FixedPopupYPosition, nameof(FixedPopupYPosition), double.TryParse);
Expand All @@ -397,7 +407,9 @@ public static void ApplyPreferences()
MainWindowWidth = ConfigDBManager.GetNumberWithDecimalPointFromConfig(connection, MainWindowWidth, nameof(MainWindowWidth), double.TryParse);
MainWindowMaxDynamicWidth = ConfigDBManager.GetNumberWithDecimalPointFromConfig(connection, MainWindowMaxDynamicWidth, nameof(MainWindowMaxDynamicWidth), double.TryParse);
MainWindowMaxDynamicHeight = ConfigDBManager.GetNumberWithDecimalPointFromConfig(connection, MainWindowMaxDynamicHeight, nameof(MainWindowMaxDynamicHeight), double.TryParse);
WindowsUtils.SetSizeToContent(MainWindowDynamicWidth, MainWindowDynamicHeight, MainWindowMaxDynamicWidth, MainWindowMaxDynamicHeight, MainWindowWidth, MainWindowHeight, MainWindow.Instance);
MainWindowMinDynamicWidth = ConfigDBManager.GetNumberWithDecimalPointFromConfig(connection, MainWindowMinDynamicWidth, nameof(MainWindowMinDynamicWidth), double.TryParse);
MainWindowMinDynamicHeight = ConfigDBManager.GetNumberWithDecimalPointFromConfig(connection, MainWindowMinDynamicHeight, nameof(MainWindowMinDynamicHeight), double.TryParse);
WindowsUtils.SetSizeToContent(MainWindowDynamicWidth, MainWindowDynamicHeight, MainWindowMaxDynamicWidth, MainWindowMaxDynamicHeight, MainWindowMinDynamicWidth, MainWindowMinDynamicHeight, MainWindowWidth, MainWindowHeight, MainWindow.Instance);
MainWindow.Instance.WidthBeforeResolutionChange = MainWindowWidth;
MainWindow.Instance.HeightBeforeResolutionChange = MainWindowHeight;

Expand Down Expand Up @@ -700,7 +712,7 @@ public static void ApplyPreferences()
currentPopupWindow.Foreground = DefinitionsColor;
currentPopupWindow.FontFamily = PopupFont;

WindowsUtils.SetSizeToContent(PopupDynamicWidth, PopupDynamicHeight, PopupMaxWidth, PopupMaxHeight, currentPopupWindow);
WindowsUtils.SetSizeToContent(PopupDynamicWidth, PopupDynamicHeight, PopupMaxWidth, PopupMaxHeight, PopupMinWidth, PopupMinHeight, currentPopupWindow);

currentPopupWindow.AddNameMenuItem.SetInputGestureText(ShowAddNameWindowKeyGesture);
currentPopupWindow.AddWordMenuItem.SetInputGestureText(ShowAddWordWindowKeyGesture);
Expand Down Expand Up @@ -837,6 +849,8 @@ public static void LoadPreferenceWindow(PreferencesWindow preferenceWindow)

preferenceWindow.MainWindowMaxDynamicWidthNumericUpDown.Value = MainWindowMaxDynamicWidth;
preferenceWindow.MainWindowMaxDynamicHeightNumericUpDown.Value = MainWindowMaxDynamicHeight;
preferenceWindow.MainWindowMinDynamicWidthNumericUpDown.Value = MainWindowMinDynamicWidth;
preferenceWindow.MainWindowMinDynamicHeightNumericUpDown.Value = MainWindowMinDynamicHeight;

preferenceWindow.MainWindowHeightNumericUpDown.Value = MainWindowHeight;
preferenceWindow.MainWindowWidthNumericUpDown.Value = MainWindowWidth;
Expand Down Expand Up @@ -891,6 +905,8 @@ public static void LoadPreferenceWindow(PreferencesWindow preferenceWindow)

preferenceWindow.PopupMaxHeightNumericUpDown.Value = PopupMaxHeight;
preferenceWindow.PopupMaxWidthNumericUpDown.Value = PopupMaxWidth;
preferenceWindow.PopupMinHeightNumericUpDown.Value = PopupMinHeight;
preferenceWindow.PopupMinWidthNumericUpDown.Value = PopupMinWidth;
preferenceWindow.FixedPopupPositioningCheckBox.IsChecked = FixedPopupPositioning;
preferenceWindow.FixedPopupXPositionNumericUpDown.Value = FixedPopupXPosition;
preferenceWindow.FixedPopupYPositionNumericUpDown.Value = FixedPopupYPosition;
Expand Down Expand Up @@ -935,6 +951,7 @@ public static void LoadPreferenceWindow(PreferencesWindow preferenceWindow)
preferenceWindow.ProfileComboBox.ItemsSource = ProfileDBUtils.GetProfileNames(connection);
preferenceWindow.ProfileComboBox.SelectedItem = ProfileUtils.CurrentProfileName;
preferenceWindow.ThemeComboBox.SelectedValue = ConfigDBManager.GetSettingValue(connection, "Theme");
preferenceWindow.MainWindowTextVerticalAlignmentComboBox.SelectedValue = ConfigDBManager.GetSettingValue(connection, nameof(MainWindowTextVerticalAlignment));
preferenceWindow.MinimumLogLevelComboBox.SelectedValue = ConfigDBManager.GetSettingValue(connection, "MinimumLogLevel");
preferenceWindow.PopupPositionRelativeToCursorComboBox.SelectedValue = ConfigDBManager.GetSettingValue(connection, "PopupPositionRelativeToCursor");
preferenceWindow.PopupFlipComboBox.SelectedValue = ConfigDBManager.GetSettingValue(connection, "PopupFlip");
Expand Down Expand Up @@ -1045,6 +1062,12 @@ public static async Task SavePreferences(PreferencesWindow preferenceWindow)
ConfigDBManager.UpdateSetting(connection, nameof(MainWindowMaxDynamicHeight),
preferenceWindow.MainWindowMaxDynamicHeightNumericUpDown.Value.ToString(CultureInfo.InvariantCulture));

ConfigDBManager.UpdateSetting(connection, nameof(MainWindowMinDynamicWidth),
preferenceWindow.MainWindowMinDynamicWidthNumericUpDown.Value.ToString(CultureInfo.InvariantCulture));

ConfigDBManager.UpdateSetting(connection, nameof(MainWindowMinDynamicHeight),
preferenceWindow.MainWindowMinDynamicHeightNumericUpDown.Value.ToString(CultureInfo.InvariantCulture));

ConfigDBManager.UpdateSetting(connection, nameof(MainWindowWidth),
preferenceWindow.MainWindowWidthNumericUpDown.Value.ToString(CultureInfo.InvariantCulture));

Expand Down Expand Up @@ -1132,6 +1155,7 @@ public static async Task SavePreferences(PreferencesWindow preferenceWindow)
preferenceWindow.MainWindowOpacityNumericUpDown.Value.ToString(CultureInfo.InvariantCulture));

ConfigDBManager.UpdateSetting(connection, "Theme", preferenceWindow.ThemeComboBox.SelectedValue.ToString()!);
ConfigDBManager.UpdateSetting(connection, nameof(MainWindowTextVerticalAlignment), preferenceWindow.MainWindowTextVerticalAlignmentComboBox.SelectedValue.ToString()!);

ConfigDBManager.UpdateSetting(connection, "MinimumLogLevel", preferenceWindow.MinimumLogLevelComboBox.SelectedValue.ToString()!);

Expand Down Expand Up @@ -1200,6 +1224,12 @@ public static async Task SavePreferences(PreferencesWindow preferenceWindow)
ConfigDBManager.UpdateSetting(connection, nameof(PopupMaxHeight),
preferenceWindow.PopupMaxHeightNumericUpDown.Value.ToString(CultureInfo.InvariantCulture));

ConfigDBManager.UpdateSetting(connection, nameof(PopupMinWidth),
preferenceWindow.PopupMinWidthNumericUpDown.Value.ToString(CultureInfo.InvariantCulture));

ConfigDBManager.UpdateSetting(connection, nameof(PopupMinHeight),
preferenceWindow.PopupMinHeightNumericUpDown.Value.ToString(CultureInfo.InvariantCulture));

ConfigDBManager.UpdateSetting(connection, nameof(FixedPopupPositioning),
preferenceWindow.FixedPopupPositioningCheckBox.IsChecked.ToString()!);

Expand Down
8 changes: 5 additions & 3 deletions JL.Windows/GUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ private bool CopyText(string text)
if (!mergeTexts && SizeToContent is SizeToContent.Manual && WindowState is not WindowState.Minimized
&& (ConfigManager.MainWindowDynamicHeight || ConfigManager.MainWindowDynamicWidth))
{
WindowsUtils.SetSizeToContent(ConfigManager.MainWindowDynamicWidth, ConfigManager.MainWindowDynamicHeight, ConfigManager.MainWindowMaxDynamicWidth, ConfigManager.MainWindowMaxDynamicHeight, ConfigManager.MainWindowWidth, ConfigManager.MainWindowHeight, this);
WindowsUtils.SetSizeToContent(ConfigManager.MainWindowDynamicWidth, ConfigManager.MainWindowDynamicHeight, ConfigManager.MainWindowMaxDynamicWidth, ConfigManager.MainWindowMaxDynamicHeight, ConfigManager.MainWindowMinDynamicWidth, ConfigManager.MainWindowMinDynamicHeight, ConfigManager.MainWindowWidth, ConfigManager.MainWindowHeight, this);
}

TitleBarContextMenu.IsOpen = false;
Expand Down Expand Up @@ -1196,7 +1196,7 @@ private void AdjustWindowsSize(Screen previousActiveScreen, DpiScale previousDpi
PopupWindow? currentPopupWindow = FirstPopupWindow;
while (currentPopupWindow is not null)
{
WindowsUtils.SetSizeToContent(ConfigManager.PopupDynamicWidth, ConfigManager.PopupDynamicHeight, ConfigManager.PopupMaxWidth, ConfigManager.PopupMaxHeight, currentPopupWindow);
WindowsUtils.SetSizeToContent(ConfigManager.PopupDynamicWidth, ConfigManager.PopupDynamicHeight, ConfigManager.PopupMaxWidth, ConfigManager.PopupMaxHeight, ConfigManager.PopupMinWidth, ConfigManager.PopupMinHeight, currentPopupWindow);
currentPopupWindow = currentPopupWindow.ChildPopupWindow;
}

Expand Down Expand Up @@ -1359,6 +1359,8 @@ private void ResizeWindow(object sender, MouseButtonEventArgs e)
{
MaxWidth = double.PositiveInfinity;
MaxHeight = double.PositiveInfinity;
MinWidth = 100;
MinHeight = 50;
}

WinApi.ResizeWindow(WindowHandle, wParam);
Expand Down Expand Up @@ -1622,7 +1624,7 @@ private void Window_StateChanged(object sender, EventArgs e)

if (SizeToContent is SizeToContent.Manual && (ConfigManager.MainWindowDynamicHeight || ConfigManager.MainWindowDynamicWidth))
{
WindowsUtils.SetSizeToContent(ConfigManager.MainWindowDynamicWidth, ConfigManager.MainWindowDynamicHeight, ConfigManager.MainWindowMaxDynamicWidth, ConfigManager.MainWindowMaxDynamicHeight, ConfigManager.MainWindowWidth, ConfigManager.MainWindowHeight, this);
WindowsUtils.SetSizeToContent(ConfigManager.MainWindowDynamicWidth, ConfigManager.MainWindowDynamicHeight, ConfigManager.MainWindowMaxDynamicWidth, ConfigManager.MainWindowMaxDynamicHeight, ConfigManager.MainWindowMinDynamicWidth, ConfigManager.MainWindowMinDynamicHeight, ConfigManager.MainWindowWidth, ConfigManager.MainWindowHeight, this);
}

if (ConfigManager.AlwaysOnTop)
Expand Down
2 changes: 1 addition & 1 deletion JL.Windows/GUI/PopupWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private void Init()
Foreground = ConfigManager.DefinitionsColor;
FontFamily = ConfigManager.PopupFont;

WindowsUtils.SetSizeToContent(ConfigManager.PopupDynamicWidth, ConfigManager.PopupDynamicHeight, ConfigManager.PopupMaxWidth, ConfigManager.PopupMaxHeight, this);
WindowsUtils.SetSizeToContent(ConfigManager.PopupDynamicWidth, ConfigManager.PopupDynamicHeight, ConfigManager.PopupMaxWidth, ConfigManager.PopupMaxHeight, ConfigManager.PopupMinWidth, ConfigManager.PopupMinHeight, this);

AddNameMenuItem.SetInputGestureText(ConfigManager.ShowAddNameWindowKeyGesture);
AddWordMenuItem.SetInputGestureText(ConfigManager.ShowAddWordWindowKeyGesture);
Expand Down
Loading

0 comments on commit 4046c39

Please sign in to comment.