Ensure controls aren't duplictated

This commit is contained in:
Ilya Fedin 2021-02-07 17:32:35 +04:00 committed by John Preston
parent e109da037e
commit 3637fec397
1 changed files with 13 additions and 1 deletions

View File

@ -27,6 +27,16 @@ namespace {
return st::callShadow.extend;
}
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
TitleWidgetQt::TitleWidgetQt(QWidget *parent)
@ -181,10 +191,12 @@ void TitleWidgetQt::updateControlsPosition() {
void TitleWidgetQt::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);