Persist variable settings after graph is plotted (#1055)
* Allow copying graph as image * Persist variables * Revert "Allow copying graph as image" This reverts commit 4fc9d798bc5f3ff82efc4fb00140103213fb81e2. * fix binding bug * undo cert change * fix animation * remove extra lines * remove overrides * undo key comment
This commit is contained in:
@@ -10,6 +10,7 @@ using namespace Platform::Collections;
|
||||
using namespace Windows::Foundation;
|
||||
using namespace Windows::Foundation::Collections;
|
||||
using namespace Windows::UI::Xaml::Data;
|
||||
using namespace GraphControl;
|
||||
|
||||
namespace CalculatorApp::ViewModel
|
||||
{
|
||||
@@ -24,12 +25,12 @@ namespace CalculatorApp::ViewModel
|
||||
{
|
||||
}
|
||||
|
||||
void GraphingCalculatorViewModel::UpdateVariables(IMap<String ^, double> ^ variables)
|
||||
void GraphingCalculatorViewModel::UpdateVariables(IMap<String ^, Variable ^> ^ variables)
|
||||
{
|
||||
Variables->Clear();
|
||||
for (auto var : variables)
|
||||
for (auto variablePair : variables)
|
||||
{
|
||||
auto variable = ref new VariableViewModel(var->Key, var->Value);
|
||||
auto variable = ref new VariableViewModel(variablePair->Key, variablePair->Value);
|
||||
variable->VariableUpdated += ref new EventHandler<VariableChangedEventArgs>([this, variable](Object ^ sender, VariableChangedEventArgs e) {
|
||||
VariableUpdated(variable, VariableChangedEventArgs{ e.variableName, e.newValue });
|
||||
});
|
||||
|
@@ -24,7 +24,7 @@ namespace CalculatorApp::ViewModel
|
||||
|
||||
event Windows::Foundation::EventHandler<VariableChangedEventArgs> ^ VariableUpdated;
|
||||
|
||||
void UpdateVariables(Windows::Foundation::Collections::IMap<Platform::String ^, double> ^ variables);
|
||||
void UpdateVariables(Windows::Foundation::Collections::IMap<Platform::String ^, GraphControl::Variable ^> ^ variables);
|
||||
|
||||
void SetSelectedEquation(EquationViewModel ^ equation);
|
||||
private:
|
||||
|
@@ -18,47 +18,89 @@ public
|
||||
[Windows::UI::Xaml::Data::Bindable] public ref class VariableViewModel sealed : public Windows::UI::Xaml::Data::INotifyPropertyChanged
|
||||
{
|
||||
public:
|
||||
VariableViewModel(Platform::String ^ name, double value)
|
||||
VariableViewModel(Platform::String ^ name, GraphControl::Variable ^ variable)
|
||||
: m_Name(name)
|
||||
, m_Value(value)
|
||||
, m_variable{ variable }
|
||||
, m_SliderSettingsVisible(false)
|
||||
, m_Min(0.0)
|
||||
, m_Step(0.1)
|
||||
, m_Max(2.0)
|
||||
{
|
||||
}
|
||||
|
||||
OBSERVABLE_OBJECT();
|
||||
OBSERVABLE_PROPERTY_R(Platform::String ^, Name);
|
||||
OBSERVABLE_PROPERTY_RW(double, Min);
|
||||
OBSERVABLE_PROPERTY_RW(double, Step);
|
||||
OBSERVABLE_PROPERTY_RW(double, Max);
|
||||
OBSERVABLE_PROPERTY_RW(bool, SliderSettingsVisible);
|
||||
|
||||
property double Min
|
||||
{
|
||||
double get()
|
||||
{
|
||||
return m_variable->Min;
|
||||
}
|
||||
void set(double value)
|
||||
{
|
||||
if (m_variable->Min != value)
|
||||
{
|
||||
m_variable->Min = value;
|
||||
RaisePropertyChanged("Min");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
property double Step
|
||||
{
|
||||
double get()
|
||||
{
|
||||
return m_variable->Step;
|
||||
}
|
||||
void set(double value)
|
||||
{
|
||||
if (m_variable->Step != value)
|
||||
{
|
||||
m_variable->Step = value;
|
||||
RaisePropertyChanged("Step");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
property double Max
|
||||
{
|
||||
double get()
|
||||
{
|
||||
return m_variable->Max;
|
||||
}
|
||||
void set(double value)
|
||||
{
|
||||
if (m_variable->Max != value)
|
||||
{
|
||||
m_variable->Max = value;
|
||||
RaisePropertyChanged("Max");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
event Windows::Foundation::EventHandler<VariableChangedEventArgs> ^ VariableUpdated;
|
||||
|
||||
property double Value
|
||||
{
|
||||
double get()
|
||||
{
|
||||
return m_Value;
|
||||
return m_variable->Value;
|
||||
}
|
||||
void set(double value)
|
||||
{
|
||||
if (value < Min)
|
||||
if (value < m_variable->Min)
|
||||
{
|
||||
Min = value;
|
||||
m_variable->Min = value;
|
||||
RaisePropertyChanged(L"Min");
|
||||
}
|
||||
else if (value > Max)
|
||||
else if (value > m_variable->Max)
|
||||
{
|
||||
Max = value;
|
||||
m_variable->Max = value;
|
||||
RaisePropertyChanged(L"Max");
|
||||
}
|
||||
|
||||
if (Value != value)
|
||||
if (m_variable->Value != value)
|
||||
{
|
||||
m_Value = value;
|
||||
m_variable->Value = value;
|
||||
VariableUpdated(this, VariableChangedEventArgs{ Name, value });
|
||||
RaisePropertyChanged(L"Value");
|
||||
}
|
||||
@@ -66,6 +108,6 @@ public
|
||||
}
|
||||
|
||||
private:
|
||||
double m_Value;
|
||||
GraphControl::Variable ^ m_variable;
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user