Allow arbitrary code list font sizes

The point size must be between 3 and 64, inclusive, just to avoid
doing anything too weird.  Also, added 14 to the drop-down.
This commit is contained in:
Andy McFadden 2024-04-19 14:43:01 -07:00
parent 8532cfb433
commit da91d9fc0e
2 changed files with 34 additions and 11 deletions

View File

@ -56,15 +56,20 @@ limitations under the License.
</ListBox>
<TextBlock Text="Font size:" Margin="0,8,0,0"/>
<ComboBox Name="sizeComboBox" IsReadOnly="True" Margin="0,4,0,0" Width="75"
HorizontalAlignment="Left">
<!-- these are parsed directly, so only use numeric values -->
<ComboBoxItem>8</ComboBoxItem>
<ComboBoxItem>10</ComboBoxItem>
<ComboBoxItem>12</ComboBoxItem>
<ComboBoxItem>16</ComboBoxItem>
<ComboBoxItem>20</ComboBoxItem>
</ComboBox>
<StackPanel Orientation="Horizontal">
<ComboBox Name="sizeComboBox" Margin="0,4,0,0" Width="75"
HorizontalAlignment="Left" IsEditable="True">
<!-- these are parsed directly, so only use numeric values -->
<ComboBoxItem>8</ComboBoxItem>
<ComboBoxItem>10</ComboBoxItem>
<ComboBoxItem>12</ComboBoxItem>
<ComboBoxItem>14</ComboBoxItem>
<ComboBoxItem>16</ComboBoxItem>
<ComboBoxItem>20</ComboBoxItem>
</ComboBox>
<TextBlock Name="sizeErrMsg" Margin="8,6,0,0" Text="Must be an integer from 3 to 64."
Foreground="Red" Visibility="Hidden"/>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,8,0,0">
<Button Name="okButton" Content="OK" IsDefault="True"

View File

@ -44,7 +44,7 @@ namespace SourceGen.WpfGui {
GenerateMonoFontList(initialFamily);
int selIndex = 0;
int selIndex = -1;
string sizeStr = initialSize.ToString();
for (int i = 0; i < sizeComboBox.Items.Count; i++) {
ComboBoxItem item = (ComboBoxItem)sizeComboBox.Items[i];
@ -53,6 +53,10 @@ namespace SourceGen.WpfGui {
break;
}
}
if (selIndex < 0) {
// Size is not one of the standard combo box items.
sizeComboBox.Text = initialSize.ToString();
}
sizeComboBox.SelectedIndex = selIndex;
}
@ -114,7 +118,21 @@ namespace SourceGen.WpfGui {
private void OkButton_Click(object sender, RoutedEventArgs e) {
ComboBoxItem item = (ComboBoxItem)sizeComboBox.SelectedItem;
SelectedSize = int.Parse((string)item.Content);
if (item != null) {
SelectedSize = int.Parse((string)item.Content);
} else {
// Catch bad font sizes when "OK" is hit. Not as nice as disabling the OK
// button on bad input, but much simpler.
try {
SelectedSize = int.Parse(sizeComboBox.Text);
} catch (FormatException) {
SelectedSize = -1; // trigger next test
}
if (SelectedSize < 3 || SelectedSize > 64) {
sizeErrMsg.Visibility = Visibility.Visible;
return;
}
}
DialogResult = true;
}
}