Add error handling to graph and equations (#827)
* add error handling * Handle regraphing on certain errors * Fix high contrast * Hide KGF button in error state
This commit is contained in:
@@ -54,6 +54,7 @@
|
||||
EquationButtonContentIndex="{x:Bind FunctionLabelIndex, Mode=OneWay}"
|
||||
EquationSubmitted="InputTextBox_Submitted"
|
||||
GotFocus="InputTextBox_GotFocus"
|
||||
HasError="{x:Bind GraphEquation.HasGraphError, Mode=OneWay}"
|
||||
Loaded="EquationTextBoxLoaded"
|
||||
LostFocus="InputTextBox_LostFocus"
|
||||
RemoveButtonClicked="EquationTextBox_RemoveButtonClicked"
|
||||
|
@@ -110,17 +110,47 @@ void GraphingCalculator::GraphingCalculator_DataContextChanged(FrameworkElement
|
||||
|
||||
void GraphingCalculator::OnEquationsVectorChanged(IObservableVector<EquationViewModel ^> ^ sender, IVectorChangedEventArgs ^ event)
|
||||
{
|
||||
if (event->CollectionChange != ::CollectionChange::ItemChanged)
|
||||
// If an item is already added to the graph, changing it should automatically trigger a graph update
|
||||
if (event->CollectionChange == ::CollectionChange::ItemChanged)
|
||||
{
|
||||
GraphingControl->Equations->Clear();
|
||||
|
||||
for (auto equationViewModel : ViewModel->Equations)
|
||||
{
|
||||
GraphingControl->Equations->Append(equationViewModel->GraphEquation);
|
||||
}
|
||||
|
||||
GraphingControl->PlotGraph();
|
||||
return;
|
||||
}
|
||||
|
||||
// Do not plot the graph if we are removing an empty equation, just remove it
|
||||
if (event->CollectionChange == ::CollectionChange::ItemRemoved)
|
||||
{
|
||||
auto itemToRemove = GraphingControl->Equations->GetAt(event->Index);
|
||||
|
||||
if (itemToRemove->Expression->IsEmpty())
|
||||
{
|
||||
GraphingControl->Equations->RemoveAt(event->Index);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Do not plot the graph if we are adding an empty equation, just add it
|
||||
if (event->CollectionChange == ::CollectionChange::ItemInserted)
|
||||
{
|
||||
auto itemToAdd = sender->GetAt(event->Index);
|
||||
|
||||
if (itemToAdd->Expression->IsEmpty())
|
||||
{
|
||||
GraphingControl->Equations->Append(itemToAdd->GraphEquation);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// We are either adding or removing a valid equation, or resetting the collection. We will need to plot the graph
|
||||
GraphingControl->Equations->Clear();
|
||||
|
||||
for (auto equationViewModel : ViewModel->Equations)
|
||||
{
|
||||
GraphingControl->Equations->Append(equationViewModel->GraphEquation);
|
||||
}
|
||||
|
||||
GraphingControl->PlotGraph();
|
||||
}
|
||||
|
||||
void GraphingCalculator::OnTracePointChanged(Windows::Foundation::Point newPoint)
|
||||
|
@@ -38,7 +38,6 @@ public ref class GraphingCalculator sealed : public Windows::UI::Xaml::Data::INo
|
||||
private:
|
||||
void GraphingCalculator_DataContextChanged(Windows::UI::Xaml::FrameworkElement ^ sender, Windows::UI::Xaml::DataContextChangedEventArgs ^ args);
|
||||
|
||||
void GraphVariablesUpdated(Platform::Object ^ sender, Object ^ args);
|
||||
void OnVariableChanged(Platform::Object ^ sender, CalculatorApp::ViewModel::VariableChangedEventArgs args);
|
||||
void OnEquationsVectorChanged(
|
||||
Windows::Foundation::Collections::IObservableVector<CalculatorApp::ViewModel::EquationViewModel ^> ^ sender,
|
||||
|
@@ -26,119 +26,6 @@
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="controls:EquationTextBox">
|
||||
<Grid>
|
||||
<Grid.Resources>
|
||||
<Style x:Key="KGF_EquationTextBoxStyle" TargetType="controls:MathRichEditBox">
|
||||
<Setter Property="Foreground" Value="{ThemeResource TextControlForeground}"/>
|
||||
<Setter Property="Background" Value="Transparent"/>
|
||||
<Setter Property="ContentLinkForegroundColor" Value="{ThemeResource ContentLinkForegroundColor}"/>
|
||||
<Setter Property="ContentLinkBackgroundColor" Value="{ThemeResource ContentLinkBackgroundColor}"/>
|
||||
<Setter Property="SelectionHighlightColor" Value="{ThemeResource TextControlSelectionHighlightColor}"/>
|
||||
<Setter Property="BorderBrush" Value="{ThemeResource TextControlBorderBrush}"/>
|
||||
<Setter Property="BorderThickness" Value="{ThemeResource TextControlBorderThemeThickness}"/>
|
||||
<Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}"/>
|
||||
<Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}"/>
|
||||
<Setter Property="ScrollViewer.HorizontalScrollMode" Value="Auto"/>
|
||||
<Setter Property="ScrollViewer.VerticalScrollMode" Value="Auto"/>
|
||||
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Hidden"/>
|
||||
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Hidden"/>
|
||||
<Setter Property="ScrollViewer.IsDeferredScrollingEnabled" Value="False"/>
|
||||
<Setter Property="Padding" Value="{ThemeResource TextControlThemePadding}"/>
|
||||
<Setter Property="UseSystemFocusVisuals" Value="{ThemeResource IsApplicationFocusVisualKindReveal}"/>
|
||||
<Setter Property="ContextFlyout" Value="{StaticResource TextControlCommandBarContextFlyout}"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="controls:MathRichEditBox">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup x:Name="CommonStates">
|
||||
<VisualState x:Name="Disabled"/>
|
||||
<VisualState x:Name="Normal"/>
|
||||
<VisualState x:Name="PointerOver"/>
|
||||
<VisualState x:Name="Focused"/>
|
||||
</VisualStateGroup>
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
|
||||
<ContentPresenter x:Name="HeaderContentPresenter"
|
||||
Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
Grid.ColumnSpan="4"
|
||||
Margin="{ThemeResource RichEditBoxTopHeaderMargin}"
|
||||
Foreground="{ThemeResource TextControlHeaderForeground}"
|
||||
FontWeight="Normal"
|
||||
x:DeferLoadStrategy="Lazy"
|
||||
Content="{TemplateBinding Header}"
|
||||
ContentTemplate="{TemplateBinding HeaderTemplate}"
|
||||
TextWrapping="Wrap"
|
||||
Visibility="Collapsed"/>
|
||||
<Border x:Name="BorderElement"
|
||||
Grid.Row="1"
|
||||
Grid.RowSpan="1"
|
||||
Grid.Column="0"
|
||||
Grid.ColumnSpan="4"
|
||||
MinWidth="{ThemeResource TextControlThemeMinWidth}"
|
||||
MinHeight="{ThemeResource TextControlThemeMinHeight}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="0"
|
||||
Control.IsTemplateFocusTarget="True"
|
||||
CornerRadius="{TemplateBinding CornerRadius}"/>
|
||||
<ScrollViewer x:Name="ContentElement"
|
||||
Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Margin="{TemplateBinding BorderThickness}"
|
||||
Padding="{TemplateBinding Padding}"
|
||||
VerticalAlignment="Center"
|
||||
AutomationProperties.AccessibilityView="Raw"
|
||||
HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
|
||||
HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}"
|
||||
IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}"
|
||||
IsHorizontalRailEnabled="{TemplateBinding ScrollViewer.IsHorizontalRailEnabled}"
|
||||
IsTabStop="False"
|
||||
IsVerticalRailEnabled="{TemplateBinding ScrollViewer.IsVerticalRailEnabled}"
|
||||
VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
|
||||
VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}"
|
||||
ZoomMode="Disabled"/>
|
||||
<TextBlock x:Name="PlaceholderTextContentPresenter"
|
||||
Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Grid.ColumnSpan="4"
|
||||
Margin="{TemplateBinding BorderThickness}"
|
||||
Padding="{TemplateBinding Padding}"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="{ThemeResource TextControlPlaceholderForeground}"
|
||||
IsHitTestVisible="False"
|
||||
Text="{TemplateBinding PlaceholderText}"
|
||||
TextAlignment="{TemplateBinding TextAlignment}"
|
||||
TextWrapping="{TemplateBinding TextWrapping}"/>
|
||||
<ContentPresenter x:Name="DescriptionPresenter"
|
||||
Grid.Row="2"
|
||||
Grid.Column="0"
|
||||
Grid.ColumnSpan="4"
|
||||
Background="Transparent"
|
||||
Foreground="{ThemeResource SystemControlDescriptionTextForegroundBrush}"
|
||||
x:Load="False"
|
||||
AutomationProperties.AccessibilityView="Raw"
|
||||
Content="{TemplateBinding Description}"/>
|
||||
|
||||
</Grid>
|
||||
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</Grid.Resources>
|
||||
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
@@ -185,12 +72,12 @@
|
||||
</Button.Resources>
|
||||
</Button>
|
||||
|
||||
<controls:MathRichEditBox x:Name="EquationTextBox"
|
||||
<controls:MathRichEditBox x:Name="MathRichEditBox"
|
||||
Grid.Column="1"
|
||||
MinHeight="44"
|
||||
Padding="{TemplateBinding Padding}"
|
||||
VerticalAlignment="Stretch"
|
||||
Style="{StaticResource MathRichEdit_EquationTextBoxStyle}"
|
||||
Style="{StaticResource MathRichEditBoxStyle}"
|
||||
Background="Transparent"
|
||||
BorderThickness="0"
|
||||
FontFamily="{TemplateBinding FontFamily}"
|
||||
|
Reference in New Issue
Block a user