Skip to content

Commit

Permalink
Added support for small windows in the graphing calculator (#803)
Browse files Browse the repository at this point in the history
* Add support of small windows

* remove extra space

* Modify how we manage the tooltip

* Fix merge issues
  • Loading branch information
rudyhuyn authored and joseartrivera committed Nov 22, 2019
1 parent a33c1a4 commit 7ef6eaf
Show file tree
Hide file tree
Showing 8 changed files with 516 additions and 217 deletions.
10 changes: 10 additions & 0 deletions src/CalcViewModel/Common/Automation/NarratorAnnouncement.cpp
Expand Up @@ -22,6 +22,7 @@ namespace CalculatorApp::Common::Automation
StringReference DisplayCopied(L"DisplayCopied");
StringReference OpenParenthesisCountChanged(L"OpenParenthesisCountChanged");
StringReference NoParenthesisAdded(L"NoParenthesisAdded");
StringReference GraphModeChanged(L"GraphModeChanged");
}
}

Expand Down Expand Up @@ -139,3 +140,12 @@ NarratorAnnouncement ^ CalculatorAnnouncement::GetNoRightParenthesisAddedAnnounc
AutomationNotificationKind::ActionCompleted,
AutomationNotificationProcessing::ImportantMostRecent);
}

NarratorAnnouncement ^ CalculatorAnnouncement::GetGraphModeChangedAnnouncement(Platform::String ^ announcement)
{
return ref new NarratorAnnouncement(
announcement,
CalculatorActivityIds::GraphModeChanged,
AutomationNotificationKind::ActionCompleted,
AutomationNotificationProcessing::ImportantMostRecent);
}
3 changes: 3 additions & 0 deletions src/CalcViewModel/Common/Automation/NarratorAnnouncement.h
Expand Up @@ -92,5 +92,8 @@ public

static NarratorAnnouncement ^ GetOpenParenthesisCountChangedAnnouncement(Platform::String ^ announcement);
static NarratorAnnouncement ^ GetNoRightParenthesisAddedAnnouncement(Platform::String ^ announcement);

static NarratorAnnouncement ^ GetGraphModeChangedAnnouncement(Platform::String ^ announcement);

};
}
6 changes: 0 additions & 6 deletions src/Calculator/Calculator.vcxproj.filters
Expand Up @@ -1489,11 +1489,5 @@
<ItemGroup>
<CopyFileToFolders Include="$(GraphingImplDll)" />
<CopyFileToFolders Include="$(GraphingEngineDll)" />
<CopyFileToFolders Include="$(GraphingImplDll)" />
<CopyFileToFolders Include="$(GraphingEngineDll)" />
<CopyFileToFolders Include="$(GraphingImplDll)" />
<CopyFileToFolders Include="$(GraphingEngineDll)" />
<CopyFileToFolders Include="$(GraphingImplDll)" />
<CopyFileToFolders Include="$(GraphingEngineDll)" />
</ItemGroup>
</Project>
22 changes: 21 additions & 1 deletion src/Calculator/Resources/en-US/Resources.resw
Expand Up @@ -3698,4 +3698,24 @@
<value>Unable to calculate the range for this function.</value>
<comment>Error displayed when Range is not returned from the analyzer.</comment>
</data>
</root>
<data name="GraphSwitchToEquationMode" xml:space="preserve">
<value>Switch to equation mode</value>
<comment>Used in Graphing Calculator to switch the view to the equation mode</comment>
</data>
<data name="GraphSwitchToGraphMode" xml:space="preserve">
<value>Switch to graph mode</value>
<comment>Used in Graphing Calculator to switch the view to the graph mode</comment>
</data>
<data name="SwitchModeToggleButton.[using:Windows.UI.Xaml.Automation]AutomationProperties.Name" xml:space="preserve">
<value>Switch to equation mode</value>
<comment>Used in Graphing Calculator to switch the view to the equation mode</comment>
</data>
<data name="GraphSwitchedToEquationModeAnnouncement" xml:space="preserve">
<value>Current mode is equation mode</value>
<comment>Announcement used in Graphing Calculator when switching to the equation mode</comment>
</data>
<data name="GraphSwitchedToGraphModeAnnouncement" xml:space="preserve">
<value>Current mode is graph mode</value>
<comment>Announcement used in Graphing Calculator when switching to the graph mode</comment>
</data>
</root>
578 changes: 391 additions & 187 deletions src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml

Large diffs are not rendered by default.

79 changes: 69 additions & 10 deletions src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.cpp
Expand Up @@ -5,7 +5,10 @@
#include "GraphingCalculator.xaml.h"
#include "CalcViewModel/Common/TraceLogger.h"
#include "CalcViewModel/Common/LocalizationSettings.h"
#include "CalcViewModel/Common/AppResourceProvider.h"
#include "CalcViewModel/Common/KeyboardShortcutManager.h"
#include "CalcViewModel/Common/Automation/NarratorAnnouncement.h"
#include "CalcViewModel/Common/Automation/NarratorNotifier.h"
#include "Controls/CalculationResult.h"
#include "CalcManager/NumberFormattingUtils.h"
#include "Calculator/Controls/EquationTextBox.h"
Expand All @@ -14,6 +17,7 @@

using namespace CalculatorApp;
using namespace CalculatorApp::Common;
using namespace CalculatorApp::Common::Automation;
using namespace CalculatorApp::Controls;
using namespace CalculatorApp::ViewModel;
using namespace CalcManager::NumberFormattingUtils;
Expand Down Expand Up @@ -42,6 +46,8 @@ using namespace Windows::UI::Popups;

constexpr auto sc_ViewModelPropertyName = L"ViewModel";

DEPENDENCY_PROPERTY_INITIALIZATION(GraphingCalculator, IsSmallState);

GraphingCalculator::GraphingCalculator()
: ActiveTracingOn(false)
{
Expand All @@ -64,14 +70,9 @@ GraphingCalculator::GraphingCalculator()

void GraphingCalculator::OnShowTracePopupChanged(bool newValue)
{
if (TraceValuePopup->IsOpen != newValue)
if ((TraceValuePopup->Visibility == ::Visibility::Visible) != newValue)
{
TraceValuePopup->IsOpen = newValue;
if (TraceValuePopup->IsOpen)
{
// Set the keyboard focus to the graph control so we can use the arrow keys safely.
GraphingControl->Focus(::FocusState::Programmatic);
}
TraceValuePopup->Visibility = newValue ? ::Visibility::Visible : ::Visibility::Collapsed;
}
}

Expand Down Expand Up @@ -118,10 +119,8 @@ void GraphingCalculator::OnEquationsVectorChanged(IObservableVector<EquationView

void GraphingCalculator::OnTracePointChanged(Windows::Foundation::Point newPoint)
{
TraceValuePopupTransform->X = (int)GraphingControl->TraceLocation.X + 15;
TraceValuePopupTransform->Y = (int)GraphingControl->TraceLocation.Y - 30;

TraceValue->Text = "(" + newPoint.X.ToString() + ", " + newPoint.Y.ToString() + ")";
PositionGraphPopup();
}

GraphingCalculatorViewModel ^ GraphingCalculator::ViewModel::get()
Expand Down Expand Up @@ -377,3 +376,63 @@ void GraphingCalculator::OnKeyGraphFeaturesClosed(Object ^ sender, RoutedEventAr
{
IsKeyGraphFeaturesVisible = false;
}

Visibility GraphingCalculator::ShouldDisplayPanel(bool isSmallState, bool isEquationModeActivated, bool isGraphPanel)
{
return (!isSmallState || isEquationModeActivated ^ isGraphPanel) ? ::Visibility::Visible : ::Visibility::Collapsed;
}

Platform::String ^ GraphingCalculator::GetInfoForSwitchModeToggleButton(bool isChecked)
{
if (isChecked)
{
return AppResourceProvider::GetInstance().GetResourceString(L"GraphSwitchToGraphMode");
}
else
{
return AppResourceProvider::GetInstance().GetResourceString(L"GraphSwitchToEquationMode");
}
}

void GraphingCalculator::SwitchModeToggleButton_Checked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e)
{
auto narratorNotifier = ref new NarratorNotifier();
String ^ announcementText;
if (SwitchModeToggleButton->IsChecked->Value)
{
announcementText = AppResourceProvider::GetInstance().GetResourceString(L"GraphSwitchedToEquationModeAnnouncement");
}
else
{
announcementText = AppResourceProvider::GetInstance().GetResourceString(L"GraphSwitchedToGraphModeAnnouncement");
}

auto announcement = CalculatorAnnouncement::GetGraphModeChangedAnnouncement(announcementText);
narratorNotifier->Announce(announcement);
}

void GraphingCalculator::PositionGraphPopup()
{
if (GraphingControl->TraceLocation.X + 15 + TraceValuePopup->ActualWidth >= GraphingControl->ActualWidth)
{
TraceValuePopupTransform->X = (int)GraphingControl->TraceLocation.X - 15 - TraceValuePopup->ActualWidth;
}
else
{
TraceValuePopupTransform->X = (int)GraphingControl->TraceLocation.X + 15;
}

if (GraphingControl->TraceLocation.Y >= 30)
{
TraceValuePopupTransform->Y = (int)GraphingControl->TraceLocation.Y - 30;
}
else
{
TraceValuePopupTransform->Y = (int)GraphingControl->TraceLocation.Y;
}
}

void GraphingCalculator::TraceValuePopup_SizeChanged(Platform::Object ^ sender, Windows::UI::Xaml::SizeChangedEventArgs ^ e)
{
PositionGraphPopup();
}
33 changes: 21 additions & 12 deletions src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.h
Expand Up @@ -13,63 +13,72 @@ namespace CalculatorApp
constexpr double zoomInScale = 1 / 1.0625;
constexpr double zoomOutScale = 1.0625;

public ref class GraphingCalculator sealed : public Windows::UI::Xaml::Data::INotifyPropertyChanged
public ref class GraphingCalculator sealed : public Windows::UI::Xaml::Data::INotifyPropertyChanged
{
public:
GraphingCalculator();

OBSERVABLE_OBJECT();
DEPENDENCY_PROPERTY_OWNER(GraphingCalculator);
COMMAND_FOR_METHOD(ZoomOutButtonPressed, GraphingCalculator::OnZoomOutCommand);
COMMAND_FOR_METHOD(ZoomInButtonPressed, GraphingCalculator::OnZoomInCommand);
COMMAND_FOR_METHOD(ZoomResetButtonPressed, GraphingCalculator::OnZoomResetCommand);
OBSERVABLE_PROPERTY_RW(bool, IsKeyGraphFeaturesVisible);
DEPENDENCY_PROPERTY(bool, IsSmallState);

property CalculatorApp::ViewModel::GraphingCalculatorViewModel^ ViewModel
{
CalculatorApp::ViewModel::GraphingCalculatorViewModel^ get();
void set(CalculatorApp::ViewModel::GraphingCalculatorViewModel^ vm);
}

Windows::UI::Xaml::Visibility ShouldDisplayPanel(bool isSmallState, bool isEquationModeActivated, bool isGraphPanel);
Platform::String ^ GetInfoForSwitchModeToggleButton(bool isChecked);
private:
void GraphingCalculator_DataContextChanged(Windows::UI::Xaml::FrameworkElement^ sender, Windows::UI::Xaml::DataContextChangedEventArgs^ args);
void GraphingCalculator_DataContextChanged(Windows::UI::Xaml::FrameworkElement ^ sender, Windows::UI::Xaml::DataContextChangedEventArgs ^ args);

void OnVariableChanged(Platform::Object^ sender, CalculatorApp::ViewModel::VariableChangedEventArgs 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,
Windows::Foundation::Collections::IVectorChangedEventArgs ^ event);

void TextBoxLosingFocus(Windows::UI::Xaml::Controls::TextBox^ textbox, Windows::UI::Xaml::Input::LosingFocusEventArgs^ args);
void TextBoxKeyDown(Windows::UI::Xaml::Controls::TextBox^ textbox, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e);
void SubmitTextbox(Windows::UI::Xaml::Controls::TextBox^ textbox);
void TextBoxLosingFocus(Windows::UI::Xaml::Controls::TextBox ^ textbox, Windows::UI::Xaml::Input::LosingFocusEventArgs ^ args);
void TextBoxKeyDown(Windows::UI::Xaml::Controls::TextBox ^ textbox, Windows::UI::Xaml::Input::KeyRoutedEventArgs ^ e);
void SubmitTextbox(Windows::UI::Xaml::Controls::TextBox ^ textbox);

void OnZoomInCommand(Object ^ parameter);
void OnZoomOutCommand(Object ^ parameter);
void OnZoomResetCommand(Object ^ parameter);

double validateDouble(Platform::String^ value, double defaultValue);
double validateDouble(Platform::String ^ value, double defaultValue);

CalculatorApp::ViewModel::GraphingCalculatorViewModel^ m_viewModel;
CalculatorApp::ViewModel::GraphingCalculatorViewModel ^ m_viewModel;

void OnShareClick(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void OnShareClick(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);

void OnShowTracePopupChanged(bool newValue);
void OnTracePointChanged(Windows::Foundation::Point newPoint);


private:
Windows::Foundation::EventRegistrationToken m_dataRequestedToken;
Windows::Foundation::EventRegistrationToken m_vectorChangedToken;
Windows::Foundation::EventRegistrationToken m_variableUpdatedToken;
void OnDataRequested(Windows::ApplicationModel::DataTransfer::DataTransferManager^ sender, Windows::ApplicationModel::DataTransfer::DataRequestedEventArgs^ e);
void OnDataRequested(
Windows::ApplicationModel::DataTransfer::DataTransferManager ^ sender,
Windows::ApplicationModel::DataTransfer::DataRequestedEventArgs ^ e);

void TextBoxGotFocus(Windows::UI::Xaml::Controls::TextBox^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void TextBoxGotFocus(Windows::UI::Xaml::Controls::TextBox ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
void OnActiveTracingClick(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
void GraphingControl_LostFocus(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
void GraphingControl_LosingFocus(Windows::UI::Xaml::UIElement ^ sender, Windows::UI::Xaml::Input::LosingFocusEventArgs ^ args);
void GraphingControl_VariablesUpdated(Platform::Object ^ sender, Object ^ args);
void OnEquationKeyGraphFeaturesRequested(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
void OnKeyGraphFeaturesClosed(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
bool ActiveTracingOn;
void SwitchModeToggleButton_Checked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
void TraceValuePopup_SizeChanged(Platform::Object ^ sender, Windows::UI::Xaml::SizeChangedEventArgs ^ e);
void PositionGraphPopup();
};

}
2 changes: 1 addition & 1 deletion src/Calculator/Views/MainPage.xaml
Expand Up @@ -96,7 +96,7 @@
<Border x:Name="DateCalcHolder">
<!-- PLACEHOLDER!!!! This is where the date calculator goes when it is delay loaded -->
</Border>
<Border x:Name="GraphingCalcHolder" Grid.Row="1">
<Border x:Name="GraphingCalcHolder">
<!-- PLACEHOLDER!!!! This is where the graphing calculator goes when it is delay loaded -->
</Border>
<Border x:Name="ConverterHolder">
Expand Down

0 comments on commit 7ef6eaf

Please sign in to comment.