Extract controls side deduction code

This commit is contained in:
Ilya Fedin 2023-07-19 12:59:58 +04:00 committed by John Preston
parent b9aa8a17d4
commit 6419b54383
2 changed files with 15 additions and 8 deletions

View file

@ -56,6 +56,17 @@ void ShowWindowMenu(not_null<QWidget*> widget, const QPoint &point);
[[nodiscard]] TitleControls::Layout TitleControlsLayout();
[[nodiscard]] rpl::producer<TitleControls::Layout> TitleControlsLayoutValue();
[[nodiscard]] rpl::producer<TitleControls::Layout> TitleControlsLayoutChanged();
[[nodiscard]] bool TitleControlsOnLeft(
const TitleControls::Layout &layout = TitleControlsLayout()) {
if (ranges::contains(layout.left, TitleControl::Close)) {
return true;
} else if (ranges::contains(layout.right, TitleControl::Close)) {
return false;
} else if (layout.left.size() > layout.right.size()) {
return true;
}
return false;
}
void FixPopupMenuNativeEmojiPopup(not_null<PopupMenu*> menu);

View file

@ -340,9 +340,9 @@ AbstractButton *TitleControls::controlWidget(Control control) const {
}
void TitleControls::updateControlsPosition() {
const auto controlsLayout = TitleControlsLayout();
auto controlsLeft = controlsLayout.left;
auto controlsRight = controlsLayout.right;
auto controlsLayout = TitleControlsLayout();
auto &controlsLeft = controlsLayout.left;
auto &controlsRight = controlsLayout.right;
const auto moveFromTo = [&](auto &from, auto &to) {
for (const auto control : from) {
if (!ranges::contains(to, control)) {
@ -351,11 +351,7 @@ void TitleControls::updateControlsPosition() {
}
from.clear();
};
if (ranges::contains(controlsLeft, Control::Close)) {
moveFromTo(controlsRight, controlsLeft);
} else if (ranges::contains(controlsRight, Control::Close)) {
moveFromTo(controlsLeft, controlsRight);
} else if (controlsLeft.size() > controlsRight.size()) {
if (TitleControlsOnLeft(controlsLayout)) {
moveFromTo(controlsRight, controlsLeft);
} else {
moveFromTo(controlsLeft, controlsRight);