Add XAML and data binding code for Engineering Notation

Remove Auto and Sci enums, and unused toEngineeringNumber function

Add Button elements for Auto,SCI,ENG options

Add data binding code for Auto,SCI,ENG buttons

Add an enum member for Eng. notation command

Add EngButton method for sending Eng button command

maybe fix merge conflicts

Add IDC_ENG case for engineering notation

Add the unused toEngineeringNumber function that gets removed later on

change automationId to camelCase
This commit is contained in:
Austin Putland 2022-07-21 19:04:26 -06:00
commit 79cfa59cda
8 changed files with 90 additions and 25 deletions

View file

@ -389,7 +389,7 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam)
} }
/* Now branch off to do other commands and functions. */ /* Now branch off to do other commands and functions. */
switch (wParam) switch (wParam) //wParam
{ {
case IDC_CLEAR: /* Total clear. */ case IDC_CLEAR: /* Total clear. */
{ {
@ -780,6 +780,11 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam)
DisplayNum(); DisplayNum();
break; break;
case IDC_ENG:
m_nFE = NumberFormat::Engineering;
DisplayNum();
break;
case IDC_EXP: case IDC_EXP:
if (m_bRecord && !m_fIntegerMode && m_input.TryBeginExponent()) if (m_bRecord && !m_fIntegerMode && m_input.TryBeginExponent())
{ {

View file

@ -66,6 +66,7 @@ namespace CalculationManager
CommandGRAD = 323, CommandGRAD = 323,
CommandDegrees = 324, CommandDegrees = 324,
CommandHYP = 325, CommandHYP = 325,
CommandENG = 326,
CommandNULL = 0, CommandNULL = 0,

View file

@ -29,6 +29,7 @@
#define IDM_RAD 322 #define IDM_RAD 322
#define IDM_GRAD 323 #define IDM_GRAD 323
#define IDM_DEGREES 324 #define IDM_DEGREES 324
#define IDC_ENG 326
#define IDC_HEX IDM_HEX #define IDC_HEX IDM_HEX
#define IDC_DEC IDM_DEC #define IDC_DEC IDM_DEC

View file

@ -38,6 +38,7 @@ namespace CalculatorApp::ViewModel::Common
Radians = (int)CM::Command::CommandRAD, Radians = (int)CM::Command::CommandRAD,
Grads = (int)CM::Command::CommandGRAD, Grads = (int)CM::Command::CommandGRAD,
Degrees = (int)CM::Command::CommandDegrees, Degrees = (int)CM::Command::CommandDegrees,
Engineering = (int)CM::Command::CommandENG,
OpenParenthesis = (int)CM::Command::CommandOPENP, OpenParenthesis = (int)CM::Command::CommandOPENP,
CloseParenthesis = (int)CM::Command::CommandCLOSEP, CloseParenthesis = (int)CM::Command::CommandCLOSEP,
Pi = (int)CM::Command::CommandPI, Pi = (int)CM::Command::CommandPI,

View file

@ -448,6 +448,12 @@ void StandardCalculatorViewModel::FtoEButtonToggled()
OnButtonPressed(NumbersAndOperatorsEnum::FToE); OnButtonPressed(NumbersAndOperatorsEnum::FToE);
} }
void StandardCalculatorViewModel::EngButton()
{
OnButtonPressed(NumbersAndOperatorsEnum::Engineering);
}
void StandardCalculatorViewModel::HandleUpdatedOperandData(Command cmdenum) void StandardCalculatorViewModel::HandleUpdatedOperandData(Command cmdenum)
{ {
DisplayExpressionToken ^ displayExpressionToken = ExpressionTokens->GetAt(m_TokenPosition); DisplayExpressionToken ^ displayExpressionToken = ExpressionTokens->GetAt(m_TokenPosition);

View file

@ -258,6 +258,7 @@ namespace CalculatorApp
void SetOpenParenthesisCountNarratorAnnouncement(); void SetOpenParenthesisCountNarratorAnnouncement();
void SwitchAngleType(CalculatorApp::ViewModel::Common::NumbersAndOperatorsEnum num); void SwitchAngleType(CalculatorApp::ViewModel::Common::NumbersAndOperatorsEnum num);
void FtoEButtonToggled(); void FtoEButtonToggled();
void EngButton();
internal: internal:
void OnPaste(Platform::String ^ pastedString); void OnPaste(Platform::String ^ pastedString);

View file

@ -98,21 +98,32 @@
CommandParameter="2" CommandParameter="2"
Content="GRAD" Content="GRAD"
Visibility="Collapsed"/> Visibility="Collapsed"/>
<ToggleButton x:Name="FtoeButton"
<Button x:Name="AutoButton"
x:Uid="AutoButton"
Grid.Column="1" Grid.Column="1"
Style="{StaticResource CaptionToggleButtonWithIndicatorStyle}" Style="{StaticResource CaptionButtonSmallStyle}"
Background="{ThemeResource SystemControlBackgroundTransparentBrush}" AutomationProperties.AutomationId="autoButton"
common:KeyboardShortcutManager.VirtualKey="{utils:ResourceVirtualKey Name=ftoeButton/[using:CalculatorApp.Common]KeyboardShortcutManager/VirtualKey}" Command="{x:Bind NotationPressed}"
AutomationProperties.AutomationId="ftoeButton" CommandParameter="0"
AutomationProperties.Name="{utils:ResourceString Name=ftoeButton/[using:Windows.UI.Xaml.Automation]AutomationProperties/Name}" Content="AUTO"/>
Checked="FToEButton_Toggled" <Button x:Name="SciButton"
Content="F-E" x:Uid="SciButton"
IsChecked="{x:Bind Model.IsFToEChecked, Mode=OneWay}" Grid.Column="1"
Unchecked="FToEButton_Toggled" Style="{StaticResource CaptionButtonSmallStyle}"
IsEnabled="{x:Bind Model.IsFToEEnabled, Mode=OneWay}"> AutomationProperties.AutomationId="sciButton"
<ToggleButton.CommandParameter> Command="{x:Bind NotationPressed}"
<local:NumbersAndOperatorsEnum>FToE</local:NumbersAndOperatorsEnum> CommandParameter="1"
</ToggleButton.CommandParameter> Content="SCI"
</ToggleButton> Visibility="Collapsed"/>
<Button x:Name="EngButton"
x:Uid="EngButton"
Grid.Column="1"
Style="{StaticResource CaptionButtonSmallStyle}"
AutomationProperties.AutomationId="engButton"
Command="{x:Bind NotationPressed}"
CommandParameter="2"
Content="ENG"
Visibility="Collapsed"/>
</Grid> </Grid>
</UserControl> </UserControl>

View file

@ -17,15 +17,15 @@ namespace CalculatorApp
[Windows.Foundation.Metadata.WebHostHidden] [Windows.Foundation.Metadata.WebHostHidden]
public sealed partial class CalculatorScientificAngleButtons public sealed partial class CalculatorScientificAngleButtons
{ {
public CalculatorScientificAngleButtons() public CalculatorScientificAngleButtons() //constructor for the class
{ {
m_isErrorVisualState = false; m_isErrorVisualState = false;
InitializeComponent(); InitializeComponent(); //initializes UI components?
} }
public StandardCalculatorViewModel Model => (StandardCalculatorViewModel)this.DataContext; public StandardCalculatorViewModel Model => (StandardCalculatorViewModel)this.DataContext; //Model is an expression-bodied read-only property of StandardCalculatorViewModel type
public System.Windows.Input.ICommand ButtonPressed public System.Windows.Input.ICommand ButtonPressed //ButtonPressed is the bind source for button command? ICommand is an interface
{ {
get get
{ {
@ -66,7 +66,7 @@ namespace CalculatorApp
if (buttonId == "0") if (buttonId == "0")
{ {
Model.SwitchAngleType(NumbersAndOperatorsEnum.Radians); Model.SwitchAngleType(NumbersAndOperatorsEnum.Radians); //Model gets a viewmodel object and SwitchAngleType is a method for that object?
RadianButton.Visibility = Visibility.Visible; RadianButton.Visibility = Visibility.Visible;
RadianButton.Focus(FocusState.Programmatic); RadianButton.Focus(FocusState.Programmatic);
} }
@ -84,10 +84,49 @@ namespace CalculatorApp
} }
} }
private void FToEButton_Toggled(object sender, RoutedEventArgs e) public System.Windows.Input.ICommand NotationPressed //ButtonPressed is the bind source for button command? ICommand is an interface
{ {
var viewModel = (StandardCalculatorViewModel)this.DataContext; get
viewModel.FtoEButtonToggled(); {
if (donotuse_NotationPressed == null)
{
donotuse_NotationPressed = DelegateCommandUtils.MakeDelegateCommand(this,
(that, param) =>
{
that.OnNotationButtonPressed(param);
});
}
return donotuse_NotationPressed;
}
}
private System.Windows.Input.ICommand donotuse_NotationPressed;
private void OnNotationButtonPressed(object commandParameter)
{
string buttonId = (string)commandParameter;
AutoButton.Visibility = Visibility.Collapsed;
SciButton.Visibility = Visibility.Collapsed;
EngButton.Visibility = Visibility.Collapsed;
if (buttonId == "0")
{
Model.FtoEButtonToggled();
SciButton.Visibility = Visibility.Visible;
SciButton.Focus(FocusState.Programmatic);
}
else if (buttonId == "1")
{
Model.EngButton(); //update this to some new method
EngButton.Visibility = Visibility.Visible;
EngButton.Focus(FocusState.Programmatic);
}
else if (buttonId == "2")
{
Model.FtoEButtonToggled();
AutoButton.Visibility = Visibility.Visible;
AutoButton.Focus(FocusState.Programmatic);
}
} }
private bool m_isErrorVisualState; private bool m_isErrorVisualState;