-
Notifications
You must be signed in to change notification settings - Fork 508
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
16 changed files
with
270 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#include "pch.h" | ||
#include "ControlSizeTrigger.h" | ||
#if __has_include("ControlSizeTrigger.g.cpp") | ||
#include "ControlSizeTrigger.g.cpp" | ||
#endif | ||
|
||
namespace winrt::Magpie::App::implementation { | ||
|
||
const DependencyProperty ControlSizeTrigger::_canTriggerProperty = DependencyProperty::Register( | ||
L"CanTrigger", | ||
xaml_typename<bool>(), | ||
xaml_typename<Magpie::App::ControlSizeTrigger>(), | ||
PropertyMetadata(box_value(true), &ControlSizeTrigger::_OnPropertyChanged) | ||
); | ||
|
||
const DependencyProperty ControlSizeTrigger::_maxWidthProperty = DependencyProperty::Register( | ||
L"MaxWidth", | ||
xaml_typename<double>(), | ||
xaml_typename<Magpie::App::ControlSizeTrigger>(), | ||
PropertyMetadata(box_value(std::numeric_limits<double>::infinity()), &ControlSizeTrigger::_OnPropertyChanged) | ||
); | ||
|
||
const DependencyProperty ControlSizeTrigger::_minWidthProperty = DependencyProperty::Register( | ||
L"MinWidth", | ||
xaml_typename<double>(), | ||
xaml_typename<Magpie::App::ControlSizeTrigger>(), | ||
PropertyMetadata(box_value(0.0), &ControlSizeTrigger::_OnPropertyChanged) | ||
); | ||
|
||
const DependencyProperty ControlSizeTrigger::_maxHeightProperty = DependencyProperty::Register( | ||
L"MaxHeight", | ||
xaml_typename<double>(), | ||
xaml_typename<Magpie::App::ControlSizeTrigger>(), | ||
PropertyMetadata(box_value(std::numeric_limits<double>::infinity()), &ControlSizeTrigger::_OnPropertyChanged) | ||
); | ||
|
||
const DependencyProperty ControlSizeTrigger::_minHeightProperty = DependencyProperty::Register( | ||
L"MinHeight", | ||
xaml_typename<double>(), | ||
xaml_typename<Magpie::App::ControlSizeTrigger>(), | ||
PropertyMetadata(box_value(0.0), &ControlSizeTrigger::_OnPropertyChanged) | ||
); | ||
|
||
const DependencyProperty ControlSizeTrigger::_targetElementProperty = DependencyProperty::Register( | ||
L"TargetElement", | ||
xaml_typename<FrameworkElement>(), | ||
xaml_typename<Magpie::App::ControlSizeTrigger>(), | ||
PropertyMetadata(nullptr, &ControlSizeTrigger::_OnTargetElementChanged) | ||
); | ||
|
||
void ControlSizeTrigger::_OnPropertyChanged(DependencyObject const& sender, DependencyPropertyChangedEventArgs const&) { | ||
get_self<ControlSizeTrigger>(sender.as<Magpie::App::ControlSizeTrigger>())->_UpdateTrigger(); | ||
} | ||
|
||
void ControlSizeTrigger::_OnTargetElementChanged(DependencyObject const& sender, DependencyPropertyChangedEventArgs const& e) { | ||
ControlSizeTrigger* that = get_self<ControlSizeTrigger>(sender.as<Magpie::App::ControlSizeTrigger>()); | ||
|
||
that->_targetElementSizeChangedRevoker.revoke(); | ||
|
||
if (IInspectable newValue = e.NewValue()) { | ||
that->_targetElementSizeChangedRevoker = newValue.as<FrameworkElement>().SizeChanged(auto_revoke, | ||
[that](IInspectable const&, SizeChangedEventArgs const&) { | ||
that->_UpdateTrigger(); | ||
} | ||
); | ||
} | ||
|
||
that->_UpdateTrigger(); | ||
} | ||
|
||
void ControlSizeTrigger::_UpdateTrigger() { | ||
const FrameworkElement targetElement = TargetElement(); | ||
|
||
if (!targetElement || !CanTrigger()) { | ||
SetActive(false); | ||
return; | ||
} | ||
|
||
const double actualWidth = targetElement.ActualWidth(); | ||
const double actualHeight = targetElement.ActualHeight(); | ||
SetActive( | ||
actualWidth >= MinWidth() && | ||
actualWidth < MaxWidth() && | ||
actualHeight >= MinHeight() && | ||
actualHeight < MaxHeight() | ||
); | ||
} | ||
|
||
} |
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,102 @@ | ||
#pragma once | ||
#include "ControlSizeTrigger.g.h" | ||
|
||
namespace winrt::Magpie::App::implementation { | ||
|
||
struct ControlSizeTrigger : ControlSizeTriggerT<ControlSizeTrigger> { | ||
bool CanTrigger() { | ||
return GetValue(_canTriggerProperty).as<bool>(); | ||
} | ||
|
||
void CanTrigger(bool value) { | ||
SetValue(_canTriggerProperty, box_value(value)); | ||
} | ||
|
||
double MaxWidth() { | ||
return GetValue(_maxWidthProperty).as<double>(); | ||
} | ||
|
||
void MaxWidth(double value) { | ||
SetValue(_maxWidthProperty, box_value(value)); | ||
} | ||
|
||
double MinWidth() { | ||
return GetValue(_minWidthProperty).as<double>(); | ||
} | ||
|
||
void MinWidth(double value) { | ||
SetValue(_minWidthProperty, box_value(value)); | ||
} | ||
|
||
double MaxHeight() { | ||
return GetValue(_maxHeightProperty).as<double>(); | ||
} | ||
|
||
void MaxHeight(double value) { | ||
SetValue(_maxHeightProperty, box_value(value)); | ||
} | ||
|
||
double MinHeight() { | ||
return GetValue(_minHeightProperty).as<double>(); | ||
} | ||
|
||
void MinHeight(double value) { | ||
SetValue(_minHeightProperty, box_value(value)); | ||
} | ||
|
||
FrameworkElement TargetElement() { | ||
return GetValue(_targetElementProperty).as<FrameworkElement>(); | ||
} | ||
|
||
void TargetElement(FrameworkElement const& value) { | ||
SetValue(_targetElementProperty, box_value(value)); | ||
} | ||
|
||
static DependencyProperty CanTriggerProperty() { | ||
return _canTriggerProperty; | ||
} | ||
|
||
static DependencyProperty MaxWidthProperty() { | ||
return _maxWidthProperty; | ||
} | ||
|
||
static DependencyProperty MinWidthProperty() { | ||
return _minWidthProperty; | ||
} | ||
|
||
static DependencyProperty MaxHeightProperty() { | ||
return _maxHeightProperty; | ||
} | ||
|
||
static DependencyProperty MinHeightProperty() { | ||
return _minHeightProperty; | ||
} | ||
|
||
static DependencyProperty TargetElementProperty() { | ||
return _targetElementProperty; | ||
} | ||
|
||
private: | ||
static const DependencyProperty _canTriggerProperty; | ||
static const DependencyProperty _maxWidthProperty; | ||
static const DependencyProperty _minWidthProperty; | ||
static const DependencyProperty _maxHeightProperty; | ||
static const DependencyProperty _minHeightProperty; | ||
static const DependencyProperty _targetElementProperty; | ||
|
||
static void _OnPropertyChanged(DependencyObject const& sender, DependencyPropertyChangedEventArgs const&); | ||
static void _OnTargetElementChanged(DependencyObject const& sender, DependencyPropertyChangedEventArgs const& ); | ||
|
||
void _UpdateTrigger(); | ||
|
||
FrameworkElement::SizeChanged_revoker _targetElementSizeChangedRevoker; | ||
}; | ||
|
||
} | ||
|
||
namespace winrt::Magpie::App::factory_implementation { | ||
|
||
struct ControlSizeTrigger : ControlSizeTriggerT<ControlSizeTrigger, implementation::ControlSizeTrigger> { | ||
}; | ||
|
||
} |
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,19 @@ | ||
namespace Magpie.App { | ||
runtimeclass ControlSizeTrigger : Windows.UI.Xaml.StateTriggerBase { | ||
ControlSizeTrigger(); | ||
|
||
Boolean CanTrigger; | ||
Double MaxWidth; | ||
Double MinWidth; | ||
Double MaxHeight; | ||
Double MinHeight; | ||
Windows.UI.Xaml.FrameworkElement TargetElement; | ||
|
||
static Windows.UI.Xaml.DependencyProperty CanTriggerProperty { get; }; | ||
static Windows.UI.Xaml.DependencyProperty MaxWidthProperty { get; }; | ||
static Windows.UI.Xaml.DependencyProperty MinWidthProperty { get; }; | ||
static Windows.UI.Xaml.DependencyProperty MaxHeightProperty { get; }; | ||
static Windows.UI.Xaml.DependencyProperty MinHeightProperty { get; }; | ||
static Windows.UI.Xaml.DependencyProperty TargetElementProperty{ get; }; | ||
} | ||
} |
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
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
Oops, something went wrong.