Fix usability issues with settings flyout (#1049)
* various settings fixes * PR fixes
This commit is contained in:
parent
1f56b4946d
commit
0c8d6dd83c
@ -20,7 +20,7 @@ GraphingSettingsViewModel::GraphingSettingsViewModel()
|
|||||||
, m_XMaxError(false)
|
, m_XMaxError(false)
|
||||||
, m_YMinError(false)
|
, m_YMinError(false)
|
||||||
, m_YMaxError(false)
|
, m_YMaxError(false)
|
||||||
, m_dontUpdateDisplayRange(false)
|
, m_dontUpdateDisplayRange()
|
||||||
, m_XIsMinLastChanged(true)
|
, m_XIsMinLastChanged(true)
|
||||||
, m_YIsMinLastChanged(true)
|
, m_YIsMinLastChanged(true)
|
||||||
{
|
{
|
||||||
@ -71,75 +71,13 @@ void GraphingSettingsViewModel::InitRanges()
|
|||||||
m_dontUpdateDisplayRange = false;
|
m_dontUpdateDisplayRange = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphingSettingsViewModel::UpdateDisplayRange(bool XValuesModified)
|
void GraphingSettingsViewModel::UpdateDisplayRange()
|
||||||
{
|
{
|
||||||
if (m_Graph == nullptr || m_dontUpdateDisplayRange || HasError())
|
if (m_Graph == nullptr || m_dontUpdateDisplayRange || HasError())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_Graph->ForceProportionalAxes)
|
|
||||||
{
|
|
||||||
// If ForceProportionalAxes is set, the graph will try to automatically adjust ranges to remain proportional.
|
|
||||||
// but without a logic to choose which values can be modified or not.
|
|
||||||
// To solve this problem, we calculate the new ranges here, taking care to not modify the current axis and
|
|
||||||
// modifying only the least recently updated value of the other axis.
|
|
||||||
|
|
||||||
if (XValuesModified)
|
|
||||||
{
|
|
||||||
if (m_YIsMinLastChanged)
|
|
||||||
{
|
|
||||||
auto yMaxValue = m_YMinValue + (m_XMaxValue - m_XMinValue) * m_Graph->ActualHeight / m_Graph->ActualWidth;
|
|
||||||
if (m_YMaxValue != yMaxValue)
|
|
||||||
{
|
|
||||||
m_YMaxValue = yMaxValue;
|
|
||||||
auto valueStr = to_wstring(m_YMaxValue);
|
|
||||||
TrimTrailingZeros(valueStr);
|
|
||||||
m_YMax = ref new String(valueStr.c_str());
|
|
||||||
RaisePropertyChanged("YMax");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
auto yMinValue = m_YMaxValue - (m_XMaxValue - m_XMinValue) * m_Graph->ActualHeight / m_Graph->ActualWidth;
|
|
||||||
if (m_YMinValue != yMinValue)
|
|
||||||
{
|
|
||||||
m_YMinValue = yMinValue;
|
|
||||||
auto valueStr = to_wstring(m_YMinValue);
|
|
||||||
TrimTrailingZeros(valueStr);
|
|
||||||
m_YMin = ref new String(valueStr.c_str());
|
|
||||||
RaisePropertyChanged("YMin");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (m_XIsMinLastChanged)
|
|
||||||
{
|
|
||||||
auto xMaxValue = m_XMinValue + (m_YMaxValue - m_YMinValue) * m_Graph->ActualWidth / m_Graph->ActualHeight;
|
|
||||||
if (m_XMaxValue != xMaxValue)
|
|
||||||
{
|
|
||||||
m_XMaxValue = xMaxValue;
|
|
||||||
auto valueStr = to_wstring(m_XMaxValue);
|
|
||||||
TrimTrailingZeros(valueStr);
|
|
||||||
m_XMax = ref new String(valueStr.c_str());
|
|
||||||
RaisePropertyChanged("XMax");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
auto xMinValue = m_XMaxValue - (m_YMaxValue - m_YMinValue) * m_Graph->ActualWidth / m_Graph->ActualHeight;
|
|
||||||
if (m_XMinValue != xMinValue)
|
|
||||||
{
|
|
||||||
m_XMinValue = xMinValue;
|
|
||||||
auto valueStr = to_wstring(m_XMinValue);
|
|
||||||
TrimTrailingZeros(valueStr);
|
|
||||||
m_XMin = ref new String(valueStr.c_str());
|
|
||||||
RaisePropertyChanged("XMin");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m_Graph->SetDisplayRanges(m_XMinValue, m_XMaxValue, m_YMinValue, m_YMaxValue);
|
m_Graph->SetDisplayRanges(m_XMinValue, m_XMaxValue, m_YMinValue, m_YMaxValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ namespace CalculatorApp::ViewModel
|
|||||||
}
|
}
|
||||||
RaisePropertyChanged("XError");
|
RaisePropertyChanged("XError");
|
||||||
RaisePropertyChanged("XMin");
|
RaisePropertyChanged("XMin");
|
||||||
UpdateDisplayRange(true);
|
UpdateDisplayRange();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +112,7 @@ namespace CalculatorApp::ViewModel
|
|||||||
}
|
}
|
||||||
RaisePropertyChanged("XError");
|
RaisePropertyChanged("XError");
|
||||||
RaisePropertyChanged("XMax");
|
RaisePropertyChanged("XMax");
|
||||||
UpdateDisplayRange(true);
|
UpdateDisplayRange();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,7 +153,7 @@ namespace CalculatorApp::ViewModel
|
|||||||
}
|
}
|
||||||
RaisePropertyChanged("YError");
|
RaisePropertyChanged("YError");
|
||||||
RaisePropertyChanged("YMin");
|
RaisePropertyChanged("YMin");
|
||||||
UpdateDisplayRange(false);
|
UpdateDisplayRange();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,7 +194,7 @@ namespace CalculatorApp::ViewModel
|
|||||||
}
|
}
|
||||||
RaisePropertyChanged("YError");
|
RaisePropertyChanged("YError");
|
||||||
RaisePropertyChanged("YMax");
|
RaisePropertyChanged("YMax");
|
||||||
UpdateDisplayRange(false);
|
UpdateDisplayRange();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,7 +270,7 @@ namespace CalculatorApp::ViewModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void UpdateDisplayRange(bool XValuesModified);
|
void UpdateDisplayRange();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void SetGrapher(GraphControl::Grapher ^ grapher);
|
void SetGrapher(GraphControl::Grapher ^ grapher);
|
||||||
|
@ -471,7 +471,7 @@
|
|||||||
</Grid.Resources>
|
</Grid.Resources>
|
||||||
<graphControl:Grapher Name="GraphingControl"
|
<graphControl:Grapher Name="GraphingControl"
|
||||||
Style="{ThemeResource ThemedGrapherStyle}"
|
Style="{ThemeResource ThemedGrapherStyle}"
|
||||||
ForceProportionalAxes="True"
|
ForceProportionalAxes="False"
|
||||||
LosingFocus="GraphingControl_LosingFocus"
|
LosingFocus="GraphingControl_LosingFocus"
|
||||||
LostFocus="GraphingControl_LostFocus"
|
LostFocus="GraphingControl_LostFocus"
|
||||||
RequestedTheme="Light"
|
RequestedTheme="Light"
|
||||||
|
@ -581,7 +581,6 @@ void GraphingCalculator::OnSettingsFlyout_Closing(FlyoutBase ^ sender, FlyoutBas
|
|||||||
{
|
{
|
||||||
auto flyout = static_cast<Flyout ^>(sender);
|
auto flyout = static_cast<Flyout ^>(sender);
|
||||||
auto graphingSetting = static_cast<GraphingSettings ^>(flyout->Content);
|
auto graphingSetting = static_cast<GraphingSettings ^>(flyout->Content);
|
||||||
args->Cancel = graphingSetting->CanBeClose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphingCalculator::Canvas_SizeChanged(Object ^ /*sender*/, SizeChangedEventArgs ^ e)
|
void GraphingCalculator::Canvas_SizeChanged(Object ^ /*sender*/, SizeChangedEventArgs ^ e)
|
||||||
|
@ -57,37 +57,6 @@ void GraphingSettings::GridSettingsTextBox_PreviewKeyDown(Platform::Object ^ sen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GraphingSettings::CanBeClose()
|
|
||||||
{
|
|
||||||
auto focusedElement = FocusManager::GetFocusedElement();
|
|
||||||
|
|
||||||
// Move focus so we are sure all values are in sync with the VM
|
|
||||||
if (focusedElement != nullptr)
|
|
||||||
{
|
|
||||||
if (focusedElement->Equals(SettingsXMin))
|
|
||||||
{
|
|
||||||
auto textbox = static_cast<TextBox ^>(focusedElement);
|
|
||||||
ViewModel->XMin = textbox->Text;
|
|
||||||
}
|
|
||||||
else if (focusedElement->Equals(SettingsXMax))
|
|
||||||
{
|
|
||||||
auto textbox = static_cast<TextBox ^>(focusedElement);
|
|
||||||
ViewModel->XMax = textbox->Text;
|
|
||||||
}
|
|
||||||
else if (focusedElement->Equals(SettingsYMin))
|
|
||||||
{
|
|
||||||
auto textbox = static_cast<TextBox ^>(focusedElement);
|
|
||||||
ViewModel->YMin = textbox->Text;
|
|
||||||
}
|
|
||||||
else if (focusedElement->Equals(SettingsYMax))
|
|
||||||
{
|
|
||||||
auto textbox = static_cast<TextBox ^>(focusedElement);
|
|
||||||
ViewModel->YMax = textbox->Text;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ViewModel != nullptr && ViewModel->HasError();
|
|
||||||
}
|
|
||||||
|
|
||||||
void GraphingSettings::RefreshRanges()
|
void GraphingSettings::RefreshRanges()
|
||||||
{
|
{
|
||||||
ViewModel->InitRanges();
|
ViewModel->InitRanges();
|
||||||
|
@ -20,7 +20,6 @@ namespace CalculatorApp
|
|||||||
PROPERTY_R(CalculatorApp::ViewModel::GraphingSettingsViewModel ^, ViewModel);
|
PROPERTY_R(CalculatorApp::ViewModel::GraphingSettingsViewModel ^, ViewModel);
|
||||||
Windows::UI::Xaml::Style ^ SelectTextBoxStyle(bool incorrectRange, bool error);
|
Windows::UI::Xaml::Style ^ SelectTextBoxStyle(bool incorrectRange, bool error);
|
||||||
void SetGrapher(GraphControl::Grapher ^ grapher);
|
void SetGrapher(GraphControl::Grapher ^ grapher);
|
||||||
bool CanBeClose();
|
|
||||||
void RefreshRanges();
|
void RefreshRanges();
|
||||||
private:
|
private:
|
||||||
void GridSettingsTextBox_PreviewKeyDown(Platform::Object ^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs ^ e);
|
void GridSettingsTextBox_PreviewKeyDown(Platform::Object ^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs ^ e);
|
||||||
|
Loading…
Reference in New Issue
Block a user