diff options
author | crupest <crupest@outlook.com> | 2020-10-28 00:10:49 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-10-28 00:10:49 +0800 |
commit | b61ab6a39ed1637c65e83b7ff7ff0d20908baafb (patch) | |
tree | 3dd74d844d173b39bc91e86405f702e745dd7d87 | |
parent | c7c9c62fd3813a6230a2af7fc8c9882baa426a7f (diff) | |
download | cru-b61ab6a39ed1637c65e83b7ff7ff0d20908baafb.tar.gz cru-b61ab6a39ed1637c65e83b7ff7ff0d20908baafb.tar.bz2 cru-b61ab6a39ed1637c65e83b7ff7ff0d20908baafb.zip |
...
-rw-r--r-- | src/ui/UiHost.cpp | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/src/ui/UiHost.cpp b/src/ui/UiHost.cpp index cd09907f..d3564619 100644 --- a/src/ui/UiHost.cpp +++ b/src/ui/UiHost.cpp @@ -45,10 +45,11 @@ bool IsAncestor(Control* control, Control* ancestor) { return false; } -std::list<Control*> GetAncestorList(Control* control) { - std::list<Control*> l; +// Ancestor at last. +std::vector<Control*> GetAncestorList(Control* control) { + std::vector<Control*> l; while (control != nullptr) { - l.push_front(control); + l.push_back(control); control = control->GetParent(); } return l; @@ -61,25 +62,25 @@ Control* FindLowestCommonAncestor(Control* left, Control* right) { auto&& right_list = GetAncestorList(right); // the root is different - if (left_list.front() != right_list.front()) return nullptr; + if (left_list.back() != right_list.back()) return nullptr; // find the last same control or the last control (one is ancestor of the // other) - auto left_i = left_list.cbegin(); - auto right_i = right_list.cbegin(); + auto left_iter = left_list.crbegin(); + auto right_iter = right_list.crbegin(); while (true) { - if (left_i == left_list.cend()) { - return *(--left_i); + if (left_iter == left_list.crend()) { + return left_list.front(); } - if (right_i == right_list.cend()) { - return *(--right_i); + if (right_iter == right_list.crend()) { + return right_list.front(); } - if (*left_i != *right_i) { - return *(--left_i); + if (*left_iter != *right_iter) { + return *(--left_iter); } - ++left_i; - ++right_i; + ++left_iter; + ++right_iter; } } } // namespace |