Fix automatic scientific notation

This commit is contained in:
uhliksk 2019-03-07 15:59:18 +01:00
commit 0d482c5b49
23 changed files with 146 additions and 23 deletions

View file

@ -44,6 +44,7 @@ bool IsGuiSettingOpCode(WPARAM opCode)
{
case IDC_INV:
case IDC_FE:
case IDC_AE:
case IDC_MCLEAR:
case IDC_BACK:
case IDC_EXP:

View file

@ -444,14 +444,14 @@ namespace CalcEngine
return !(lhs < rhs);
}
wstring Rational::ToString(uint32_t radix, NUMOBJ_FMT fmt, int32_t precision) const
wstring Rational::ToString(uint32_t radix, NUMOBJ_FMT fmt, NUMOBJ_AUTOFMT afmt, int32_t precision) const
{
PRAT rat = this->ToPRAT();
wstring result{};
try
{
result = RatToString(rat, fmt, radix, precision);
result = RatToString(rat, fmt, afmt, radix, precision);
}
catch (DWORD error)
{

View file

@ -62,6 +62,8 @@ CCalcEngine::CCalcEngine(bool fPrecedence, bool fIntegerMode, CalculationManager
m_fIntegerMode(fIntegerMode),
m_pCalcDisplay(pCalcDisplay),
m_input(DEFAULT_DEC_SEPARATOR),
m_nFE(FMT_FLOAT),
m_nAE(AUTOFMT_ENABLED),
m_nOpCode(0),
m_nPrevOpCode(0),
m_openParenCount(0),
@ -74,7 +76,6 @@ CCalcEngine::CCalcEngine(bool fPrecedence, bool fIntegerMode, CalculationManager
m_bRecord(false),
m_bError(false),
m_bInv(false),
m_nFE(FMT_FLOAT),
m_bNoPrevEqu(true),
m_numwidth(QWORD_WIDTH),
m_angletype(ANGLE_DEG),
@ -120,7 +121,7 @@ void CCalcEngine::InitChopNumbers()
auto maxVal = m_chopNumbers[i] / 2;
maxVal = RationalMath::Integer(maxVal);
m_maxDecimalValueStrings[i] = maxVal.ToString(10, FMT_FLOAT, m_precision);
m_maxDecimalValueStrings[i] = maxVal.ToString(10, FMT_FLOAT, AUTOFMT_ENABLED, m_precision);
}
}

View file

@ -389,7 +389,7 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam)
m_precedenceOpCount = m_nTempCom = m_nLastCom = m_nOpCode = m_openParenCount = 0;
m_nPrevOpCode = 0;
m_bNoPrevEqu = true;
m_nAE = AUTOFMT_ENABLED;
/* clear the parenthesis status box indicator, this will not be
cleared for CENTR */
@ -757,6 +757,12 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam)
DisplayNum();
break;
case IDC_AE:
// Toggle automatic exponential notation display.
m_nAE = NUMOBJ_AUTOFMT(!(int)m_nAE);
DisplayNum();
break;
case IDC_EXP:
if (m_bRecord && !m_fIntegerMode && m_input.TryBeginExponent())
{
@ -1033,7 +1039,7 @@ wstring CCalcEngine::GetStringForDisplay(Rational const& rat, uint32_t radix)
// Check for standard\scientific mode
if (!m_fIntegerMode)
{
result = rat.ToString(radix, m_nFE, m_precision);
result = rat.ToString(radix, m_nFE, m_nAE, m_precision);
}
else
{
@ -1051,7 +1057,7 @@ wstring CCalcEngine::GetStringForDisplay(Rational const& rat, uint32_t radix)
tempRat = -((tempRat ^ m_chopNumbers[m_numwidth]) + 1);
}
result = tempRat.ToString(radix, m_nFE, m_precision);
result = tempRat.ToString(radix, m_nFE, m_nAE, m_precision);
}
catch (DWORD)
{

View file

@ -40,13 +40,14 @@ typedef struct {
int32_t precision;
uint32_t radix;
INT nFE;
INT nAE;
NUM_WIDTH numwidth;
bool fIntMath;
bool bRecord;
bool bUseSep;
} LASTDISP;
LASTDISP gldPrevious = { 0, -1, 0, -1, (NUM_WIDTH)-1, false, false, false };
LASTDISP gldPrevious = { 0, -1, 0, -1, -1, (NUM_WIDTH)-1, false, false, false };
// Truncates if too big, makes it a non negative - the number in rat. Doesn't do anything if not in INT mode
CalcEngine::Rational CCalcEngine::TruncateNumForIntMath(CalcEngine::Rational const& rat)
@ -87,6 +88,7 @@ void CCalcEngine::DisplayNum(void)
gldPrevious.precision != m_precision ||
gldPrevious.radix != m_radix ||
gldPrevious.nFE != (int)m_nFE ||
gldPrevious.nAE != (int)m_nAE ||
gldPrevious.bUseSep != true ||
gldPrevious.numwidth != m_numwidth ||
gldPrevious.fIntMath != m_fIntegerMode ||
@ -95,6 +97,7 @@ void CCalcEngine::DisplayNum(void)
gldPrevious.precision = m_precision;
gldPrevious.radix = m_radix;
gldPrevious.nFE = (int)m_nFE;
gldPrevious.nAE = (int)m_nAE;
gldPrevious.numwidth = m_numwidth;
gldPrevious.fIntMath = m_fIntegerMode;

View file

@ -28,6 +28,7 @@ namespace CalculationManager
m_currentDegreeMode(Command::CommandNULL),
m_savedDegreeMode(Command::CommandDEG),
m_isExponentialFormat(false),
m_isAutoExponentialFormat(true),
m_persistedPrimaryValue(),
m_currentCalculatorEngine(nullptr),
m_pStdHistory(new CalculatorHistory(CM_STD, MAX_HISTORY_ITEMS)),
@ -129,6 +130,11 @@ namespace CalculationManager
m_savedCommands.clear();
SetStandardMode();
if (!m_isAutoExponentialFormat)
{
m_isAutoExponentialFormat = true;
m_scientificCalculatorEngine->ProcessCommand(IDC_AE);
}
if (m_scientificCalculatorEngine)
{
m_scientificCalculatorEngine->ProcessCommand(IDC_DEG);
@ -248,7 +254,7 @@ namespace CalculationManager
m_currentDegreeMode = command;
}
if (command != Command::CommandFE)
if (command != Command::CommandFE && command != Command::CommandAE)
{
m_savedCommands.push_back(MapCommandForSerialize(command)); // Save the commands in the m_savedCommands
}
@ -285,6 +291,8 @@ namespace CalculationManager
break;
case Command::CommandFE:
m_isExponentialFormat = !m_isExponentialFormat;
case Command::CommandAE:
m_isAutoExponentialFormat = !m_isAutoExponentialFormat;
// fall through
default:
m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(command));

View file

@ -57,6 +57,7 @@ namespace CalculationManager
CalcEngine::Rational m_persistedPrimaryValue;
bool m_isExponentialFormat;
bool m_isAutoExponentialFormat;
static const unsigned int m_maximumMemorySize = 100;

View file

@ -99,6 +99,7 @@ namespace CalculationManager
CommandPERCENT = 118,
CommandFE = 119,
CommandAE = 148,
CommandPI = 120,
CommandEQU = 121,

View file

@ -293,7 +293,7 @@ wstring COpndCommand::GetString(uint32_t radix, int32_t precision, wchar_t decim
if (m_fInitialized)
{
result = m_value.ToString(radix, eNUMOBJ_FMT::FMT_FLOAT, precision);
result = m_value.ToString(radix, eNUMOBJ_FMT::FMT_FLOAT, eNUMOBJ_AUTOFMT::AUTOFMT_ENABLED, precision);
}
return result;

View file

@ -103,6 +103,7 @@
#define IDC_UNARYLAST IDC_PERCENT
#define IDC_FE 119
#define IDC_AE 148
#define IDC_PI 120
#define IDC_EQU 121

View file

@ -88,6 +88,7 @@ private:
bool m_bSetCalcState; //Flag for setting the engine result state
CalcEngine::CalcInput m_input; // Global calc input object for decimal strings
eNUMOBJ_FMT m_nFE; /* Scientific notation conversion flag. */
eNUMOBJ_AUTOFMT m_nAE; /* Automatic scientific notation conversion flag. */
CalcEngine::Rational m_maxTrigonometricNum;
std::unique_ptr<CalcEngine::Rational> m_memoryValue; // Current memory value.

View file

@ -64,7 +64,7 @@ namespace CalcEngine
friend bool operator<=(Rational const& lhs, Rational const& rhs);
friend bool operator>=(Rational const& lhs, Rational const& rhs);
std::wstring ToString(uint32_t radix, NUMOBJ_FMT format, int32_t precision) const;
std::wstring ToString(uint32_t radix, NUMOBJ_FMT format, NUMOBJ_AUTOFMT autoformat, int32_t precision) const;
uint64_t ToUInt64_t() const;
private:

View file

@ -1038,14 +1038,14 @@ bool stripzeroesnum(_Inout_ PNUMBER pnum, long starting)
// representation.
//
//-----------------------------------------------------------------------------
wstring NumberToString(_Inout_ PNUMBER& pnum, int format, uint32_t radix, int32_t precision)
wstring NumberToString(_Inout_ PNUMBER& pnum, int format, int autoformat, uint32_t radix, int32_t precision)
{
stripzeroesnum(pnum, precision + 2);
long length = pnum->cdigit;
long exponent = pnum->exp + length; // Actual number of digits to the left of decimal
long oldFormat = format;
if (exponent > precision && format == FMT_FLOAT)
if (exponent > precision && format == FMT_FLOAT && autoformat == AUTOFMT_ENABLED)
{
// Force scientific mode to prevent user from assuming 33rd digit is exact.
format = FMT_SCIENTIFIC;
@ -1065,7 +1065,7 @@ wstring NumberToString(_Inout_ PNUMBER& pnum, int format, uint32_t radix, int32_
// - if number is zero no rounding
// - if number of digits is less than the maximum output no rounding
PNUMBER round = nullptr;
if (!zernum(pnum) && (pnum->cdigit >= precision || (length - exponent > precision && exponent >= -MAX_ZEROS_AFTER_DECIMAL)))
if (!zernum(pnum) && (pnum->cdigit >= precision && autoformat == AUTOFMT_ENABLED || (length - exponent > precision && (exponent >= -MAX_ZEROS_AFTER_DECIMAL || autoformat == AUTOFMT_DISABLED))))
{
// Otherwise round.
round = longtonum(radix, radix);
@ -1088,9 +1088,9 @@ wstring NumberToString(_Inout_ PNUMBER& pnum, int format, uint32_t radix, int32_
if (format == FMT_FLOAT)
{
// Figure out if the exponent will fill more space than the non-exponent field.
if ((length - exponent > precision) || (exponent > precision + 3))
if ((length - exponent > precision) || (exponent > precision + 3 && autoformat == AUTOFMT_ENABLED))
{
if (exponent >= -MAX_ZEROS_AFTER_DECIMAL)
if (exponent >= -MAX_ZEROS_AFTER_DECIMAL || autoformat == AUTOFMT_DISABLED)
{
round->exp -= exponent;
length = precision + exponent;
@ -1119,7 +1119,7 @@ wstring NumberToString(_Inout_ PNUMBER& pnum, int format, uint32_t radix, int32_
{
// WARNING: nesting/recursion, too much has been changed, need to
// re-figure format.
return NumberToString(pnum, oldFormat, radix, precision);
return NumberToString(pnum, oldFormat, autoformat, radix, precision);
}
}
else
@ -1257,11 +1257,11 @@ wstring NumberToString(_Inout_ PNUMBER& pnum, int format, uint32_t radix, int32_
// why a pointer to the rational is passed in.
//
//-----------------------------------------------------------------------------
wstring RatToString(_Inout_ PRAT& prat, int format, uint32_t radix, int32_t precision)
wstring RatToString(_Inout_ PRAT& prat, int format, int autoformat, uint32_t radix, int32_t precision)
{
PNUMBER p = RatToNumber(prat, radix, precision);
wstring result = NumberToString(p, format, radix, precision);
wstring result = NumberToString(p, format, autoformat, radix, precision);
destroynum(p);
return result;

View file

@ -34,6 +34,11 @@ enum eNUMOBJ_FMT {
};
enum eNUMOBJ_AUTOFMT {
AUTOFMT_DISABLED, // never use scientific notation for FMT_FLOAT
AUTOFMT_ENABLED // use scientific notation if number is out of FMT_FLOAT range
};
enum eANGLE_TYPE {
ANGLE_DEG, // Calculate trig using 360 degrees per revolution
ANGLE_RAD, // Calculate trig using 2 pi radians per revolution
@ -42,6 +47,7 @@ enum eANGLE_TYPE {
};
typedef enum eNUMOBJ_FMT NUMOBJ_FMT;
typedef enum eNUMOBJ_AUTOFMT NUMOBJ_AUTOFMT;
typedef enum eANGLE_TYPE ANGLE_TYPE;
//-----------------------------------------------------------------------------
@ -312,10 +318,10 @@ extern bool equnum(_In_ PNUMBER a, _In_ PNUMBER b ); // returns true of a ==
extern bool lessnum(_In_ PNUMBER a, _In_ PNUMBER b ); // returns true of a < b
extern bool zernum(_In_ PNUMBER a ); // returns true of a == 0
extern bool zerrat(_In_ PRAT a ); // returns true if a == 0/q
extern std::wstring NumberToString(_Inout_ PNUMBER& pnum, int format, uint32_t radix, int32_t precision);
extern std::wstring NumberToString(_Inout_ PNUMBER& pnum, int format, int autoformat, uint32_t radix, int32_t precision);
// returns a text representation of a PRAT
extern std::wstring RatToString(_Inout_ PRAT& prat, int format, uint32_t radix, int32_t precision);
extern std::wstring RatToString(_Inout_ PRAT& prat, int format, int autoformat, uint32_t radix, int32_t precision);
// converts a PRAT into a PNUMBER
extern PNUMBER RatToNumber(_In_ PRAT prat, uint32_t radix, int32_t precision);
// flattens a PRAT by converting it to a PNUMBER and back to a PRAT

View file

@ -48,6 +48,7 @@ namespace CalculatorApp
XPower2 = (int) CM::Command::CommandSQR,
Mod = (int) CM::Command::CommandMOD,
FToE = (int) CM::Command::CommandFE,
AutoE = (int) CM::Command::CommandAE,
LogBaseE = (int) CM::Command::CommandLN,
InvSin = (int) CM::Command::CommandASIN,
InvCos = (int) CM::Command::CommandACOS,
@ -179,6 +180,7 @@ namespace CalculatorApp
XPower2 = (int) CM::Command::CommandSQR,
Mod = (int) CM::Command::CommandMOD,
FToE = (int) CM::Command::CommandFE,
AutoE = (int) CM::Command::CommandAE,
LogBaseE = (int) CM::Command::CommandLN,
InvSin = (int) CM::Command::CommandASIN,
InvCos = (int) CM::Command::CommandACOS,

View file

@ -73,6 +73,7 @@ StandardCalculatorViewModel::StandardCalculatorViewModel() :
m_MemorizedNumbers(ref new Vector<MemoryItemViewModel^>()),
m_IsMemoryEmpty(true),
m_IsFToEChecked(false),
m_IsAutoEChecked(true),
m_isShiftChecked(false),
m_IsShiftProgrammerChecked(false),
m_IsQwordEnabled(true),
@ -414,6 +415,16 @@ void StandardCalculatorViewModel::FtoEButtonToggled()
OnButtonPressed(NumbersAndOperatorsEnum::FToE);
}
void StandardCalculatorViewModel::AutoEButtonToggled()
{
OnButtonPressed(NumbersAndOperatorsEnum::AutoE);
}
void StandardCalculatorViewModel::AutoEButtonInit()
{
OnButtonInit(NumbersAndOperatorsEnum::AutoE);
}
void StandardCalculatorViewModel::HandleUpdatedOperandData(Command cmdenum)
{
DisplayExpressionToken^ displayExpressionToken = ExpressionTokens->GetAt(m_tokenPosition);
@ -553,7 +564,7 @@ bool StandardCalculatorViewModel::IsOperator(Command cmdenum)
{
if ((cmdenum == Command::Command0) || (cmdenum == Command::Command1) || (cmdenum == Command::Command2) || (cmdenum == Command::Command3) || (cmdenum == Command::Command4) || (cmdenum == Command::Command5)
|| (cmdenum == Command::Command6) || (cmdenum == Command::Command7) || (cmdenum == Command::Command8) || (cmdenum == Command::Command9) || (cmdenum == Command::CommandPNT) || (cmdenum == Command::CommandBACK)
|| (cmdenum == Command::CommandEXP) || (cmdenum == Command::CommandFE) || (cmdenum == Command::ModeBasic) || (cmdenum == Command::ModeBasic) || (cmdenum == Command::ModeProgrammer) || (cmdenum == Command::ModeScientific)
|| (cmdenum == Command::CommandEXP) || (cmdenum == Command::CommandFE) || (cmdenum == Command::CommandAE) || (cmdenum == Command::ModeBasic) || (cmdenum == Command::ModeBasic) || (cmdenum == Command::ModeProgrammer) || (cmdenum == Command::ModeScientific)
|| (cmdenum == Command::CommandINV) || (cmdenum == Command::CommandCENTR) || (cmdenum == Command::CommandDEG) || (cmdenum == Command::CommandRAD) || (cmdenum == Command::CommandGRAD)
|| ((cmdenum >= Command::CommandBINEDITSTART) && (cmdenum <= Command::CommandBINEDITEND)))
{
@ -562,6 +573,16 @@ bool StandardCalculatorViewModel::IsOperator(Command cmdenum)
return true;
}
void StandardCalculatorViewModel::OnButtonInit(Object^ parameter)
{
NumbersAndOperatorsEnum numOpEnum = CalculatorButtonPressedEventArgs::GetOperationFromCommandParameter(parameter);
if (numOpEnum == NumbersAndOperatorsEnum::AutoE)
{
m_standardCalculatorManager.SendCommand(Command::CommandCLEAR);
}
}
void StandardCalculatorViewModel::OnButtonPressed(Object^ parameter)
{
m_feedbackForButtonPress = CalculatorButtonPressedEventArgs::GetAuditoryFeedbackFromCommandParameter(parameter);
@ -586,6 +607,7 @@ void StandardCalculatorViewModel::OnButtonPressed(Object^ parameter)
numOpEnum != NumbersAndOperatorsEnum::IsStandardMode &&
numOpEnum != NumbersAndOperatorsEnum::IsProgrammerMode &&
numOpEnum != NumbersAndOperatorsEnum::FToE &&
numOpEnum != NumbersAndOperatorsEnum::AutoE &&
(numOpEnum != NumbersAndOperatorsEnum::Degree) && (numOpEnum != NumbersAndOperatorsEnum::Radians) && (numOpEnum != NumbersAndOperatorsEnum::Grads))
{
if (!m_keyPressed)
@ -622,6 +644,17 @@ void StandardCalculatorViewModel::OnButtonPressed(Object^ parameter)
IsFToEChecked = false;
}
}
if (numOpEnum == NumbersAndOperatorsEnum::Clear ||
numOpEnum == NumbersAndOperatorsEnum::ClearEntry ||
numOpEnum == NumbersAndOperatorsEnum::IsStandardMode ||
numOpEnum == NumbersAndOperatorsEnum::IsScientificMode ||
numOpEnum == NumbersAndOperatorsEnum::IsProgrammerMode)
{
if (!IsAutoEChecked)
{
IsAutoEChecked = true;
}
}
if (numOpEnum == NumbersAndOperatorsEnum::Degree || numOpEnum == NumbersAndOperatorsEnum::Radians || numOpEnum == NumbersAndOperatorsEnum::Grads)
{
m_CurrentAngleType = numOpEnum;
@ -640,6 +673,7 @@ void StandardCalculatorViewModel::OnButtonPressed(Object^ parameter)
((numOpEnum != NumbersAndOperatorsEnum::Degree) && (numOpEnum != NumbersAndOperatorsEnum::Radians) && (numOpEnum != NumbersAndOperatorsEnum::Grads)))
{
IsFToEEnabled = true;
IsAutoEEnabled = true;
m_isLastOperationHistoryLoad = false;
}
@ -1144,6 +1178,7 @@ Array<unsigned char>^ StandardCalculatorViewModel::Serialize()
DataWriter^ writer = ref new DataWriter();
writer->WriteUInt32(static_cast<UINT32>(m_CurrentAngleType));
writer->WriteBoolean(IsFToEChecked);
writer->WriteBoolean(IsAutoEChecked);
writer->WriteBoolean(IsCurrentViewPinned);
writer->WriteUInt32(static_cast<UINT32>(m_standardCalculatorManager.SerializeSavedDegreeMode()));
@ -1202,6 +1237,7 @@ void StandardCalculatorViewModel::Deserialize(Array<unsigned char>^ state)
m_CurrentAngleType = ConvertIntegerToNumbersAndOperatorsEnum(reader->ReadUInt32());
IsFToEChecked = reader->ReadBoolean();
IsAutoEChecked = reader->ReadBoolean();
IsCurrentViewPinned = reader->ReadBoolean();
Command serializedDegreeMode = static_cast<Command>(reader->ReadUInt32());
@ -1566,6 +1602,10 @@ void StandardCalculatorViewModel::Recalculate(bool fromHistory)
{
m_standardCalculatorManager.SendCommand(Command::CommandFE);
}
if (!IsAutoEChecked)
{
m_standardCalculatorManager.SendCommand(Command::CommandAE);
}
m_standardCalculatorManager.SendCommand(currentDegreeMode);
size_t currentCommandsSize = currentCommands.size();

View file

@ -72,6 +72,8 @@ namespace CalculatorApp
OBSERVABLE_PROPERTY_RW(bool, IsMemoryEmpty);
OBSERVABLE_PROPERTY_RW(bool, IsFToEChecked);
OBSERVABLE_PROPERTY_RW(bool, IsFToEEnabled);
OBSERVABLE_PROPERTY_RW(bool, IsAutoEChecked);
OBSERVABLE_PROPERTY_RW(bool, IsAutoEEnabled);
OBSERVABLE_PROPERTY_RW(bool, IsHyperbolicChecked);
OBSERVABLE_PROPERTY_RW(bool, AreHEXButtonsEnabled);
NAMED_OBSERVABLE_PROPERTY_RW(Platform::String^, CalculationResultAutomationName);
@ -226,6 +228,7 @@ namespace CalculatorApp
IsDecimalEnabled = value;
AreHEXButtonsEnabled = IsProgrammer;
IsFToEEnabled = value;
IsAutoEEnabled = value;
RaisePropertyChanged(L"IsOperandEnabled");
}
}
@ -305,6 +308,8 @@ namespace CalculatorApp
void Recalculate(bool fromHistory = false);
bool IsOperator(CalculationManager::Command cmdenum);
void FtoEButtonToggled();
void AutoEButtonToggled();
void AutoEButtonInit();
void SwitchProgrammerModeBase(RADIX_TYPE calculatorBase);
void SetMemorizedNumbersString();
void SwitchAngleType(NumbersAndOperatorsEnum num);
@ -368,6 +373,7 @@ namespace CalculatorApp
Platform::String^ GetLeftParenthesisAutomationName();
Platform::String^ m_feedbackForButtonPress;
void OnButtonInit(Platform::Object^ parameter);
void OnButtonPressed(Platform::Object^ parameter);
void OnClearMemoryCommand(Platform::Object^ parameter);
std::wstring AddPadding(std::wstring);

View file

@ -3371,4 +3371,8 @@
<value>Microsoft Services Agreement</value>
<comment>Displayed on a link to the Microsoft Services Agreement in the about this app information</comment>
</data>
<data name="autoeButton.[using:CalculatorApp.Common]KeyboardShortcutManager.VirtualKey" xml:space="preserve">
<value>B</value>
<comment>{Locked}This is the value that comes from the VirtualKey enum that represents the button. This value is not localized and must be one value that comes from the Windows::System::VirtualKey enum.</comment>
</data>
</root>

View file

@ -492,6 +492,7 @@ void Calculator::OnHistoryItemClicked(_In_ HistoryItemViewModel^ e)
Model->SetExpressionDisplay(e->GetTokens(), e->GetCommands());
Model->SetPrimaryDisplay(e->Result->Data(), false);
Model->IsFToEEnabled = false;
Model->IsAutoEEnabled = false;
TraceLogger::GetInstance().LogHistoryItemLoadEnd(tokenSize);
CloseHistoryFlyout();

View file

@ -50,6 +50,7 @@
<Setter Target="hyperbolicButton.Style" Value="{StaticResource CaptionToggleButtonSmallStyle}"/>
<Setter Target="ftoeButton.Style" Value="{StaticResource CaptionToggleButtonSmallStyle}"/>
<Setter Target="autoeButton.Style" Value="{StaticResource CaptionToggleButtonSmallStyle}"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
@ -62,6 +63,7 @@
<Setter Target="gradsButton.IsEnabled" Value="False"/>
<Setter Target="hyperbolicButton.IsEnabled" Value="False"/>
<Setter Target="ftoeButton.IsEnabled" Value="False"/>
<Setter Target="autoeButton.IsEnabled" Value="False"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
@ -116,5 +118,22 @@
<local:NumbersAndOperatorsEnum>FToE</local:NumbersAndOperatorsEnum>
</ToggleButton.CommandParameter>
</ToggleButton>
<ToggleButton x:Name="autoeButton"
x:Uid="autoeButton"
Grid.Column="3"
Style="{StaticResource CaptionToggleButtonStyle}"
Background="{ThemeResource SystemControlBackgroundTransparentBrush}"
FontWeight="SemiBold"
AutomationProperties.AutomationId="autoeButton"
Loaded="AutoEButton_Init"
Checked="AutoEButton_Toggled"
Content="Auto-E"
IsChecked="{Binding IsAutoEChecked, Mode=TwoWay}"
IsEnabled="{x:Bind Model.IsAutoEEnabled, Mode=OneWay}"
Unchecked="AutoEButton_Toggled">
<ToggleButton.CommandParameter>
<local:NumbersAndOperatorsEnum>AutoE</local:NumbersAndOperatorsEnum>
</ToggleButton.CommandParameter>
</ToggleButton>
</Grid>
</UserControl>

View file

@ -44,6 +44,25 @@ void CalculatorScientificAngleButtons::FToEButton_Toggled(_In_ Object^ sender,_I
{
auto viewModel = safe_cast<StandardCalculatorViewModel^>(this->DataContext);
viewModel->FtoEButtonToggled();
if (Model->IsFToEChecked)
{
autoeButton->Visibility = ::Visibility::Collapsed;
}
else {
autoeButton->Visibility = ::Visibility::Visible;
}
}
void CalculatorScientificAngleButtons::AutoEButton_Toggled(_In_ Object^ sender, _In_ RoutedEventArgs^ e)
{
auto viewModel = safe_cast<StandardCalculatorViewModel^>(this->DataContext);
viewModel->AutoEButtonToggled();
}
void CalculatorScientificAngleButtons::AutoEButton_Init(_In_ Object^ sender, _In_ RoutedEventArgs^ e)
{
auto viewModel = safe_cast<StandardCalculatorViewModel^>(this->DataContext);
viewModel->AutoEButtonInit();
}
void CalculatorApp::CalculatorScientificAngleButtons::OnAngleButtonPressed(_In_ Object^ commandParameter)

View file

@ -35,6 +35,8 @@ namespace CalculatorApp
private:
void OnAngleButtonPressed(_In_ Platform::Object^ commandParameter);
void FToEButton_Toggled(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs^ e);
void AutoEButton_Init(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs^ e);
void AutoEButton_Toggled(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs^ e);
void HypButton_Toggled(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs^ e);
bool m_isErrorVisualState;

View file

@ -77,6 +77,7 @@ namespace CalculatorFunctionalTests
m_standardViewModel->SetExpressionDisplay(e->GetTokens(), e->GetCommands());
m_standardViewModel->SetPrimaryDisplay(e->Result->Data(), false/*IsError*/);
m_standardViewModel->IsFToEEnabled = false;
m_standardViewModel->IsAutoEEnabled = false;
}
void AddSingleHistoryItem(unsigned int windowId = 0)