-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
232 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#include "pch.h" | ||
#include "ControlWidthTrigger.h" | ||
|
||
namespace winrt { | ||
using namespace ::winrt::Windows::Foundation; | ||
|
||
using namespace ::winrt::Microsoft::UI::Xaml; | ||
using namespace ::winrt::Microsoft::UI::Xaml::Controls; | ||
|
||
using namespace ::winrt::Mntone::AngelUmbrella::Triggers; | ||
} | ||
|
||
using namespace winrt::Mntone::AngelUmbrella::Triggers::implementation; | ||
|
||
ControlWidthTrigger::ControlWidthTrigger(): width_(0.f) { | ||
props_.DelayInitIfNeeded(); | ||
} | ||
|
||
void ControlWidthTrigger::UpdateTrigger(double minWidth) const { | ||
bool active { false }; | ||
if (TargetElement()) { | ||
if (minWidth >= 0.0) { | ||
active = width_ >= minWidth; | ||
} | ||
} | ||
SetActive(active); | ||
} | ||
|
||
void ControlWidthTrigger::OnTargetElementSizeChanged(IInspectable const& /*sender*/, SizeChangedEventArgs const& args) { | ||
Size newSize { args.NewSize() }; | ||
|
||
double minWidth { MinWidth() }; | ||
if (minWidth >= 0.0) { | ||
if (width_ != newSize.Width) { | ||
width_ = newSize.Width; | ||
UpdateTrigger(minWidth); | ||
} | ||
} | ||
} | ||
|
||
void ControlWidthTrigger::OnMinWidthChanged(double newValue) const { | ||
UpdateTrigger(newValue); | ||
} | ||
|
||
void ControlWidthTrigger::OnTargetElementChanged(Microsoft::UI::Xaml::FrameworkElement const& newValue) { | ||
revoker_.revoke(); | ||
|
||
UpdateTrigger(MinWidth()); | ||
|
||
if (newValue) { | ||
revoker_ = newValue.SizeChanged(auto_revoke, SizeChangedEventHandler(this, &ControlWidthTrigger::OnTargetElementSizeChanged)); | ||
} | ||
} | ||
|
||
void ControlWidthTrigger::OnMinWidthChangedStatic(DependencyObject const& sender, DependencyPropertyChangedEventArgs const& args) { | ||
double oldValue { args.OldValue().as<double>() }; | ||
double newValue { args.NewValue().as<double>() }; | ||
if (oldValue >= 0.0 || newValue >= 0.0) { | ||
get_self<ControlWidthTrigger>(sender.as<winrt::ControlWidthTrigger>())->OnMinWidthChanged(newValue); | ||
} | ||
} | ||
|
||
void ControlWidthTrigger::OnTargetElementChangedStatic(DependencyObject const& sender, DependencyPropertyChangedEventArgs const& args) { | ||
get_self<ControlWidthTrigger>(sender.as<winrt::ControlWidthTrigger>())->OnTargetElementChanged(args.NewValue().as<FrameworkElement>()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#pragma once | ||
#include "Triggers/ControlWidthTrigger.g.h" | ||
|
||
namespace winrt::Mntone::AngelUmbrella::Triggers::implementation { | ||
|
||
struct ControlWidthTrigger: ControlWidthTriggerT<ControlWidthTrigger> { | ||
ControlWidthTrigger(); | ||
|
||
private: | ||
inline void UpdateTrigger(double minWidth) const; | ||
|
||
private: | ||
void OnTargetElementSizeChanged(Windows::Foundation::IInspectable const& sender, Microsoft::UI::Xaml::SizeChangedEventArgs const& args); | ||
|
||
inline void OnMinWidthChanged(double newValue) const; | ||
inline void OnTargetElementChanged(Microsoft::UI::Xaml::FrameworkElement const& newValue); | ||
|
||
static void OnMinWidthChangedStatic(Microsoft::UI::Xaml::DependencyObject const& sender, Microsoft::UI::Xaml::DependencyPropertyChangedEventArgs const& args); | ||
static void OnTargetElementChangedStatic(Microsoft::UI::Xaml::DependencyObject const& sender, Microsoft::UI::Xaml::DependencyPropertyChangedEventArgs const& args); | ||
|
||
public: // - Properties | ||
inline double MinWidth() const { return GetValue(props_.MinWidth).as<double>(); } | ||
inline void MinWidth(double value) const { SetValue(props_.MinWidth, box_value(value)); } | ||
|
||
inline Microsoft::UI::Xaml::FrameworkElement TargetElement() const { return GetValue(props_.TargetElement).as<Microsoft::UI::Xaml::FrameworkElement>(); } | ||
inline void TargetElement(Microsoft::UI::Xaml::FrameworkElement const& value) const { SetValue(props_.TargetElement, value); } | ||
|
||
inline static Microsoft::UI::Xaml::DependencyProperty MinWidthProperty() noexcept { return props_.MinWidth; } | ||
inline static Microsoft::UI::Xaml::DependencyProperty TargetElementProperty() noexcept { return props_.TargetElement; } | ||
|
||
private: // - Variables | ||
float width_; | ||
Microsoft::UI::Xaml::FrameworkElement::SizeChanged_revoker revoker_; | ||
|
||
struct DependencyProperties final { | ||
void DelayInitIfNeeded(); | ||
|
||
bool initialized_ { false }; | ||
Microsoft::UI::Xaml::DependencyProperty MinWidth { nullptr }; | ||
Microsoft::UI::Xaml::DependencyProperty TargetElement { nullptr }; | ||
}; | ||
static DependencyProperties props_; | ||
}; | ||
|
||
} | ||
|
||
namespace winrt::Mntone::AngelUmbrella::Triggers::factory_implementation { | ||
|
||
struct ControlWidthTrigger: ControlWidthTriggerT<ControlWidthTrigger, implementation::ControlWidthTrigger> { | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include "pch.h" | ||
#include "ControlWidthTrigger.h" | ||
#if __has_include("Triggers/ControlWidthTrigger.g.cpp") | ||
#include "Triggers/ControlWidthTrigger.g.cpp" | ||
#endif | ||
|
||
#define DELAY_INIT_DP // Delay Init | ||
#include "Helpers/DependencyPropertyHelper.h" | ||
|
||
namespace projection { // Need to build | ||
using namespace ::winrt::Mntone::AngelUmbrella::Triggers; | ||
} | ||
|
||
using namespace ::winrt::Mntone::AngelUmbrella::Triggers::implementation; | ||
|
||
ControlWidthTrigger::DependencyProperties ControlWidthTrigger::props_; | ||
|
||
void ControlWidthTrigger::DependencyProperties::DelayInitIfNeeded() { | ||
if (initialized_) return; | ||
|
||
DEFINE_PARENT_TYPENAME(ControlWidthTrigger); | ||
|
||
DEFINE_DP_METADATA( | ||
MinWidth, | ||
double, | ||
ControlWidthTrigger, | ||
PropertyMetadata( | ||
box_value(-1.0), | ||
&ControlWidthTrigger::OnMinWidthChangedStatic)); | ||
|
||
DEFINE_DP_CALLBACK( | ||
TargetElement, | ||
Microsoft::UI::Xaml::FrameworkElement, | ||
ControlWidthTrigger, | ||
&ControlWidthTrigger::OnTargetElementChangedStatic); | ||
|
||
initialized_ = true; | ||
} |