Skip to content

Commit

Permalink
ui: 优化 SettingsExpander 箭头动画
Browse files Browse the repository at this point in the history
  • Loading branch information
Blinue committed Dec 25, 2024
1 parent 2d64597 commit a0e0a69
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Magpie/SettingsExpander.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,15 @@ void SettingsExpander::RegisterDependencyProperties() {

void SettingsExpander::OnApplyTemplate() {
base_type::OnApplyTemplate();

_OnItemsConnectedPropertyChanged();

auto expander = VisualTreeHelper::GetChild(*this, 0).as<MUXC::Expander>();
expander.ApplyTemplate();
auto header = expander.as<IControlProtected>().GetTemplateChild(L"ExpanderHeader").as<Control>();
header.ApplyTemplate();
_expandCollapseChevron = header.as<IControlProtected>().GetTemplateChild(L"ExpandCollapseChevron").as<MUXC::AnimatedIcon>();
MUXC::AnimatedIcon::SetState(_expandCollapseChevron, IsExpanded() ? L"PointerOverOn" : L"PointerOverOff");
}

void SettingsExpander::_OnIsExpandedChanged(DependencyObject const& sender, DependencyPropertyChangedEventArgs const& args) {
Expand All @@ -114,6 +122,11 @@ void SettingsExpander::_OnIsExpandedChanged(DependencyObject const& sender, Depe
} else {
that->Collapsed.Invoke();
}

if (that->_expandCollapseChevron) {
MUXC::AnimatedIcon::SetState(that->_expandCollapseChevron,
args.NewValue().as<bool>() ? L"PointerOverOn" : L"PointerOverOff");
}
}

void SettingsExpander::_OnItemsConnectedPropertyChanged(DependencyObject const& sender, DependencyPropertyChangedEventArgs const&) {
Expand Down
2 changes: 2 additions & 0 deletions src/Magpie/SettingsExpander.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ struct SettingsExpander : SettingsExpanderT<SettingsExpander> {
static void _OnItemsConnectedPropertyChanged(DependencyObject const& sender, DependencyPropertyChangedEventArgs const&);

void _OnItemsConnectedPropertyChanged();

MUXC::AnimatedIcon _expandCollapseChevron{ nullptr };
};

}
Expand Down

0 comments on commit a0e0a69

Please sign in to comment.