Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix alignment of number pad buttons #2240

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Calculator/Views/CalculatorProgrammerRadixOperators.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,8 @@
Grid.Row="2"
Grid.RowSpan="4"
Grid.Column="1"
Grid.ColumnSpan="3"
Grid.ColumnSpan="4"
ExtraColumns="1"
ButtonStyle="{StaticResource NumericButtonStyle18}"
CurrentRadixType="{x:Bind Model.CurrentRadixType, Mode=OneWay}"/>
</Grid>
Expand Down
3 changes: 2 additions & 1 deletion src/Calculator/Views/CalculatorScientificOperators.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -1303,7 +1303,8 @@
Grid.Row="4"
Grid.RowSpan="4"
Grid.Column="1"
Grid.ColumnSpan="3"
Grid.ColumnSpan="4"
ExtraColumns="1"
AutomationProperties.HeadingLevel="Level1"
AutomationProperties.Name="{utils:ResourceString Name=NumberPad/[using:Windows.UI.Xaml.Automation]AutomationProperties/Name}"
ButtonStyle="{StaticResource NumericButtonStyle24}"/>
Expand Down
3 changes: 2 additions & 1 deletion src/Calculator/Views/CalculatorStandardOperators.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@
Grid.Row="2"
Grid.RowSpan="4"
Grid.Column="2"
Grid.ColumnSpan="3"
Grid.ColumnSpan="4"
ExtraColumns="1"
AutomationProperties.HeadingLevel="Level1"
AutomationProperties.Name="{utils:ResourceString Name=NumberPad/[using:Windows.UI.Xaml.Automation]AutomationProperties/Name}"
ButtonStyle="{StaticResource NumericButtonStyle24}"/>
Expand Down
38 changes: 38 additions & 0 deletions src/Calculator/Views/NumberPad.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using CalculatorApp.ViewModel.Common;

using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

Expand Down Expand Up @@ -29,6 +30,20 @@ public NumberPad()
Num9Button.Content = localizationSettings.GetDigitSymbolFromEnUsDigit('9');
}

// Extra empty columns to the right so that column widths are calculated consistently with the rest of the button panel.

public int ExtraColumns
{
get => (int)GetValue(ExtraColumnsProperty);
set => SetValue(ExtraColumnsProperty, value);
}

public static readonly DependencyProperty ExtraColumnsProperty =
DependencyProperty.Register(nameof(ExtraColumns), typeof(int), typeof(NumberPad), new PropertyMetadata(0, (sender, args) =>
{
((NumberPad)sender).OnExtraColumnsPropertyChanged((int)args.OldValue, (int)args.NewValue);
}));

public Windows.UI.Xaml.Style ButtonStyle
{
get => (Windows.UI.Xaml.Style)GetValue(ButtonStyleProperty);
Expand Down Expand Up @@ -67,6 +82,29 @@ public bool IsErrorVisualState
}
}

private void OnExtraColumnsPropertyChanged(int oldValue, int newValue)
{
if (newValue < 0)
{
throw new ArgumentException($"ExtraColumns of value {newValue} is smaller than 0.");
}
var columnDefinitions = Root.ColumnDefinitions;
if (newValue > oldValue)
{
for (int i = oldValue; i < newValue; ++i)
{
columnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) });
}
}
else
{
for (int i = oldValue; i > newValue; --i)
{
columnDefinitions.RemoveAt(columnDefinitions.Count - 1);
}
}
}

private void OnCurrentRadixTypePropertyChanged(NumberBase oldValue, NumberBase newValue)
{
Num0Button.IsEnabled = true;
Expand Down