[Graph] Replace the Add button by a EquationTextBlock (#826)

* init

* Replace the Add equation button by an EquationTextBox

* Move automatically the focus to the next textbox when users press Enter

* nit

* localize the placeholder

* rebase

* rebased and disable remove context menu when the equation is the last one

* replace storyboards by setters in visual states
This commit is contained in:
Rudy Huyn 2019-12-10 11:06:37 -08:00 committed by Pepe Rivera
parent f1bf3354c4
commit 07d012cf6b
12 changed files with 449 additions and 281 deletions

View File

@ -41,6 +41,7 @@ public
OBSERVABLE_OBJECT();
OBSERVABLE_PROPERTY_R(GraphControl::Equation ^, GraphEquation);
OBSERVABLE_PROPERTY_RW(int, FunctionLabelIndex);
OBSERVABLE_PROPERTY_RW(bool, IsLastItemInList);
property Platform::String ^ Expression
{

View File

@ -3,6 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Controls="using:CalculatorApp.Controls"
xmlns:common="using:CalculatorApp.Common"
xmlns:contract7Present="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract,7)"
xmlns:local="using:CalculatorApp">
<Application.Resources>
@ -68,10 +69,10 @@
FallbackColor="{ThemeResource SystemChromeMediumColor}"
TintColor="{ThemeResource SystemChromeLowColor}"
TintOpacity="0.7"/>
<SolidColorBrush x:Key="EquationBoxAddBackgroundBrush" Color="#9d000000"/>
<SolidColorBrush x:Key="EquationBoxPointerOverBackgroundBrush" Color="{ThemeResource SystemControlBackgroundAltMediumBrush}"/>
<SolidColorBrush x:Key="EquationBoxHoverButtonForegroundBrush" Color="{ThemeResource SystemBaseHighColor}"/>
<SolidColorBrush x:Key="AppChromeAcrylicOperatorFlyoutBackgroundBrush" Color="#FF2F2F2F"/>
<SolidColorBrush x:Key="EquationTextBoxTransparentBackgroundBrush" Color="Transparent"/>
<SolidColorBrush x:Key="EquationBoxBorderBrush" Color="{ThemeResource TextControlBackground}"/>
<SolidColorBrush x:Key="EquationButtonOverlayBackgroundBrush" Color="White"/>
<SolidColorBrush x:Key="EquationBoxErrorBackgroundBrush" Color="#33EB5757"/>
@ -164,6 +165,7 @@
FallbackColor="{ThemeResource SystemChromeMediumColor}"
TintColor="{ThemeResource SystemChromeLowColor}"
TintOpacity="0.8"/>
<SolidColorBrush x:Key="EquationBoxAddBackgroundBrush" Color="#D0FFFFFF"/>
<SolidColorBrush x:Key="EquationBoxPointerOverBackgroundBrush" Color="{ThemeResource SystemControlBackgroundAltMediumBrush}"/>
<SolidColorBrush x:Key="EquationBoxHoverButtonForegroundBrush" Color="{ThemeResource SystemBaseHighColor}"/>
<SolidColorBrush x:Key="EquationBoxBorderBrush" Color="{ThemeResource TextControlBackground}"/>
@ -222,6 +224,7 @@
<SolidColorBrush x:Key="AppControlHighlightCalcButtonBrush" Color="{ThemeResource SystemColorWindowColor}"/>
<SolidColorBrush x:Key="AppControlHighlightCalcButtonToggledBrush" Color="{ThemeResource SystemColorHighlightColor}"/>
<SolidColorBrush x:Key="AppControlHighlightCalcButtonHoverBrush" Color="{ThemeResource SystemColorHighlightColor}"/>
<SolidColorBrush x:Key="EquationBoxAddBackgroundBrush" Color="{ThemeResource SystemColorButtonFaceColor}"/>
<SolidColorBrush x:Key="EquationBoxPointerOverBackgroundBrush" Color="{ThemeResource SystemColorHighlightColor}"/>
<SolidColorBrush x:Key="EquationBoxHoverButtonForegroundBrush" Color="{ThemeResource SystemColorCaptionTextColor}"/>
<SolidColorBrush x:Key="EquationBoxBorderBrush" Color="{ThemeResource SystemColorButtonTextColor}"/>
@ -1856,7 +1859,6 @@
AutomationProperties.AccessibilityView="Raw"
Content="{TemplateBinding Description}"
x:Load="False"/>
</Grid>
</ControlTemplate>
@ -1890,155 +1892,71 @@
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="EquationBoxBorder" Storyboard.TargetProperty="BorderBrush">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource EquationBoxBorderBrush}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
<VisualState.Setters>
<Setter Target="EquationBoxBorder.BorderBrush" Value="{ThemeResource EquationBoxBorderBrush}"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="AddEquation">
<VisualState.Setters>
<Setter Target="RemoveButtonPanel.Visibility" Value="Collapsed"/>
<Setter Target="MathRichEditBox.PlaceholderText" Value="Enter an equation"/>
<Setter Target="EquationBoxBorder.Background" Value="{ThemeResource EquationBoxAddBackgroundBrush}"/>
<Setter Target="EquationBoxBorder.BorderBrush" Value="{ThemeResource EquationBoxBorderBrush}"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Error">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="EquationBoxBorder" Storyboard.TargetProperty="BorderBrush">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource EquationBoxErrorBorderBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="EquationBoxBorder" Storyboard.TargetProperty="Background">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource EquationBoxErrorBackgroundBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ErrorIcon" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
<VisualState.Setters>
<Setter Target="EquationBoxBorder.BorderBrush" Value="{ThemeResource EquationBoxErrorBorderBrush}"/>
<Setter Target="EquationBoxBorder.Background" Value="{ThemeResource EquationBoxErrorBackgroundBrush}"/>
<Setter Target="ErrorIcon.Visibility" Value="Visible"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="PointerOver">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="EquationBoxBorder" Storyboard.TargetProperty="BorderBrush">
<DiscreteObjectKeyFrame KeyTime="0" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=EquationColor}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ColorChooserButton" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="FunctionButton" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="RemoveButton" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ErrorIcon" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Collapsed</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
<VisualState.Setters>
<Setter Target="EquationBoxBorder.BorderBrush" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=EquationColor}"/>
<Setter Target="ColorChooserButton.Visibility" Value="Visible"/>
<Setter Target="FunctionButton.Visibility" Value="Visible"/>
<Setter Target="RemoveButton.Visibility" Value="Visible"/>
<Setter Target="ErrorIcon.Visibility" Value="Collapsed"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="PointerOverError">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="EquationBoxBorder" Storyboard.TargetProperty="BorderBrush">
<DiscreteObjectKeyFrame KeyTime="0" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=EquationColor}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="EquationBoxBorder" Storyboard.TargetProperty="Background">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource EquationBoxErrorBackgroundBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ColorChooserButton" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="FunctionButton" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Collapsed</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="RemoveButton" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ErrorIcon" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Collapsed</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
<VisualState.Setters>
<Setter Target="EquationBoxBorder.BorderBrush" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=EquationColor}"/>
<Setter Target="EquationBoxBorder.Background" Value="{ThemeResource EquationBoxErrorBackgroundBrush}"/>
<Setter Target="ColorChooserButton.Visibility" Value="Visible"/>
<Setter Target="FunctionButton.Visibility" Value="Collapsed"/>
<Setter Target="RemoveButton.Visibility" Value="Visible"/>
<Setter Target="ErrorIcon.Visibility" Value="Collapsed"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Disabled">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="EquationBoxBorder" Storyboard.TargetProperty="Background">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextBoxDisabledBackgroundThemeBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="EquationBoxBorder" Storyboard.TargetProperty="BorderBrush">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextBoxDisabledBorderThemeBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="EquationTextBox" Storyboard.TargetProperty="Background">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource AppControlTransparentButtonBackgroundBrush}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
<VisualState.Setters>
<Setter Target="EquationBoxBorder.Background" Value="{ThemeResource TextBoxDisabledBackgroundThemeBrush}"/>
<Setter Target="EquationBoxBorder.BorderBrush" Value="{ThemeResource TextBoxDisabledBorderThemeBrush}"/>
<Setter Target="EquationTextBox.Background" Value="{ThemeResource AppControlTransparentButtonBackgroundBrush}"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Focused">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="EquationBoxBorder" Storyboard.TargetProperty="BorderBrush">
<DiscreteObjectKeyFrame KeyTime="0" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=EquationColor}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="EquationBoxBorder" Storyboard.TargetProperty="Background">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextBoxBackgroundThemeBrush}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
<VisualState.Setters>
<Setter Target="EquationBoxBorder.BorderBrush" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=EquationColor}"/>
<Setter Target="EquationBoxBorder.Background" Value="{ThemeResource TextBoxBackgroundThemeBrush}"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="ButtonStates">
<VisualState x:Name="ButtonVisible">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="DeleteButton" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ErrorIcon" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Collapsed</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
<VisualState.Setters>
<Setter Target="DeleteButton.Visibility" Value="Visible"/>
<Setter Target="ErrorIcon.Visibility" Value="Collapsed"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="ButtonHideRemove">
<VisualState.Setters>
<Setter Target="RemoveButtonPanel.Visibility" Value="Collapsed"/>
<Setter Target="RemoveFunctionMenuItem.IsEnabled" Value="False"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="ButtonCollapsed"/>
</VisualStateGroup>
@ -2158,8 +2076,8 @@
Grid.Column="1"
Background="{ThemeResource TextControlBackground}"
BorderBrush="{TemplateBinding EquationColor}"
BorderThickness="{TemplateBinding BorderThickness}">
BorderThickness="{TemplateBinding BorderThickness}"
contract7Present:BackgroundSizing="OuterBorderEdge">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
@ -2218,16 +2136,16 @@
Visibility="Collapsed"/>
<FontIcon x:Name="ErrorIcon"
Grid.Column="3"
MinWidth="34"
MinWidth="28"
VerticalAlignment="Stretch"
FontFamily="{ThemeResource SymbolThemeFontFamily}"
FontSize="16"
AutomationProperties.AccessibilityView="Raw"
Glyph="&#xE783;"
Visibility="Collapsed"/>
<Grid x:Name="RemoveButtonPanel" Grid.Column="3">
<Button x:Name="RemoveButton"
x:Uid="removeButton"
Grid.Column="3"
MinWidth="34"
Margin="{ThemeResource HelperButtonThemePadding}"
VerticalAlignment="Stretch"
@ -2240,6 +2158,7 @@
Content="&#xECC9;"
IsTabStop="False"
Visibility="Collapsed"/>
</Grid>
<ToggleButton x:Name="ColorChooserButton"
x:Uid="colorChooserButton"
Grid.Column="2"

View File

@ -262,6 +262,7 @@
<DependentUpon>EquationStylePanelControl.xaml</DependentUpon>
</ClInclude>
<ClInclude Include="TemplateSelectors\KeyGraphFeaturesTemplateSelector.h" />
<ClInclude Include="Utils\VisualTree.h" />
<ClInclude Include="Views\Calculator.xaml.h">
<DependentUpon>Views\Calculator.xaml</DependentUpon>
</ClInclude>
@ -425,6 +426,7 @@
<DependentUpon>EquationStylePanelControl.xaml</DependentUpon>
</ClCompile>
<ClCompile Include="TemplateSelectors\KeyGraphFeaturesTemplateSelector.cpp" />
<ClCompile Include="Utils\VisualTree.cpp" />
<ClCompile Include="Views\Calculator.xaml.cpp">
<DependentUpon>Views\Calculator.xaml</DependentUpon>
</ClCompile>

View File

@ -221,6 +221,9 @@
<Filter Include="Views\GraphingCalculator">
<UniqueIdentifier>{e23e2a6e-491b-4200-9bf7-d355a1ee695b}</UniqueIdentifier>
</Filter>
<Filter Include="Utils">
<UniqueIdentifier>{b491a249-26b8-4814-9f50-2c3a57018c56}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml" />
@ -321,6 +324,9 @@
<Filter>Views\GraphingCalculator</Filter>
</ClCompile>
<ClCompile Include="TemplateSelectors\KeyGraphFeaturesTemplateSelector.cpp" />
<ClCompile Include="Utils\VisualTree.cpp">
<Filter>Utils</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h" />
@ -421,6 +427,9 @@
<Filter>Views\GraphingCalculator</Filter>
</ClInclude>
<ClInclude Include="TemplateSelectors\KeyGraphFeaturesTemplateSelector.h" />
<ClInclude Include="Utils\VisualTree.h">
<Filter>Utils</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<AppxManifest Include="Package.appxmanifest" />
@ -1551,7 +1560,5 @@
<ItemGroup>
<CopyFileToFolders Include="$(GraphingImplDll)" />
<CopyFileToFolders Include="$(GraphingEngineDll)" />
<CopyFileToFolders Include="$(GraphingImplDll)" />
<CopyFileToFolders Include="$(GraphingEngineDll)" />
</ItemGroup>
</Project>

View File

@ -26,6 +26,11 @@ DEPENDENCY_PROPERTY_INITIALIZATION(EquationTextBox, EquationColor);
DEPENDENCY_PROPERTY_INITIALIZATION(EquationTextBox, ColorChooserFlyout);
DEPENDENCY_PROPERTY_INITIALIZATION(EquationTextBox, EquationButtonContentIndex);
DEPENDENCY_PROPERTY_INITIALIZATION(EquationTextBox, HasError);
DEPENDENCY_PROPERTY_INITIALIZATION(EquationTextBox, IsAddEquationMode);
EquationTextBox::EquationTextBox()
{
}
void EquationTextBox::OnApplyTemplate()
{
@ -56,7 +61,8 @@ void EquationTextBox::OnApplyTemplate()
m_equationButton->Click += ref new RoutedEventHandler(this, &EquationTextBox::OnEquationButtonClicked);
auto toolTip = ref new ToolTip();
auto equationButtonMessage = m_equationButton->IsChecked->Value ? resProvider->GetResourceString(L"showEquationButtonToolTip") : resProvider->GetResourceString(L"hideEquationButtonToolTip");
auto equationButtonMessage = m_equationButton->IsChecked->Value ? resProvider->GetResourceString(L"showEquationButtonToolTip")
: resProvider->GetResourceString(L"hideEquationButtonToolTip");
toolTip->Content = equationButtonMessage;
ToolTipService::SetToolTip(m_equationButton, toolTip);
AutomationProperties::SetName(m_equationButton, equationButtonMessage);
@ -64,8 +70,7 @@ void EquationTextBox::OnApplyTemplate()
if (m_richEditContextMenu != nullptr)
{
m_richEditContextMenu->Opening +=
ref new Windows::Foundation::EventHandler<Platform::Object ^>(this, &EquationTextBox::OnRichEditMenuOpening);
m_richEditContextMenu->Opening += ref new Windows::Foundation::EventHandler<Platform::Object ^>(this, &EquationTextBox::OnRichEditMenuOpening);
}
if (m_kgfEquationButton != nullptr)
@ -119,6 +124,7 @@ void EquationTextBox::OnApplyTemplate()
}
UpdateCommonVisualState();
UpdateButtonsVisualState();
}
void EquationTextBox::OnPointerEntered(PointerRoutedEventArgs ^ e)
@ -149,24 +155,32 @@ void EquationTextBox::OnKeyDown(KeyRoutedEventArgs ^ e)
{
if (e->Key == VirtualKey::Enter)
{
EquationSubmitted(this, ref new RoutedEventArgs());
m_sourceSubmission = EquationSubmissionSource::ENTER_KEY;
// We will rely on OnLostFocus to submit the equation to prevent the launch of 2 events
if (!m_HasFocus || !FocusManager::TryMoveFocusAsync(::FocusNavigationDirection::Next))
{
m_sourceSubmission = EquationSubmissionSource::FOCUS_LOST;
EquationSubmitted(this, EquationSubmissionSource::ENTER_KEY);
if (m_functionButton && m_richEditBox->MathText != L"")
{
m_functionButton->IsEnabled = true;
}
}
}
}
void EquationTextBox::OnLostFocus(RoutedEventArgs ^ e)
{
if (m_richEditBox != nullptr && !m_richEditBox->ContextFlyout->IsOpen)
if (m_richEditBox == nullptr || m_richEditBox->ContextFlyout->IsOpen)
{
EquationSubmitted(this, ref new RoutedEventArgs());
return;
}
EquationSubmitted(this, m_sourceSubmission);
if (m_functionButton && m_richEditBox->MathText != L"")
{
m_functionButton->IsEnabled = true;
}
}
}
void EquationTextBox::OnColorFlyoutOpened(Object ^ sender, Object ^ e)
@ -184,14 +198,15 @@ void EquationTextBox::OnColorFlyoutClosed(Object ^ sender, Object ^ e)
void EquationTextBox::OnRichEditBoxTextChanged(Object ^ sender, RoutedEventArgs ^ e)
{
UpdateDeleteButtonVisualState();
UpdateButtonsVisualState();
}
void EquationTextBox::OnRichEditBoxGotFocus(Object ^ sender, RoutedEventArgs ^ e)
{
m_HasFocus = true;
m_sourceSubmission = EquationSubmissionSource::FOCUS_LOST;
UpdateCommonVisualState();
UpdateDeleteButtonVisualState();
UpdateButtonsVisualState();
}
void EquationTextBox::OnRichEditBoxLostFocus(Object ^ sender, RoutedEventArgs ^ e)
@ -202,7 +217,7 @@ void EquationTextBox::OnRichEditBoxLostFocus(Object ^ sender, RoutedEventArgs ^
}
UpdateCommonVisualState();
UpdateDeleteButtonVisualState();
UpdateButtonsVisualState();
}
void EquationTextBox::OnDeleteButtonClicked(Object ^ sender, RoutedEventArgs ^ e)
@ -223,7 +238,8 @@ void EquationTextBox::OnEquationButtonClicked(Object ^ sender, RoutedEventArgs ^
auto toolTip = ref new ToolTip();
auto resProvider = AppResourceProvider::GetInstance();
auto equationButtonMessage = m_equationButton->IsChecked->Value ? resProvider->GetResourceString(L"showEquationButtonToolTip") : resProvider->GetResourceString(L"hideEquationButtonToolTip");
auto equationButtonMessage = m_equationButton->IsChecked->Value ? resProvider->GetResourceString(L"showEquationButtonToolTip")
: resProvider->GetResourceString(L"hideEquationButtonToolTip");
toolTip->Content = equationButtonMessage;
ToolTipService::SetToolTip(m_equationButton, toolTip);
AutomationProperties::SetName(m_equationButton, equationButtonMessage);
@ -236,6 +252,12 @@ void EquationTextBox::OnKGFEquationButtonClicked(Object ^ sender, RoutedEventArg
void EquationTextBox::OnRemoveButtonClicked(Object ^ sender, RoutedEventArgs ^ e)
{
if (IsAddEquationMode)
{
// Don't remove the last equation
return;
}
if (m_richEditBox != nullptr)
{
m_richEditBox->MathText = L"";
@ -269,11 +291,15 @@ void EquationTextBox::OnFunctionButtonClicked(Object ^ sender, RoutedEventArgs ^
KeyGraphFeaturesButtonClicked(this, ref new RoutedEventArgs());
}
void EquationTextBox::UpdateDeleteButtonVisualState()
void EquationTextBox::UpdateButtonsVisualState()
{
String ^ state;
if (RichEditHasContent())
if (IsAddEquationMode)
{
state = "ButtonHideRemove";
}
else if (RichEditHasContent())
{
state = "ButtonVisible";
}
@ -287,13 +313,13 @@ void EquationTextBox::UpdateDeleteButtonVisualState()
void EquationTextBox::UpdateCommonVisualState()
{
String ^ state = "Normal";
String ^ state = nullptr;
if (m_HasFocus)
{
state = "Focused";
}
else if ((m_isPointerOver && HasError) || (m_isColorChooserFlyoutOpen && HasError))
else if (HasError && (m_isPointerOver || m_isColorChooserFlyoutOpen))
{
state = "PointerOverError";
}
@ -305,8 +331,15 @@ void EquationTextBox::UpdateCommonVisualState()
{
state = "Error";
}
VisualStateManager::GoToState(this, state, true);
else if (IsAddEquationMode)
{
state = "AddEquation";
}
else
{
state = "Normal";
}
VisualStateManager::GoToState(this, state, false);
}
void EquationTextBox::OnHasErrorPropertyChanged(bool, bool)
@ -360,3 +393,17 @@ void EquationTextBox::OnRichEditMenuOpening(Object ^ /*sender*/, Object ^ /*args
m_kgfEquationMenuItem->IsEnabled = EquationTextBox::RichEditHasContent();
}
}
void EquationTextBox::OnIsAddEquationModePropertyChanged(bool /*oldValue*/, bool /*newValue*/)
{
UpdateCommonVisualState();
UpdateButtonsVisualState();
}
void EquationTextBox::FocusTextBox()
{
if (m_richEditBox != nullptr)
{
m_richEditBox->Focus(::FocusState::Programmatic);
}
}

View File

@ -11,46 +11,55 @@ namespace CalculatorApp
{
namespace Controls
{
public ref class EquationTextBox sealed : public Windows::UI::Xaml::Controls::Control
public
enum class EquationSubmissionSource
{
FOCUS_LOST,
ENTER_KEY
};
public
ref class EquationTextBox sealed : public Windows::UI::Xaml::Controls::Control
{
public:
EquationTextBox()
{
}
EquationTextBox();
DEPENDENCY_PROPERTY_OWNER(EquationTextBox);
DEPENDENCY_PROPERTY(Windows::UI::Xaml::Media::SolidColorBrush^, EquationColor);
DEPENDENCY_PROPERTY(Windows::UI::Xaml::Controls::Flyout^, ColorChooserFlyout);
DEPENDENCY_PROPERTY(Windows::UI::Xaml::Media::SolidColorBrush ^, EquationColor);
DEPENDENCY_PROPERTY(Windows::UI::Xaml::Controls::Flyout ^, ColorChooserFlyout);
DEPENDENCY_PROPERTY(Platform::String ^, EquationButtonContentIndex);
DEPENDENCY_PROPERTY_WITH_CALLBACK(bool, HasError);
DEPENDENCY_PROPERTY_WITH_CALLBACK(bool, IsAddEquationMode);
PROPERTY_R(bool, HasFocus);
event Windows::UI::Xaml::RoutedEventHandler ^ RemoveButtonClicked;
event Windows::UI::Xaml::RoutedEventHandler ^ KeyGraphFeaturesButtonClicked;
event Windows::UI::Xaml::RoutedEventHandler ^ EquationSubmitted;
event Windows::Foundation::EventHandler<EquationSubmissionSource> ^ EquationSubmitted;
event Windows::UI::Xaml::RoutedEventHandler ^ EquationButtonClicked;
Platform::String^ GetEquationText();
void SetEquationText(Platform::String^ equationText);
Platform::String ^ GetEquationText();
void SetEquationText(Platform::String ^ equationText);
void FocusTextBox();
protected:
virtual void OnApplyTemplate() override;
virtual void OnPointerEntered(Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e) override;
virtual void OnPointerExited(Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e) override;
virtual void OnPointerCanceled(Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e) override;
virtual void OnPointerCaptureLost(Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e) override;
virtual void OnKeyDown(Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e) override;
virtual void OnLostFocus(Windows::UI::Xaml::RoutedEventArgs^ e) override;
virtual void OnPointerEntered(Windows::UI::Xaml::Input::PointerRoutedEventArgs ^ e) override;
virtual void OnPointerExited(Windows::UI::Xaml::Input::PointerRoutedEventArgs ^ e) override;
virtual void OnPointerCanceled(Windows::UI::Xaml::Input::PointerRoutedEventArgs ^ e) override;
virtual void OnPointerCaptureLost(Windows::UI::Xaml::Input::PointerRoutedEventArgs ^ e) override;
virtual void OnKeyDown(Windows::UI::Xaml::Input::KeyRoutedEventArgs ^ e) override;
virtual void OnLostFocus(Windows::UI::Xaml::RoutedEventArgs ^ e) override;
void OnIsAddEquationModePropertyChanged(bool oldValue, bool newValue);
private:
void UpdateCommonVisualState();
void UpdateDeleteButtonVisualState();
void UpdateButtonsVisualState();
bool RichEditHasContent();
void OnRichEditBoxGotFocus(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void OnRichEditBoxLostFocus(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void OnRichEditBoxTextChanged(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void OnRichEditBoxGotFocus(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
void OnRichEditBoxLostFocus(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
void OnRichEditBoxTextChanged(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
void OnDeleteButtonClicked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void OnEquationButtonClicked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
@ -60,18 +69,18 @@ namespace CalculatorApp
void OnFunctionButtonClicked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void OnRichEditMenuOpening(Platform::Object ^ sender, Platform::Object ^ args);
void OnColorFlyoutOpened(Platform::Object^ sender, Platform::Object^ e);
void OnColorFlyoutClosed(Platform::Object^ sender, Platform::Object^ e);
void OnColorFlyoutOpened(Platform::Object ^ sender, Platform::Object ^ e);
void OnColorFlyoutClosed(Platform::Object ^ sender, Platform::Object ^ e);
void OnHasErrorPropertyChanged(bool oldValue, bool newValue);
CalculatorApp::Controls::MathRichEditBox^ m_richEditBox;
Windows::UI::Xaml::Controls::Primitives::ToggleButton^ m_equationButton;
Windows::UI::Xaml::Controls::Button^ m_kgfEquationButton;
Windows::UI::Xaml::Controls::Button^ m_deleteButton;
Windows::UI::Xaml::Controls::Button^ m_removeButton;
Windows::UI::Xaml::Controls::Button^ m_functionButton;
Windows::UI::Xaml::Controls::Primitives::ToggleButton^ m_colorChooserButton;
CalculatorApp::Controls::MathRichEditBox ^ m_richEditBox;
Windows::UI::Xaml::Controls::Primitives::ToggleButton ^ m_equationButton;
Windows::UI::Xaml::Controls::Button ^ m_kgfEquationButton;
Windows::UI::Xaml::Controls::Button ^ m_deleteButton;
Windows::UI::Xaml::Controls::Button ^ m_removeButton;
Windows::UI::Xaml::Controls::Button ^ m_functionButton;
Windows::UI::Xaml::Controls::Primitives::ToggleButton ^ m_colorChooserButton;
Windows::UI::Xaml::Controls::MenuFlyout^ m_richEditContextMenu;
Windows::UI::Xaml::Controls::MenuFlyoutItem^ m_kgfEquationMenuItem;
@ -80,6 +89,7 @@ namespace CalculatorApp
bool m_isPointerOver;
bool m_isColorChooserFlyoutOpen;
EquationSubmissionSource m_sourceSubmission;
};
}
}

View File

@ -3907,7 +3907,7 @@
<value>Zoom Out</value>
<comment>Screen reader prompt for the zoom out button.</comment>
</data>
<data name="EquationInputButtonPlaceholder.Text" xml:space="preserve">
<data name="EquationTextBoxAddPanel.[using:Windows.UI.Xaml.Controls]ToolTipService.ToolTip" xml:space="preserve">
<value>Add Equation</value>
<comment>Placeholder text for the equation input button</comment>
</data>
@ -4218,4 +4218,8 @@
<value>Current mode is graph mode</value>
<comment>Announcement used in Graphing Calculator when switching to the graph mode</comment>
</data>
<data name="equationMathRichEditBox.PlaceholderText" xml:space="preserve">
<value>Enter an equation</value>
<comment>Used in the Graphing Calculator to indicate to users that they can enter an equation in the textbox</comment>
</data>
</root>

View File

@ -0,0 +1,104 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#include "pch.h"
#include "VisualTree.h"
using namespace Windows::Foundation::Collections;
using namespace Windows::UI::Xaml;
using namespace Platform;
using namespace Windows::UI::Xaml::Interop;
using namespace Windows::UI::Xaml::Media;
using namespace Calculator::Utils;
FrameworkElement ^ VisualTree::FindDescendantByName(DependencyObject ^ element, String ^ name)
{
if (element == nullptr || name == nullptr || name->Length() == 0)
{
return nullptr;
}
auto frameworkElement = dynamic_cast<FrameworkElement ^>(element);
auto nsame = frameworkElement->Name->Data();
nsame = nsame;
if (frameworkElement != nullptr && name->Equals(frameworkElement->Name))
{
return frameworkElement;
}
auto childCount = VisualTreeHelper::GetChildrenCount(element);
for (int i = 0; i < childCount; i++)
{
auto result = FindDescendantByName(VisualTreeHelper::GetChild(element, i), name);
if (result != nullptr)
{
return result;
}
}
return nullptr;
}
DependencyObject ^ VisualTree::FindDescendant(DependencyObject ^ element, TypeName typeName)
{
DependencyObject ^ retValue = nullptr;
auto childrenCount = VisualTreeHelper::GetChildrenCount(element);
for (auto i = 0; i < childrenCount; i++)
{
auto child = VisualTreeHelper::GetChild(element, i);
if (child->GetType() == typeName)
{
retValue = child;
break;
}
retValue = FindDescendant(child, typeName);
if (retValue != nullptr)
{
break;
}
}
return retValue;
}
FrameworkElement ^ VisualTree::FindAscendantByName(DependencyObject ^ element, String ^ name)
{
if (element == nullptr || name == nullptr || name->Length() == 0)
{
return nullptr;
}
auto parent = VisualTreeHelper::GetParent(element);
if (parent == nullptr)
{
return nullptr;
}
auto frameworkElement = dynamic_cast<FrameworkElement ^>(parent);
if (frameworkElement != nullptr && name->Equals(frameworkElement->Name))
{
return frameworkElement;
}
return FindAscendantByName(parent, name);
}
Object ^ VisualTree::FindAscendant(DependencyObject ^ element, TypeName typeName)
{
auto parent = VisualTreeHelper::GetParent(element);
if (parent == nullptr)
{
return nullptr;
}
if (parent->GetType() == typeName)
{
return parent;
}
return FindAscendant(parent, typeName);
}

View File

@ -0,0 +1,50 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Light C++/CX port of Microsoft.Toolkit.Uwp.UI.Extensions.VisualTree from the Windows Community toolkit
// Original version here:
// https://raw.githubusercontent.com/windows-toolkit/WindowsCommunityToolkit/master/Microsoft.Toolkit.Uwp.UI/Extensions/Tree/VisualTree.cs
namespace Calculator::Utils
{
/// <summary>
/// Defines a collection of extensions methods for UI.
/// </summary>
ref class VisualTree sealed
{
/// <summary>
/// Find descendant <see cref="Windows::UI::Xaml::FrameworkElement ^"/> control using its name.
/// </summary>
/// <param name="element">Parent element.</param>
/// <param name="name">Name of the control to find</param>
/// <returns>Descendant control or null if not found.</returns>
internal : static Windows::UI::Xaml::FrameworkElement ^ FindDescendantByName(Windows::UI::Xaml::DependencyObject ^ element, Platform::String ^ name);
/// <summary>
/// Find first descendant control of a specified type.
/// </summary>
/// <param name="element">Parent element.</param>
/// <param name="type">Type of descendant.</param>
/// <returns>Descendant control or null if not found.</returns>
static Windows::UI::Xaml::DependencyObject
^ FindDescendant(Windows::UI::Xaml::DependencyObject ^ element, Windows::UI::Xaml::Interop::TypeName typeName);
/// <summary>
/// Find visual ascendant <see cref="Windows::UI::Xaml::FrameworkElement ^"/> control using its name.
/// </summary>
/// <param name="element">Parent element.</param>
/// <param name="name">Name of the control to find</param>
/// <returns>Descendant control or null if not found.</returns>
static Windows::UI::Xaml::FrameworkElement ^ FindAscendantByName(Windows::UI::Xaml::DependencyObject ^ element, Platform::String ^ name);
/// <summary>
/// Find first visual ascendant control of a specified type.
/// </summary>
/// <param name="element">Child element.</param>
/// <param name="type">Type of ascendant to look for.</param>
/// <returns>Ascendant control or null if not found.</returns>
static Platform::Object ^ FindAscendant(Windows::UI::Xaml::DependencyObject ^ element, Windows::UI::Xaml::Interop::TypeName type);
};
}

View File

@ -2,7 +2,6 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:CalculatorApp.Controls"
xmlns:converters="using:CalculatorApp.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:CalculatorApp"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
@ -11,24 +10,18 @@
d:DesignWidth="400"
mc:Ignorable="d">
<Grid VerticalAlignment="Top">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid>
<ListView x:Name="EquationInputList"
IsItemClickEnabled="False"
ItemsSource="{x:Bind Equations}"
SelectionMode="None">
<!-- Removes animations from the ListView Style. -->
<!-- Removes animations from the ListView Style. -->
<ListView.Style>
<Style TargetType="ListView">
<Setter Property="ItemContainerTransitions">
<Setter.Value>
<TransitionCollection>
</TransitionCollection>
<TransitionCollection/>
</Setter.Value>
</Setter>
</Style>
@ -43,22 +36,23 @@
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemTemplate>
<DataTemplate x:DataType="vm:EquationViewModel">
<controls:EquationTextBox x:Uid="EquationInputButton"
Margin="1,0,1,0"
<controls:EquationTextBox x:Name="EquationInputButton"
x:Uid="EquationInputButton"
Margin="1"
Style="{StaticResource EquationTextBoxStyle}"
EquationColor="{x:Bind LineColor, Mode=OneWay}"
EquationButtonClicked="EquationTextBox_EquationButtonClicked"
EquationButtonContentIndex="{x:Bind FunctionLabelIndex, Mode=OneWay}"
EquationColor="{x:Bind LineColor, Mode=OneWay}"
EquationSubmitted="InputTextBox_Submitted"
GotFocus="InputTextBox_GotFocus"
HasError="{x:Bind GraphEquation.HasGraphError, Mode=OneWay}"
IsAddEquationMode="{x:Bind IsLastItemInList, Mode=OneWay}"
KeyGraphFeaturesButtonClicked="EquationTextBox_KeyGraphFeaturesButtonClicked"
Loaded="EquationTextBoxLoaded"
LostFocus="InputTextBox_LostFocus"
RemoveButtonClicked="EquationTextBox_RemoveButtonClicked"
KeyGraphFeaturesButtonClicked="EquationTextBox_KeyGraphFeaturesButtonClicked">
RemoveButtonClicked="EquationTextBox_RemoveButtonClicked">
<controls:EquationTextBox.ColorChooserFlyout>
<Flyout x:Name="ColorChooserFlyout"
x:Uid="ColorChooserFlyout"
@ -70,35 +64,5 @@
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<Button Grid.Row="1"
MinHeight="44"
Margin="2,0,2,1"
Padding="0"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
Style="{ThemeResource CaptionButtonStyle}"
FontSize="14"
FontWeight="Normal"
Click="AddEquationButton_Click">
<Button.Content>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<FontIcon MinWidth="44"
FontFamily="{StaticResource SymbolThemeFontFamily}"
Glyph="&#xE710;"/>
<TextBlock x:Uid="EquationInputButtonPlaceholder"
Grid.Column="1"
Margin="8,0,0,0"
VerticalAlignment="Center"/>
</Grid>
</Button.Content>
</Button>
</Grid>
</UserControl>

View File

@ -3,6 +3,7 @@
#include "pch.h"
#include "EquationInputArea.xaml.h"
#include "Utils/VisualTree.h"
using namespace CalculatorApp;
using namespace CalculatorApp::Common;
@ -21,6 +22,7 @@ using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Controls::Primitives;
using namespace Windows::UI::Xaml::Input;
using namespace GraphControl;
using namespace Calculator::Utils;
namespace
{
@ -31,6 +33,7 @@ EquationInputArea::EquationInputArea()
: m_lastLineColorIndex{ -1 }
, m_AvailableColors{ ref new Vector<SolidColorBrush ^>() }
, m_accessibilitySettings{ ref new AccessibilitySettings() }
, m_equationToFocus{ nullptr }
{
m_accessibilitySettings->HighContrastChanged +=
ref new TypedEventHandler<AccessibilitySettings ^, Object ^>(this, &EquationInputArea::OnHighContrastChanged);
@ -56,14 +59,15 @@ void EquationInputArea::OnEquationsPropertyChanged()
}
}
void EquationInputArea::AddEquationButton_Click(Object ^ sender, RoutedEventArgs ^ e)
{
AddNewEquation();
}
void EquationInputArea::AddNewEquation()
{
auto eq = ref new EquationViewModel(ref new Equation());
eq->IsLastItemInList = true;
if (Equations->Size > 0)
{
Equations->GetAt(Equations->Size - 1)->IsLastItemInList = false;
}
m_lastLineColorIndex = (m_lastLineColorIndex + 1) % AvailableColors->Size;
@ -71,7 +75,7 @@ void EquationInputArea::AddNewEquation()
eq->IsLineEnabled = true;
eq->FunctionLabelIndex = ++m_lastFunctionLabelIndex;
Equations->Append(eq);
EquationInputList->ScrollIntoView(eq);
m_equationToFocus = eq;
}
void EquationInputArea::InputTextBox_GotFocus(Object ^ sender, RoutedEventArgs ^ e)
@ -84,20 +88,65 @@ void EquationInputArea::InputTextBox_LostFocus(Object ^ sender, RoutedEventArgs
KeyboardShortcutManager::HonorShortcuts(true);
}
void EquationInputArea::InputTextBox_Submitted(Object ^ sender, RoutedEventArgs ^ e)
void EquationInputArea::InputTextBox_Submitted(Object ^ sender, EquationSubmissionSource source)
{
auto tb = static_cast<EquationTextBox ^>(sender);
auto eq = static_cast<EquationViewModel ^>(tb->DataContext);
// eq can be null if the equation has been removed
if (eq != nullptr)
if (tb == nullptr)
{
eq->Expression = tb->GetEquationText();
return;
}
auto eq = static_cast<EquationViewModel ^>(tb->DataContext);
if (eq == nullptr)
{
return;
}
if (tb->HasFocus)
auto expressionText = tb->GetEquationText();
if (source == EquationSubmissionSource::FOCUS_LOST && eq->Expression == expressionText)
{
FocusManager::TryMoveFocus(::FocusNavigationDirection::Left);
// The expression didn't change.
return;
}
eq->Expression = expressionText;
if (source == EquationSubmissionSource::ENTER_KEY || eq->Expression != nullptr && eq->Expression->Length() > 0)
{
unsigned int index = 0;
if (Equations->IndexOf(eq, &index) && index == Equations->Size - 1)
{
// If it's the last equation of the list
AddNewEquation();
}
else
{
auto nextEquation = Equations->GetAt(index + 1);
FocusEquationTextBox(nextEquation);
}
}
}
void EquationInputArea::FocusEquationTextBox(EquationViewModel ^ equation)
{
auto nextContainer = EquationInputList->ContainerFromItem(equation);
if (nextContainer == nullptr)
{
return;
}
auto listviewItem = dynamic_cast<ListViewItem ^>(nextContainer);
if (listviewItem == nullptr)
{
return;
}
auto equationInput = VisualTree::FindDescendantByName(nextContainer, "EquationInputButton");
if (equationInput == nullptr)
{
return;
}
auto equationTextBox = dynamic_cast<EquationTextBox ^>(equationInput);
if (equationTextBox != nullptr)
{
equationTextBox->FocusTextBox();
}
}
@ -113,6 +162,10 @@ void EquationInputArea::EquationTextBox_RemoveButtonClicked(Object ^ sender, Rou
m_lastFunctionLabelIndex--;
}
if (index == Equations->Size - 1 && Equations->Size > 1)
{
Equations->GetAt(Equations->Size - 2)->IsLastItemInList = true;
}
Equations->RemoveAt(index);
}
}
@ -124,7 +177,7 @@ void EquationInputArea::EquationTextBox_KeyGraphFeaturesButtonClicked(Object ^ s
// ensure the equation has been submitted before trying to get key graph features out of it
if (tb->HasFocus)
{
EquationInputArea::InputTextBox_Submitted(sender, e);
EquationInputArea::InputTextBox_Submitted(sender, EquationSubmissionSource::FOCUS_LOST);
}
auto eq = static_cast<EquationViewModel ^>(tb->DataContext);
@ -143,10 +196,15 @@ void EquationInputArea::EquationTextBox_EquationButtonClicked(Object ^ sender, R
void EquationInputArea::EquationTextBoxLoaded(Object ^ sender, RoutedEventArgs ^ e)
{
auto tb = static_cast<EquationTextBox ^>(sender);
auto eq = static_cast<EquationViewModel ^>(tb->DataContext);
auto colorChooser = static_cast<EquationStylePanelControl ^>(tb->ColorChooserFlyout->Content);
colorChooser->AvailableColors = AvailableColors;
if (tb->DataContext == m_equationToFocus)
{
m_equationToFocus = nullptr;
tb->FocusTextBox();
}
}
void EquationInputArea::OnHighContrastChanged(AccessibilitySettings ^ sender, Object ^ args)

View File

@ -29,23 +29,25 @@ namespace CalculatorApp
void OnPropertyChanged(Platform::String^ propertyName);
void OnEquationsPropertyChanged();
void AddEquationButton_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void AddNewEquation();
void InputTextBox_GotFocus(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void InputTextBox_LostFocus(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void InputTextBox_Submitted(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
void InputTextBox_Submitted(Platform::Object ^ sender, CalculatorApp::Controls::EquationSubmissionSource e);
void OnHighContrastChanged(Windows::UI::ViewManagement::AccessibilitySettings ^ sender, Platform::Object ^ args);
void ReloadAvailableColors(bool isHighContrast);
void FocusEquationTextBox(ViewModel::EquationViewModel ^ equation);
void EquationTextBox_RemoveButtonClicked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
void EquationTextBox_KeyGraphFeaturesButtonClicked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
void EquationTextBox_EquationButtonClicked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
void EquationTextBoxLoaded(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
private:
Windows::UI::ViewManagement::AccessibilitySettings ^ m_accessibilitySettings;
int m_lastLineColorIndex;
int m_lastFunctionLabelIndex;
void EquationTextBox_RemoveButtonClicked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void EquationTextBox_KeyGraphFeaturesButtonClicked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
void EquationTextBox_EquationButtonClicked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
void EquationTextBoxLoaded(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
ViewModel::EquationViewModel ^ m_equationToFocus;
};
}