Skip to content

Commit

Permalink
Fix some UI bugs in graph mode (#862)
Browse files Browse the repository at this point in the history
* Address issues with error states

* Add various fixes

* Add back initial tooltip

* PR comments
  • Loading branch information
joseartrivera committed Dec 12, 2019
1 parent f282605 commit 2a0637e
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 25 deletions.
12 changes: 9 additions & 3 deletions src/Calculator/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -1923,9 +1923,9 @@
</VisualState>
<VisualState x:Name="PointerOverError">
<VisualState.Setters>
<Setter Target="EquationBoxBorder.BorderBrush" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=EquationColor}"/>
<Setter Target="EquationBoxBorder.BorderBrush" Value="{ThemeResource EquationBoxErrorBorderBrush}"/>
<Setter Target="EquationBoxBorder.Background" Value="{ThemeResource EquationBoxErrorBackgroundBrush}"/>
<Setter Target="ColorChooserButton.Visibility" Value="Visible"/>
<Setter Target="ColorChooserButton.Visibility" Value="Collapsed"/>
<Setter Target="FunctionButton.Visibility" Value="Collapsed"/>
<Setter Target="RemoveButton.Visibility" Value="Visible"/>
<Setter Target="ErrorIcon.Visibility" Value="Collapsed"/>
Expand All @@ -1944,12 +1944,18 @@
<Setter Target="EquationBoxBorder.Background" Value="{ThemeResource TextBoxBackgroundThemeBrush}"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="FocusedError">
<VisualState.Setters>
<Setter Target="EquationBoxBorder.BorderBrush" Value="{ThemeResource EquationBoxErrorBorderBrush}"/>
<Setter Target="EquationBoxBorder.Background" Value="{ThemeResource TextBoxBackgroundThemeBrush}"/>
<Setter Target="ErrorIcon.Visibility" Value="Collapsed"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="ButtonStates">
<VisualState x:Name="ButtonVisible">
<VisualState.Setters>
<Setter Target="DeleteButton.Visibility" Value="Visible"/>
<Setter Target="ErrorIcon.Visibility" Value="Collapsed"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="ButtonHideRemove">
Expand Down
13 changes: 11 additions & 2 deletions src/Calculator/Controls/EquationTextBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,11 @@ void EquationTextBox::UpdateCommonVisualState()
{
String ^ state = nullptr;

if (m_HasFocus)
if (m_HasFocus && HasError)
{
state = "FocusedError";
}
else if (m_HasFocus)
{
state = "Focused";
}
Expand Down Expand Up @@ -390,7 +394,12 @@ void EquationTextBox::OnRichEditMenuOpening(Object ^ /*sender*/, Object ^ /*args
{
if (m_kgfEquationMenuItem != nullptr)
{
m_kgfEquationMenuItem->IsEnabled = EquationTextBox::RichEditHasContent();
m_kgfEquationMenuItem->IsEnabled = RichEditHasContent();
}

if (m_colorChooserMenuItem != nullptr)
{
m_colorChooserMenuItem->IsEnabled = !HasError;
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/Calculator/Resources/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -4096,11 +4096,11 @@
<comment>Title for KeyGraphFeatures Vertical Asymptotes Property</comment>
</data>
<data name="XIntercept" xml:space="preserve">
<value>X Intercept</value>
<value>X-Intercept</value>
<comment>Title for KeyGraphFeatures XIntercept Property</comment>
</data>
<data name="YIntercept" xml:space="preserve">
<value>Y Intercept</value>
<value>Y-Intercept</value>
<comment>Title for KeyGraphFeatures YIntercept Property</comment>
</data>
<data name="KGFAnalysisCouldNotBePerformed" xml:space="preserve">
Expand Down Expand Up @@ -4222,4 +4222,4 @@
<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>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,7 @@
<!-- Ideally the KeyGraphFeaturesPanel should be a frame so that navigation to and from the panel could be handled nicely -->
<local:KeyGraphFeaturesPanel x:Name="KeyGraphFeaturesControl"
Grid.RowSpan="2"
Margin="0,4,0,0"
KeyGraphFeaturesClosed="OnKeyGraphFeaturesClosed"
ViewModel="{x:Bind EquationInputAreaControl.EquationVM, Mode=OneWay}"
Visibility="{x:Bind IsKeyGraphFeaturesVisible, Mode=OneWay}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,12 @@ void GraphingCalculator::OnEquationsVectorChanged(IObservableVector<EquationView

void GraphingCalculator::OnTracePointChanged(Windows::Foundation::Point newPoint)
{
TraceValue->Text = "(" + newPoint.X.ToString() + ", " + newPoint.Y.ToString() + ")";
wstringstream traceValueString;

// TODO: The below precision should ideally be dynamic based on the current scale of the graph.
traceValueString << "x=" << fixed << setprecision(1) << newPoint.X << ", y=" << fixed << setprecision(1) << newPoint.Y;

TraceValue->Text = ref new String(traceValueString.str().c_str());

auto peer = FrameworkElementAutomationPeer::FromElement(TraceValue);

Expand Down Expand Up @@ -507,6 +512,8 @@ ::Visibility GraphingCalculator::ManageEditVariablesButtonVisibility(unsigned in

void CalculatorApp::GraphingCalculator::ActiveTracing_Checked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e)
{
GraphingControl->Focus(::FocusState::Programmatic);

m_activeTracingKeyUpToken = Window::Current->CoreWindow->KeyUp +=
ref new Windows::Foundation::TypedEventHandler<Windows::UI::Core::CoreWindow ^, Windows::UI::Core::KeyEventArgs ^>(
this, &CalculatorApp::GraphingCalculator::ActiveTracing_KeyUp);
Expand Down
22 changes: 14 additions & 8 deletions src/Calculator/Views/GraphingCalculator/KeyGraphFeaturesPanel.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="controls:EquationTextBox">
<Grid>
<Grid Background="{ThemeResource TextControlBackground}">

<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
Expand Down Expand Up @@ -102,7 +102,7 @@
<Setter Property="IsReadOnly" Value="True"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="IsEnabled" Value="True"/>
<Setter Property="Margin" Value="-8,0,0,0"/>
<Setter Property="Padding" Value="0,3,4,0"/>
<Setter Property="UseSystemFocusVisuals" Value="True"/>
<Setter Property="TextWrapping" Value="NoWrap"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
Expand Down Expand Up @@ -169,8 +169,8 @@
<Border x:Name="BorderElement"
Grid.Row="1"
Grid.RowSpan="1"
MinWidth="{ThemeResource TextControlThemeMinWidth}"
MinHeight="{ThemeResource TextControlThemeMinHeight}"
MinWidth="0"
MinHeight="0"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Expand Down Expand Up @@ -224,6 +224,7 @@
<Style x:Name="KGF_TextBlockStyle" TargetType="TextBlock">
<Setter Property="FontWeight" Value="Normal"/>
<Setter Property="FontSize" Value="14"/>
<Setter Property="IsTextSelectionEnabled" Value="True"/>
<Setter Property="TextWrapping" Value="WrapWholeWords"/>
</Style>

Expand All @@ -243,6 +244,11 @@
Style="{StaticResource KGF_TitleTextBlockStyle}"
Text="{x:Bind Title, Mode=OneWay}"/>
<ItemsControl ItemsSource="{x:Bind DisplayItems, Mode=OneWay}" UseSystemFocusVisuals="True">
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Setter Property="Margin" Value="0"/>
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="x:String">
<controls:MathRichEditBox HorizontalAlignment="Left"
Expand All @@ -265,7 +271,7 @@
<DataTemplate x:DataType="vm:GridDisplayItems">
<Grid VerticalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto" MinWidth="64"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<controls:MathRichEditBox Grid.Column="0"
Expand Down Expand Up @@ -308,7 +314,7 @@
<converters:BooleanToVisibilityNegationConverter x:Name="BooleanToVisibilityNegationConverter"/>
</UserControl.Resources>

<Grid Margin="0,7,0,0" Background="Transparent">
<Grid Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
Expand All @@ -335,8 +341,7 @@

<ListView x:Name="KeyGraphFeaturesListView"
Grid.Row="2"
Margin="12,10,10,0"
Padding="0,0,0,12"
Padding="12,10,10,12"
IsItemClickEnabled="False"
ItemContainerStyle="{StaticResource KGF_ListViewItemContainerStyle}"
ItemTemplateSelector="{StaticResource KGFTemplateSelector}"
Expand All @@ -350,6 +355,7 @@
Margin="12,10,10,0"
Style="{StaticResource KGF_TextBlockStyle}"
FontWeight="Normal"
IsTextSelectionEnabled="False"
Text="{x:Bind ViewModel.AnalysisErrorString, Mode=OneWay}"
Visibility="{x:Bind ViewModel.AnalysisErrorVisible, Mode=OneWay}"/>
</Grid>
Expand Down
1 change: 1 addition & 0 deletions src/Calculator/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <concrt.h>
#include <regex>
#include <string>
#include <iomanip>

// C++\WinRT Headers
#include "winrt/base.h"
Expand Down
9 changes: 2 additions & 7 deletions src/GraphControl/Control/Grapher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,10 +621,9 @@ namespace GraphControl

void Grapher::UpdateTracingChanged()
{
if (m_renderMain->Tracing || m_renderMain->ActiveTracing)
if (m_renderMain->Tracing)
{
TracingChangedEvent(true);

TracingValueChangedEvent(m_renderMain->TraceValue);
}
else
Expand All @@ -650,11 +649,7 @@ namespace GraphControl
if (m_renderMain)
{
m_renderMain->DrawNearestPoint = false;
if (ActiveTracing == false)
{
// IF we are active tracing we never want to hide the popup..
TracingChangedEvent(false);
}
TracingChangedEvent(false);
e->Handled = true;
}
}
Expand Down
10 changes: 9 additions & 1 deletion src/GraphControl/DirectX/RenderMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace GraphControl::DX
, m_backgroundColor{ {} }
, m_swapChainPanel{ panel }
, m_TraceValue(Point(0, 0))
, m_TraceLocation(Point(0,0))
, m_TraceLocation(Point(0, 0))
, m_Tracing(false)
, m_ActiveTracingPointRenderer{ &m_deviceResources }
{
Expand Down Expand Up @@ -195,6 +195,14 @@ namespace GraphControl::DX

if (!isnan(nearestPointLocation.X) && !isnan(nearestPointLocation.Y))
{
auto lineColors = m_graph->GetOptions().GetGraphColors();

if (formulaId >= 0 && formulaId < lineColors.size())
{
auto dotColor = lineColors[formulaId];
m_nearestPointRenderer.SetColor(D2D1::ColorF(dotColor.R * 65536 + dotColor.G * 256 + dotColor.B, 1.0));
}

m_nearestPointRenderer.Render(nearestPointLocation);
m_Tracing = true;
m_TraceLocation = Point(nearestPointLocation.X, nearestPointLocation.Y);
Expand Down

0 comments on commit 2a0637e

Please sign in to comment.