Skip to content

Commit

Permalink
Add "Use custom line height" and "Custom line height" options
Browse files Browse the repository at this point in the history
Closes #101
  • Loading branch information
rampaa committed Oct 1, 2024
1 parent f8e02ea commit 7d648a5
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
23 changes: 23 additions & 0 deletions JL.Windows/ConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ internal static class ConfigManager
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;

#endregion

Expand Down Expand Up @@ -358,6 +360,19 @@ public static void ApplyPreferences()
MaxDelayBetweenCopiesForMergingMatchingSequentialTextsInMilliseconds = ConfigDBManager.GetNumberWithDecimalPointFromConfig(connection, MaxDelayBetweenCopiesForMergingMatchingSequentialTextsInMilliseconds, nameof(MaxDelayBetweenCopiesForMergingMatchingSequentialTextsInMilliseconds), double.TryParse);
MaxNumResultsNotInMiningMode = ConfigDBManager.GetValueFromConfig(connection, MaxNumResultsNotInMiningMode, nameof(MaxNumResultsNotInMiningMode), int.TryParse);

TextBoxUseCustomLineHeight = ConfigDBManager.GetValueFromConfig(connection, TextBoxUseCustomLineHeight, nameof(TextBoxUseCustomLineHeight), bool.TryParse);
TextBoxCustomLineHeight = ConfigDBManager.GetValueFromConfig(connection, TextBoxCustomLineHeight, nameof(TextBoxCustomLineHeight), double.TryParse);
if (TextBoxUseCustomLineHeight)
{
MainWindow.Instance.MainTextBox.SetValue(TextBlock.LineStackingStrategyProperty, LineStackingStrategy.BlockLineHeight);
MainWindow.Instance.MainTextBox.SetValue(TextBlock.LineHeightProperty, TextBoxCustomLineHeight);
}
else
{
MainWindow.Instance.MainTextBox.SetValue(TextBlock.LineStackingStrategyProperty, LineStackingStrategy.MaxHeight);
MainWindow.Instance.MainTextBox.SetValue(TextBlock.LineHeightProperty, double.NaN);
}

AutoHidePopupIfMouseIsNotOverItDelayInMilliseconds = ConfigDBManager.GetNumberWithDecimalPointFromConfig(connection, AutoHidePopupIfMouseIsNotOverItDelayInMilliseconds, nameof(AutoHidePopupIfMouseIsNotOverItDelayInMilliseconds), double.TryParse);
PopupWindowUtils.PopupAutoHideTimer.Enabled = false;
PopupWindowUtils.PopupAutoHideTimer.Interval = AutoHidePopupIfMouseIsNotOverItDelayInMilliseconds;
Expand Down Expand Up @@ -848,6 +863,7 @@ public static void LoadPreferenceWindow(PreferencesWindow preferenceWindow)
preferenceWindow.TextToSpeechOnTextChangeCheckBox.IsChecked = TextToSpeechOnTextChange;
preferenceWindow.HidePopupsOnTextChangeCheckBox.IsChecked = HidePopupsOnTextChange;
preferenceWindow.MergeSequentialTextsWhenTheyMatchCheckBox.IsChecked = MergeSequentialTextsWhenTheyMatch;
preferenceWindow.TextBoxUseCustomLineHeightCheckBox.IsChecked = TextBoxUseCustomLineHeight;
preferenceWindow.ToggleHideAllTitleBarButtonsWhenMouseIsNotOverTitleBarCheckBox.IsChecked = HideAllTitleBarButtonsWhenMouseIsNotOverTitleBar;
preferenceWindow.HorizontallyCenterMainWindowTextCheckBox.IsChecked = HorizontallyCenterMainWindowText;
preferenceWindow.MainWindowFontComboBox.ItemsSource = s_japaneseFonts;
Expand Down Expand Up @@ -885,6 +901,7 @@ public static void LoadPreferenceWindow(PreferencesWindow preferenceWindow)
preferenceWindow.DeconjugationInfoFontSizeNumericUpDown.Value = DeconjugationInfoFontSize;
preferenceWindow.DictTypeFontSizeNumericUpDown.Value = DictTypeFontSize;
preferenceWindow.MaxDelayBetweenCopiesForMergingMatchingSequentialTextsInMillisecondsNumericUpDown.Value = MaxDelayBetweenCopiesForMergingMatchingSequentialTextsInMilliseconds;
preferenceWindow.TextBoxCustomLineHeightNumericUpDown.Value = TextBoxCustomLineHeight;
preferenceWindow.AutoHidePopupIfMouseIsNotOverItDelayInMillisecondsNumericUpDown.Value = AutoHidePopupIfMouseIsNotOverItDelayInMilliseconds;
preferenceWindow.DefinitionsFontSizeNumericUpDown.Value = DefinitionsFontSize;
preferenceWindow.FrequencyFontSizeNumericUpDown.Value = FrequencyFontSize;
Expand Down Expand Up @@ -1094,6 +1111,9 @@ public static async Task SavePreferences(PreferencesWindow preferenceWindow)
ConfigDBManager.UpdateSetting(connection, nameof(MergeSequentialTextsWhenTheyMatch),
preferenceWindow.MergeSequentialTextsWhenTheyMatchCheckBox.IsChecked.ToString()!);

ConfigDBManager.UpdateSetting(connection, nameof(TextBoxUseCustomLineHeight),
preferenceWindow.TextBoxUseCustomLineHeightCheckBox.IsChecked.ToString()!);

ConfigDBManager.UpdateSetting(connection, nameof(HideAllTitleBarButtonsWhenMouseIsNotOverTitleBar),
preferenceWindow.ToggleHideAllTitleBarButtonsWhenMouseIsNotOverTitleBarCheckBox.IsChecked.ToString()!);

Expand Down Expand Up @@ -1239,6 +1259,9 @@ public static async Task SavePreferences(PreferencesWindow preferenceWindow)
ConfigDBManager.UpdateSetting(connection, nameof(MaxDelayBetweenCopiesForMergingMatchingSequentialTextsInMilliseconds),
preferenceWindow.MaxDelayBetweenCopiesForMergingMatchingSequentialTextsInMillisecondsNumericUpDown.Value.ToString(CultureInfo.InvariantCulture));

ConfigDBManager.UpdateSetting(connection, nameof(TextBoxCustomLineHeight),
preferenceWindow.TextBoxCustomLineHeightNumericUpDown.Value.ToString(CultureInfo.InvariantCulture));

ConfigDBManager.UpdateSetting(connection, nameof(SeparatorColor), preferenceWindow.SeparatorColorButton.Tag.ToString()!);

ConfigDBManager.UpdateSetting(connection, nameof(DictTypeColor), preferenceWindow.DictTypeColorButton.Tag.ToString()!);
Expand Down
4 changes: 2 additions & 2 deletions JL.Windows/GUI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@

<uc:TouchScreenTextBox x:Name="MainTextBox" Margin="5,20,5,5" TextWrapping="Wrap" VerticalContentAlignment="Top" HorizontalContentAlignment="Left" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
Background="Transparent" FontSize="{Binding Value, ElementName=FontSizeSlider}"
IsReadOnly="True" BorderThickness="0,0,0,0" MouseMove="MainTextBox_MouseMove"
IsReadOnly="True" BorderThickness="0,0,0,0" MouseMove="MainTextBox_MouseMove" TextBlock.LineHeight="Auto" TextBlock.LineStackingStrategy="MaxHeight"
VerticalScrollBarVisibility="Auto" ScrollViewer.CanContentScroll="True" AutoWordSelection="False"
MouseWheel="MainTextBox_MouseWheel" Cursor="Arrow" PreviewTouchDown="MainTextBox_PreviewTouchDown" PreviewTouchUp="MainTextBox_PreviewTouchUp"
FlowDirection="LeftToRight" IsInactiveSelectionHighlightEnabled="True" IsUndoEnabled="False" UndoLimit="0"
PreviewMouseUp="MainTextBox_PreviewMouseUp" ContextMenuOpening="MainTextBox_ContextMenuOpening" AcceptsReturn="True" AcceptsTab="True">

<uc:TouchScreenTextBox.ContextMenu>
<ContextMenu Name="MainTextBoxContextMenu">
<ContextMenu Name="MainTextBoxContextMenu" TextBlock.LineHeight="Auto" TextBlock.LineStackingStrategy="MaxHeight">
<MenuItem
Name="AddNameMenuItem"
Header="Add name"
Expand Down
21 changes: 21 additions & 0 deletions JL.Windows/GUI/PreferencesWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,27 @@
<CheckBox x:Name="SteppedBacklogWithMouseWheelCheckBox" HorizontalAlignment="Right" />
</DockPanel>

<DockPanel>
<TextBlock HorizontalAlignment="Left" Text="Use custom line height"
TextWrapping="Wrap" VerticalAlignment="Center"
Style="{StaticResource TextBlockDefault}"
Cursor="Help"
ToolTip="If enabled, main window will use the specified line height below.
&#10;If disabled, the line height will be determined automatically from the current font characteristics.
&#10;Custom line height does not affect the height of the text, it changes the height of the line that contains the text.
&#10;To change the size of the text, use the Font size option.
&#10;Enabling this option is *not* recommended."/>
<CheckBox x:Name="TextBoxUseCustomLineHeightCheckBox" HorizontalAlignment="Right" />
</DockPanel>

<DockPanel>
<TextBlock HorizontalAlignment="Left" Text="Custom line height"
Style="{StaticResource TextBlockDefault}"
TextWrapping="Wrap" VerticalAlignment="Center" />
<hc:NumericUpDown x:Name="TextBoxCustomLineHeightNumericUpDown" Minimum="1" Maximum="1000" DecimalPlaces="0"
HorizontalAlignment="Right" />
</DockPanel>

</StackPanel>
</ScrollViewer>
</TabItem>
Expand Down

0 comments on commit 7d648a5

Please sign in to comment.