Ensure controls aren't duplicated

This commit is contained in:
Ilya Fedin 2021-02-07 17:39:10 +04:00 committed by John Preston
parent 3bc42db7bc
commit 34fc25a56c

View file

@ -21,6 +21,19 @@
namespace Ui {
namespace Platform {
namespace {
template <typename T>
void RemoveDuplicates(std::vector<T> &v) {
auto end = v.end();
for (auto it = v.begin(); it != end; ++it) {
end = std::remove(it + 1, end, *it);
}
v.erase(end, v.end());
}
} // namespace
TitleControls::TitleControls(
not_null<RpWidget*> parent,
@ -197,10 +210,12 @@ void TitleControls::updateControlsPosition() {
void TitleControls::updateControlsPositionBySide(
const std::vector<Control> &controls,
bool right) {
const auto preparedControls = right
auto preparedControls = right
? (ranges::view::reverse(controls) | ranges::to_vector)
: controls;
RemoveDuplicates(preparedControls);
auto position = 0;
for (const auto &control : preparedControls) {
const auto widget = controlWidget(control);