From db86e949f91bfc21d83a51216741c5e9828ed7ea Mon Sep 17 00:00:00 2001 From: Pepe Rivera Date: Fri, 24 Apr 2020 10:02:44 -0700 Subject: [PATCH] Don't create a new flyout every time the graph settings button is clicked (#1197) * attempt a fix * fix ranges --- .../GraphingCalculator.xaml | 5 ++- .../GraphingCalculator.xaml.cpp | 36 +++++++++---------- .../GraphingCalculator.xaml.h | 2 +- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml b/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml index a10fc8a..21b7cff 100644 --- a/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml +++ b/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml @@ -296,8 +296,7 @@ - - + @@ -699,8 +698,8 @@ Receivers->Append(GraphingControl); } - + m_accessibilitySettings->HighContrastChanged += ref new TypedEventHandler(this, &GraphingCalculator::OnHighContrastChanged); @@ -634,15 +634,18 @@ void GraphingCalculator::DisplayGraphSettings() m_graphSettings->GraphThemeSettingChanged += ref new EventHandler(this, &GraphingCalculator::OnGraphThemeSettingChanged); } - m_graphSettings->IsMatchAppTheme = IsMatchAppTheme; + if (m_graphFlyout == nullptr) + { + m_graphFlyout = ref new Flyout(); + m_graphFlyout->Content = m_graphSettings; + } + m_graphSettings->SetGrapher(this->GraphingControl); - auto flyoutGraphSettings = ref new Flyout(); - flyoutGraphSettings->Content = m_graphSettings; - flyoutGraphSettings->Closing += ref new TypedEventHandler(this, &GraphingCalculator::OnSettingsFlyout_Closing); + m_graphSettings->IsMatchAppTheme = IsMatchAppTheme; auto options = ref new FlyoutShowOptions(); options->Placement = FlyoutPlacementMode::BottomEdgeAlignedRight; - flyoutGraphSettings->ShowAt(GraphSettingsButton, options); + m_graphFlyout->ShowAt(GraphSettingsButton, options); } void CalculatorApp::GraphingCalculator::AddTracePointerShadow() @@ -660,12 +663,6 @@ void CalculatorApp::GraphingCalculator::AddTracePointerShadow() ::Hosting::ElementCompositionPreview::SetElementChildVisual(CursorShadow, shadowSpriteVisual); } -void GraphingCalculator::OnSettingsFlyout_Closing(FlyoutBase ^ sender, FlyoutBaseClosingEventArgs ^ args) -{ - auto flyout = static_cast(sender); - auto graphingSetting = static_cast(flyout->Content); -} - void GraphingCalculator::Canvas_SizeChanged(Object ^ /*sender*/, SizeChangedEventArgs ^ e) { // Initialize the pointer to the correct location to match initial value in GraphControl\DirectX\RenderMain.cpp @@ -812,12 +809,12 @@ void GraphingCalculator::OnGraphThemeSettingChanged(Object ^ sender, bool isMatc IsMatchAppTheme = isMatchAppTheme; WeakReference weakThis(this); this->Dispatcher->RunAsync(CoreDispatcherPriority::Normal, ref new DispatchedHandler([weakThis]() { - auto refThis = weakThis.Resolve(); - if (refThis != nullptr) - { - refThis->UpdateGraphTheme(); - } - })); + auto refThis = weakThis.Resolve(); + if (refThis != nullptr) + { + refThis->UpdateGraphTheme(); + } + })); } void GraphingCalculator::GraphViewButton_Click(Object ^ sender, RoutedEventArgs ^ e) @@ -837,5 +834,6 @@ void GraphingCalculator::GraphViewButton_Click(Object ^ sender, RoutedEventArgs auto announcement = CalculatorAnnouncement::GetGraphViewBestFitChangedAnnouncement(announcementText); narratorNotifier->Announce(announcement); - TraceLogger::GetInstance()->LogGraphButtonClicked(GraphButton::GraphView, IsManualAdjustment ? GraphButtonValue::ManualAdjustment : GraphButtonValue::AutomaticBestFit); + TraceLogger::GetInstance()->LogGraphButtonClicked( + GraphButton::GraphView, IsManualAdjustment ? GraphButtonValue::ManualAdjustment : GraphButtonValue::AutomaticBestFit); } diff --git a/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.h b/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.h index 4380a7b..bff615c 100644 --- a/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.h +++ b/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.h @@ -97,8 +97,8 @@ public ref class GraphingCalculator sealed : public Windows::UI::Xaml::Data::INo Windows::UI::ViewManagement::AccessibilitySettings ^ m_accessibilitySettings; bool m_cursorShadowInitialized; Windows::UI::ViewManagement::UISettings ^ m_uiSettings; + Windows::UI::Xaml::Controls::Flyout ^ m_graphFlyout; CalculatorApp::GraphingSettings ^ m_graphSettings; - void OnSettingsFlyout_Closing(Windows::UI::Xaml::Controls::Primitives::FlyoutBase ^ sender, Windows::UI::Xaml::Controls::Primitives::FlyoutBaseClosingEventArgs ^ args); void Canvas_SizeChanged(Platform::Object ^ sender, Windows::UI::Xaml::SizeChangedEventArgs ^ e); void OnHighContrastChanged(Windows::UI::ViewManagement::AccessibilitySettings ^ sender, Platform::Object ^ args); void OnEquationFormatRequested(Platform::Object ^ sender, CalculatorApp::Controls::MathRichEditBoxFormatRequest ^ e);