mirror of
https://github.com/Microsoft/calculator.git
synced 2025-07-16 02:02:51 -07:00
Feature/GraphingCalculator initial commit (#450)
Initial PR for the feature/GraphingCalculator feature branch, part of #338. The feature incorporates a proprietary Microsoft-owned graphing engine to drive graphing experiences in the Windows Calculator app. Due to the private nature of the graphing engine, the source available in the public repo will make use of a mock graphing engine. See README.md for more details. This PR simply serves as a base for future feature development. As such, the PR will be immediately merged. Feedback on the content of this PR, and on the feature in general, is encouraged. If there is feedback related to the content of this specific PR, please leave comments on the PR page. We will address the comments in future PRs to the feature branch.
This commit is contained in:
parent
47a2741218
commit
091732aa94
65 changed files with 5190 additions and 109 deletions
|
@ -0,0 +1,108 @@
|
|||
#include "pch.h"
|
||||
#include "EquationInputArea.xaml.h"
|
||||
#include "CalcViewModel/Common/KeyboardShortcutManager.h"
|
||||
|
||||
using namespace CalculatorApp;
|
||||
using namespace CalculatorApp::Common;
|
||||
using namespace CalculatorApp::ViewModel;
|
||||
using namespace Platform;
|
||||
using namespace std;
|
||||
using namespace Windows::System;
|
||||
using namespace Windows::UI;
|
||||
using namespace Windows::UI::ViewManagement;
|
||||
using namespace Windows::UI::Xaml;
|
||||
using namespace Windows::UI::Xaml::Controls;
|
||||
using namespace Windows::UI::Xaml::Input;
|
||||
|
||||
namespace
|
||||
{
|
||||
const Color accentColor = (ref new UISettings())->GetColorValue(UIColorType::Accent);
|
||||
const Color lineColors[] = {
|
||||
accentColor,
|
||||
Colors::DarkOrange,
|
||||
Colors::MediumPurple,
|
||||
Colors::ForestGreen,
|
||||
Colors::BlueViolet,
|
||||
Colors::DarkRed,
|
||||
Colors::LightGoldenrodYellow,
|
||||
Colors::DarkOliveGreen
|
||||
};
|
||||
const size_t lineColorsSize = std::size(lineColors);
|
||||
|
||||
StringReference EquationsPropertyName(L"Equations");
|
||||
}
|
||||
|
||||
EquationInputArea::EquationInputArea()
|
||||
: m_lastLineColorIndex{ -1 }
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
void EquationInputArea::OnPropertyChanged(String^ propertyName)
|
||||
{
|
||||
if (propertyName == EquationsPropertyName)
|
||||
{
|
||||
OnEquationsPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void EquationInputArea::OnEquationsPropertyChanged()
|
||||
{
|
||||
if (Equations != nullptr && Equations->Size == 0)
|
||||
{
|
||||
AddNewEquation();
|
||||
|
||||
// For now, the first equation needs to be y = 0.
|
||||
// We can remove this when we can create empty graphs.
|
||||
if (EquationViewModel^ eqvm = Equations->GetAt(0))
|
||||
{
|
||||
eqvm->Expression = L"0";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EquationInputArea::AddEquationButton_Click(Object^ sender, RoutedEventArgs^ e)
|
||||
{
|
||||
AddNewEquation();
|
||||
}
|
||||
|
||||
void EquationInputArea::AddNewEquation()
|
||||
{
|
||||
auto eq = ref new EquationViewModel();
|
||||
eq->LineColor = GetNextLineColor();
|
||||
|
||||
Equations->Append(eq);
|
||||
EquationInputList->ScrollIntoView(eq);
|
||||
}
|
||||
|
||||
void EquationInputArea::InputTextBox_GotFocus(Object^ sender, RoutedEventArgs^ e)
|
||||
{
|
||||
KeyboardShortcutManager::HonorShortcuts(false);
|
||||
}
|
||||
|
||||
void EquationInputArea::InputTextBox_LostFocus(Object^ sender, RoutedEventArgs^ e)
|
||||
{
|
||||
KeyboardShortcutManager::HonorShortcuts(true);
|
||||
|
||||
auto tb = static_cast<TextBox^>(sender);
|
||||
auto eq = static_cast<EquationViewModel^>(tb->DataContext);
|
||||
tb->Text = eq->Expression;
|
||||
}
|
||||
|
||||
void EquationInputArea::InputTextBox_KeyUp(Object^ sender, KeyRoutedEventArgs^ e)
|
||||
{
|
||||
if (e->Key == VirtualKey::Enter)
|
||||
{
|
||||
auto tb = static_cast<TextBox^>(sender);
|
||||
auto eq = static_cast<EquationViewModel^>(tb->DataContext);
|
||||
eq->Expression = tb->Text;
|
||||
|
||||
e->Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
Color EquationInputArea::GetNextLineColor()
|
||||
{
|
||||
m_lastLineColorIndex = (m_lastLineColorIndex + 1) % lineColorsSize;
|
||||
return lineColors[m_lastLineColorIndex];
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue