Create EquationTextBox control (#547)

This commit is contained in:
Pepe Rivera
2019-06-25 13:40:56 -07:00
committed by GitHub
parent c3c001af28
commit 1475b49120
17 changed files with 1058 additions and 90 deletions

View File

@@ -35,8 +35,6 @@ namespace GraphControl
m_tokens.emplace_back(
value->PropertyChanged += ref new GraphControl::PropertyChangedEventHandler(this, &EquationCollection::OnEquationPropertyChanged)
);
EquationChanged();
}
virtual void Clear()
@@ -49,8 +47,6 @@ namespace GraphControl
m_vector->Clear();
m_tokens.clear();
EquationChanged();
}
virtual GraphControl::Equation^ GetAt(unsigned int index)
@@ -80,8 +76,6 @@ namespace GraphControl
m_tokens.begin() + index,
value->PropertyChanged += ref new PropertyChangedEventHandler(this, &EquationCollection::OnEquationPropertyChanged)
);
EquationChanged();
}
virtual void RemoveAt(unsigned int index)
@@ -90,8 +84,6 @@ namespace GraphControl
m_vector->RemoveAt(index);
m_tokens.erase(m_tokens.begin() + index);
EquationChanged();
}
virtual void RemoveAtEnd()
@@ -104,8 +96,6 @@ namespace GraphControl
}
m_vector->RemoveAtEnd();
EquationChanged();
}
virtual void ReplaceAll(const Platform::Array< GraphControl::Equation^ >^ items)
@@ -124,8 +114,6 @@ namespace GraphControl
}
m_vector->ReplaceAll(items);
EquationChanged();
}
virtual void SetAt(unsigned int index, GraphControl::Equation^ value)
@@ -135,8 +123,6 @@ namespace GraphControl
m_vector->SetAt(index, value);
m_tokens[index] =
value->PropertyChanged += ref new PropertyChangedEventHandler(this, &EquationCollection::OnEquationPropertyChanged);
EquationChanged();
}
#pragma endregion

View File

@@ -300,6 +300,17 @@ namespace GraphControl
void Grapher::OnEquationsVectorChanged(IObservableVector<Equation^>^ sender, IVectorChangedEventArgs^ event)
{
if (event->CollectionChange == ::CollectionChange::ItemInserted || event->CollectionChange == ::CollectionChange::ItemChanged)
{
auto eq = sender->GetAt(event->Index);
// Don't update the graph unless the equations being added/modified is valid.
if (eq->Expression->IsEmpty())
{
return;
}
}
UpdateGraph();
}
@@ -313,9 +324,9 @@ namespace GraphControl
if (m_renderMain && m_graph != nullptr)
{
auto validEqs = GetValidEquations();
if (!validEqs.empty())
{
wstringstream ss{};
ss << L"show2d(";
@@ -333,7 +344,8 @@ namespace GraphControl
ss << L")";
wstring request = ss.str();
if (auto graphExpression = m_solver->ParseInput(request))
unique_ptr<IExpression> graphExpression;
if (graphExpression = m_solver->ParseInput(request))
{
if (m_graph->TryInitialize(graphExpression.get()))
{
@@ -343,6 +355,15 @@ namespace GraphControl
}
}
}
else
{
if (m_graph->TryInitialize())
{
UpdateGraphOptions(m_graph->GetOptions(), validEqs);
m_renderMain->Graph = m_graph;
}
}
}
}
@@ -350,18 +371,21 @@ namespace GraphControl
{
options.SetForceProportional(ForceProportionalAxes);
vector<Graphing::Color> graphColors;
graphColors.reserve(validEqs.size());
for (Equation^ eq : validEqs)
if (!validEqs.empty())
{
auto lineColor = eq->LineColor;
graphColors.emplace_back(
lineColor.R,
lineColor.G,
lineColor.B,
lineColor.A);
vector<Graphing::Color> graphColors;
graphColors.reserve(validEqs.size());
for (Equation^ eq : validEqs)
{
auto lineColor = eq->LineColor;
graphColors.emplace_back(
lineColor.R,
lineColor.G,
lineColor.B,
lineColor.A);
}
options.SetGraphColors(graphColors);
}
options.SetGraphColors(graphColors);
}
vector<Equation^> Grapher::GetValidEquations()