mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-23 06:25:19 -07:00
Merge pull request #78 from nventive/dev/dr/ProgCalc
Add support for the programmer calculator
This commit is contained in:
commit
e3b9aca5da
2 changed files with 103 additions and 27 deletions
|
@ -22,9 +22,11 @@ using static CalculationManager.CCommand;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Globalization;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Calculator;
|
using Calculator;
|
||||||
using Windows.UI.Xaml.Input;
|
using Windows.UI.Xaml.Input;
|
||||||
|
using Uno.Extensions;
|
||||||
|
|
||||||
namespace CalculatorApp.ViewModel
|
namespace CalculatorApp.ViewModel
|
||||||
{
|
{
|
||||||
|
@ -671,7 +673,7 @@ namespace CalculatorApp.ViewModel
|
||||||
|
|
||||||
if (IsProgrammer)
|
if (IsProgrammer)
|
||||||
{
|
{
|
||||||
UpdateProgrammerPanelDisplay();
|
UpdateProgrammerPanelDisplay(displayStringValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2243,7 +2245,7 @@ namespace CalculatorApp.ViewModel
|
||||||
return padString + binaryString;
|
return padString + binaryString;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateProgrammerPanelDisplay()
|
void UpdateProgrammerPanelDisplay(string displayValue)
|
||||||
{
|
{
|
||||||
string hexDisplayString = "";
|
string hexDisplayString = "";
|
||||||
string decimalDisplayString = "";
|
string decimalDisplayString = "";
|
||||||
|
@ -2253,21 +2255,68 @@ namespace CalculatorApp.ViewModel
|
||||||
if (!IsInError)
|
if (!IsInError)
|
||||||
{
|
{
|
||||||
// we want the precision to be set to maximum value so that the varconversions result as desired
|
// we want the precision to be set to maximum value so that the varconversions result as desired
|
||||||
int precision = 64;
|
// TODO UNO -- BEGIN
|
||||||
if (m_standardCalculatorManager.GetResultForRadix(16, precision) == "")
|
var value = 0L;
|
||||||
|
var hasValue = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
displayValue = displayValue.Replace(" ", string.Empty);
|
||||||
|
switch (m_CurrentRadixType)
|
||||||
|
{
|
||||||
|
case RADIX_TYPE.HEX_RADIX:
|
||||||
|
value = Convert.ToInt64(displayValue, 16);
|
||||||
|
hasValue = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RADIX_TYPE.DEC_RADIX:
|
||||||
|
hasValue = long.TryParse(displayValue, NumberStyles.Any, CultureInfo.InvariantCulture, out value);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RADIX_TYPE.OCT_RADIX:
|
||||||
|
value = Convert.ToInt64(displayValue, 8);
|
||||||
|
hasValue = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RADIX_TYPE.BIN_RADIX:
|
||||||
|
value = Convert.ToInt64(displayValue, 2);
|
||||||
|
hasValue = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
|
||||||
|
if (hasValue && value != 0)
|
||||||
|
{
|
||||||
|
hexDisplayString = GroupBy(Convert.ToString(value, 16).ToUpperInvariant(), 4);
|
||||||
|
decimalDisplayString = value.ToString(CultureInfo.CurrentCulture);
|
||||||
|
octalDisplayString = GroupBy(Convert.ToString(value, 8), 3);
|
||||||
|
binaryDisplayString = GroupBy(Convert.ToString(value, 2), 4, '0');
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
hexDisplayString = DisplayValue;
|
hexDisplayString = DisplayValue;
|
||||||
decimalDisplayString = DisplayValue;
|
decimalDisplayString = DisplayValue;
|
||||||
octalDisplayString = DisplayValue;
|
octalDisplayString = DisplayValue;
|
||||||
binaryDisplayString = DisplayValue;
|
binaryDisplayString = DisplayValue;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
hexDisplayString = m_standardCalculatorManager.GetResultForRadix(16, precision);
|
//if (m_standardCalculatorManager.GetResultForRadix(16, precision) == "")
|
||||||
decimalDisplayString = m_standardCalculatorManager.GetResultForRadix(10, precision);
|
//{
|
||||||
octalDisplayString = m_standardCalculatorManager.GetResultForRadix(8, precision);
|
// hexDisplayString = DisplayValue;
|
||||||
binaryDisplayString = m_standardCalculatorManager.GetResultForRadix(2, precision);
|
// decimalDisplayString = DisplayValue;
|
||||||
}
|
// octalDisplayString = DisplayValue;
|
||||||
|
// binaryDisplayString = DisplayValue;
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//{
|
||||||
|
// hexDisplayString = m_standardCalculatorManager.GetResultForRadix(16, precision);
|
||||||
|
// decimalDisplayString = m_standardCalculatorManager.GetResultForRadix(10, precision);
|
||||||
|
// octalDisplayString = m_standardCalculatorManager.GetResultForRadix(8, precision);
|
||||||
|
// binaryDisplayString = m_standardCalculatorManager.GetResultForRadix(2, precision);
|
||||||
|
//}
|
||||||
|
|
||||||
|
// TODO UNO -- EBD
|
||||||
}
|
}
|
||||||
var localizer = LocalizationSettings.GetInstance();
|
var localizer = LocalizationSettings.GetInstance();
|
||||||
binaryDisplayString = AddPadding(binaryDisplayString);
|
binaryDisplayString = AddPadding(binaryDisplayString);
|
||||||
|
@ -2287,6 +2336,37 @@ namespace CalculatorApp.ViewModel
|
||||||
BinDisplayValue_AutomationName = GetLocalizedStringFormat(m_localizedBinaryAutomationFormat, GetNarratorStringReadRawNumbers(BinaryDisplayValue));
|
BinDisplayValue_AutomationName = GetLocalizedStringFormat(m_localizedBinaryAutomationFormat, GetNarratorStringReadRawNumbers(BinaryDisplayValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO UNO
|
||||||
|
private static string GroupBy(string value, int count, char? pad = null)
|
||||||
|
{
|
||||||
|
var sb = new StringBuilder(value.Length);
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(value))
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
var firstGroupLength = value.Length % count;
|
||||||
|
if (firstGroupLength > 0 && pad.HasValue)
|
||||||
|
{
|
||||||
|
sb.Append(pad.Value, count - firstGroupLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (firstGroupLength <= 0)
|
||||||
|
{
|
||||||
|
firstGroupLength = count;
|
||||||
|
}
|
||||||
|
sb.Append(value, 0, firstGroupLength);
|
||||||
|
|
||||||
|
for (var i = firstGroupLength; i < value.Length; i += count)
|
||||||
|
{
|
||||||
|
sb.Append(' ');
|
||||||
|
sb.Append(value, i, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
public void SwitchAngleType(NumbersAndOperatorsEnum num)
|
public void SwitchAngleType(NumbersAndOperatorsEnum num)
|
||||||
{
|
{
|
||||||
OnButtonPressed(num);
|
OnButtonPressed(num);
|
||||||
|
|
|
@ -107,15 +107,13 @@
|
||||||
<Grid x:Name="NormalStatesGrid">
|
<Grid x:Name="NormalStatesGrid">
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="4" />
|
<ColumnDefinition Width="4" />
|
||||||
<ColumnDefinition Width="Auto"
|
<ColumnDefinition Width="48" />
|
||||||
MinWidth="48" />
|
|
||||||
<ColumnDefinition Width="*" />
|
<ColumnDefinition Width="*" />
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
|
|
||||||
<TextBlock x:Name="ContentPresenter"
|
<TextBlock x:Name="ContentPresenter"
|
||||||
Grid.Column="2"
|
Grid.Column="2"
|
||||||
not_android:Margin="0,2,4,-2"
|
Margin="4,0,4,0"
|
||||||
android:Margin="4,0,0,0"
|
|
||||||
HorizontalAlignment="Left"
|
HorizontalAlignment="Left"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Foreground="{ThemeResource SystemControlForegroundBaseHighBrush}"
|
Foreground="{ThemeResource SystemControlForegroundBaseHighBrush}"
|
||||||
|
@ -147,8 +145,7 @@
|
||||||
Opacity="0">
|
Opacity="0">
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="4" />
|
<ColumnDefinition Width="4" />
|
||||||
<ColumnDefinition Width="Auto"
|
<ColumnDefinition Width="48" />
|
||||||
MinWidth="48" />
|
|
||||||
<ColumnDefinition Width="*" />
|
<ColumnDefinition Width="*" />
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
|
|
||||||
|
@ -161,8 +158,7 @@
|
||||||
|
|
||||||
<TextBlock x:Name="CheckedContentPresenter"
|
<TextBlock x:Name="CheckedContentPresenter"
|
||||||
Grid.Column="2"
|
Grid.Column="2"
|
||||||
not_android:Margin="0,2,4,-2"
|
Margin="4,0,4,0"
|
||||||
android:Margin="4,0,0,0"
|
|
||||||
HorizontalAlignment="Left"
|
HorizontalAlignment="Left"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Foreground="{ThemeResource SystemControlHighlightAltBaseHighBrush}"
|
Foreground="{ThemeResource SystemControlHighlightAltBaseHighBrush}"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue