diff --git a/Telegram/SourceFiles/historywidget.cpp b/Telegram/SourceFiles/historywidget.cpp index ca95bccdd..77a746f9e 100644 --- a/Telegram/SourceFiles/historywidget.cpp +++ b/Telegram/SourceFiles/historywidget.cpp @@ -3787,11 +3787,12 @@ void HistoryWidget::toggleTabbedSelectorMode() { updateTabbedSelectorSectionShown(); recountChatWidth(); updateControlsGeometry(); - } else if (_controller->provideChatWidth(minimalWidthForTabbedSelectorSection())) { + } else if (_controller->canProvideChatWidth(minimalWidthForTabbedSelectorSection())) { if (!AuthSession::Current().data().tabbedSelectorSectionEnabled()) { AuthSession::Current().data().setTabbedSelectorSectionEnabled(true); AuthSession::Current().saveDataDelayed(kSaveTabbedSelectorSectionTimeoutMs); } + _controller->provideChatWidth(minimalWidthForTabbedSelectorSection()); updateTabbedSelectorSectionShown(); recountChatWidth(); updateControlsGeometry(); diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 26e3194d8..10045eee2 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -3192,6 +3192,9 @@ void MainWidget::handleAdaptiveLayoutUpdate() { void MainWidget::updateWindowAdaptiveLayout() { auto layout = _controller->computeColumnLayout(); + + // Check if we are in a single-column layout in a wide enough window + // for the normal layout. If so, switch to the normal layout. if (layout.windowLayout == Adaptive::WindowLayout::OneColumn) { auto chatWidth = layout.dialogsWidth; if (AuthSession::Current().data().tabbedSelectorSectionEnabled() @@ -3205,6 +3208,7 @@ void MainWidget::updateWindowAdaptiveLayout() { _controller->dialogsWidthRatio().set(float64(layout.dialogsWidth) / layout.bodyWidth, true); } } + _dialogsWidth = layout.dialogsWidth; if (layout.windowLayout != Global::AdaptiveWindowLayout()) { Global::SetAdaptiveWindowLayout(layout.windowLayout); diff --git a/Telegram/SourceFiles/window/window_controller.cpp b/Telegram/SourceFiles/window/window_controller.cpp index 93016b021..2cfe90819 100644 --- a/Telegram/SourceFiles/window/window_controller.cpp +++ b/Telegram/SourceFiles/window/window_controller.cpp @@ -57,14 +57,14 @@ int Controller::dialogsSmallColumnWidth() const { return st::dialogsPadding.x() + st::dialogsPhotoSize + st::dialogsPadding.x(); } -Controller::ColumnLayout Controller::computeColumnLayout() { +Controller::ColumnLayout Controller::computeColumnLayout() const { auto layout = Adaptive::WindowLayout::OneColumn; auto bodyWidth = window()->bodyWidget()->width(); auto dialogsWidth = qRound(bodyWidth * dialogsWidthRatio().value()); - auto historyWidth = bodyWidth - dialogsWidth; - accumulate_max(historyWidth, st::windowMinWidth); - dialogsWidth = bodyWidth - historyWidth; + auto chatWidth = bodyWidth - dialogsWidth; + accumulate_max(chatWidth, st::windowMinWidth); + dialogsWidth = bodyWidth - chatWidth; auto useOneColumnLayout = [this, bodyWidth, dialogsWidth] { auto someSectionShown = !App::main()->selectingPeer() && App::main()->isSectionShown(); @@ -76,15 +76,17 @@ Controller::ColumnLayout Controller::computeColumnLayout() { } return false; }; + auto useSmallColumnLayout = [this, dialogsWidth] { - // used if useOneColumnLayout() == false. + // Used if useOneColumnLayout() == false. if (dialogsWidth < st::dialogsWidthMin / 2) { return true; } return false; }; + if (useOneColumnLayout()) { - dialogsWidth = bodyWidth; + dialogsWidth = chatWidth = bodyWidth; } else if (useSmallColumnLayout()) { layout = Adaptive::WindowLayout::SmallColumn; auto forceWideDialogs = [this] { @@ -100,31 +102,35 @@ Controller::ColumnLayout Controller::computeColumnLayout() { } else { dialogsWidth = dialogsSmallColumnWidth(); } + chatWidth = bodyWidth - dialogsWidth; } else { layout = Adaptive::WindowLayout::Normal; accumulate_max(dialogsWidth, st::dialogsWidthMin); + chatWidth = bodyWidth - dialogsWidth; } - return { bodyWidth, dialogsWidth, layout }; + return { bodyWidth, dialogsWidth, chatWidth, layout }; } -bool Controller::provideChatWidth(int requestedWidth) { +bool Controller::canProvideChatWidth(int requestedWidth) const { auto currentLayout = computeColumnLayout(); - auto chatWidth = currentLayout.bodyWidth - currentLayout.dialogsWidth; - if (currentLayout.windowLayout == Adaptive::WindowLayout::OneColumn) { - chatWidth = currentLayout.bodyWidth; - } - if (chatWidth >= requestedWidth) { + auto extendBy = requestedWidth - currentLayout.chatWidth; + if (extendBy <= 0) { return true; } - if (!window()->canExtendWidthBy(requestedWidth - chatWidth)) { - return false; + return window()->canExtendWidthBy(extendBy); +} + +void Controller::provideChatWidth(int requestedWidth) { + auto currentLayout = computeColumnLayout(); + auto extendBy = requestedWidth - currentLayout.chatWidth; + if (extendBy <= 0) { + return; } - window()->tryToExtendWidthBy(requestedWidth - chatWidth); + window()->tryToExtendWidthBy(extendBy); auto newLayout = computeColumnLayout(); if (newLayout.windowLayout != Adaptive::WindowLayout::OneColumn) { dialogsWidthRatio().set(float64(newLayout.bodyWidth - requestedWidth) / newLayout.bodyWidth, true); } - return true; } } // namespace Window diff --git a/Telegram/SourceFiles/window/window_controller.h b/Telegram/SourceFiles/window/window_controller.h index 112cf7029..69cbf78c8 100644 --- a/Telegram/SourceFiles/window/window_controller.h +++ b/Telegram/SourceFiles/window/window_controller.h @@ -69,21 +69,32 @@ public: struct ColumnLayout { int bodyWidth; int dialogsWidth; + int chatWidth; Adaptive::WindowLayout windowLayout; }; - ColumnLayout computeColumnLayout(); + ColumnLayout computeColumnLayout() const; int dialogsSmallColumnWidth() const; - bool provideChatWidth(int requestedWidth); + bool canProvideChatWidth(int requestedWidth) const; + void provideChatWidth(int requestedWidth); base::Variable &dialogsWidthRatio() { return _dialogsWidthRatio; } + const base::Variable &dialogsWidthRatio() const { + return _dialogsWidthRatio; + } base::Variable &dialogsListFocused() { return _dialogsListFocused; } + const base::Variable &dialogsListFocused() const { + return _dialogsListFocused; + } base::Variable &dialogsListDisplayForced() { return _dialogsListDisplayForced; } + const base::Variable &dialogsListDisplayForced() const { + return _dialogsListDisplayForced; + } private: gsl::not_null _window;