Shrink dialogs column when enabling emoji sidebar.

Try to hold the ratio between the chat width and the dialogs list
width when the emoji sidebar is created by shrinking the left column.
This commit is contained in:
John Preston 2017-05-17 15:38:42 +03:00
parent 9f7c45e35c
commit 0339b1b54b
5 changed files with 46 additions and 4 deletions

View File

@ -167,7 +167,7 @@ void paintPreparedDate(Painter &p, const QString &dateText, int dateTextWidth, i
int left = st::msgServiceMargin.left();
int maxwidth = w;
if (Adaptive::ChatWide()) {
maxwidth = qMin(maxwidth, int32(st::msgMaxWidth + 2 * st::msgPhotoSkip + 2 * st::msgMargin.left()));
maxwidth = qMin(maxwidth, WideChatWidth());
}
w = maxwidth - st::msgServiceMargin.left() - st::msgServiceMargin.left();
@ -182,6 +182,10 @@ void paintPreparedDate(Painter &p, const QString &dateText, int dateTextWidth, i
} // namepsace
int WideChatWidth() {
return st::msgMaxWidth + 2 * st::msgPhotoSkip + 2 * st::msgMargin.left();
}
void ServiceMessagePainter::paint(Painter &p, const HistoryService *message, const PaintContext &context, int height) {
int left = 0, width = 0;
message->countPositionAndSize(left, width);

View File

@ -22,6 +22,8 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
namespace HistoryLayout {
int WideChatWidth();
struct PaintContext {
PaintContext(TimeMs ms, const QRect &clip, TextSelection selection)
: ms(ms)

View File

@ -3779,8 +3779,16 @@ int HistoryWidget::minimalWidthForTabbedSelectorSection() const {
return st::windowMinWidth + tabbedSelectorSectionWidth();
}
bool HistoryWidget::willSwitchToTabbedSelectorWithWidth(int newWidth) const {
if (!AuthSession::Current().data().tabbedSelectorSectionEnabled()) {
return false;
} else if (_tabbedSectionUsed) {
return false;
}
return (newWidth >= minimalWidthForTabbedSelectorSection());
}
void HistoryWidget::toggleTabbedSelectorMode() {
auto sectionEnabled = AuthSession::Current().data().tabbedSelectorSectionEnabled();
if (_tabbedSection) {
AuthSession::Current().data().setTabbedSelectorSectionEnabled(false);
AuthSession::Current().saveDataDelayed(kSaveTabbedSelectorSectionTimeoutMs);

View File

@ -202,6 +202,7 @@ public:
QRect historyRect() const;
int tabbedSelectorSectionWidth() const;
int minimalWidthForTabbedSelectorSection() const;
bool willSwitchToTabbedSelectorWithWidth(int newWidth) const;
void updateSendAction(History *history, SendAction::Type type, int32 progress = 0);
void cancelSendAction(History *history, SendAction::Type type);

View File

@ -35,6 +35,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "apiwrap.h"
#include "dialogswidget.h"
#include "historywidget.h"
#include "history/history_service_layout.h"
#include "overviewwidget.h"
#include "lang.h"
#include "boxes/add_contact_box.h"
@ -3192,11 +3193,12 @@ void MainWidget::handleAdaptiveLayoutUpdate() {
void MainWidget::updateWindowAdaptiveLayout() {
auto layout = _controller->computeColumnLayout();
auto dialogsWidthRatio = _controller->dialogsWidthRatio().value();
// 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;
auto chatWidth = layout.chatWidth;
if (AuthSession::Current().data().tabbedSelectorSectionEnabled()
&& chatWidth >= _history->minimalWidthForTabbedSelectorSection()) {
chatWidth -= _history->tabbedSelectorSectionWidth();
@ -3205,10 +3207,35 @@ void MainWidget::updateWindowAdaptiveLayout() {
// Switch layout back to normal in a wide enough window.
layout.windowLayout = Adaptive::WindowLayout::Normal;
layout.dialogsWidth = st::dialogsWidthMin;
_controller->dialogsWidthRatio().set(float64(layout.dialogsWidth) / layout.bodyWidth, true);
layout.chatWidth = layout.bodyWidth - layout.dialogsWidth;
dialogsWidthRatio = float64(layout.dialogsWidth) / layout.bodyWidth;
}
}
// Check if we are going to create the third column and shrink the
// dialogs widget to provide a wide enough chat history column.
// Don't shrink the column on the first call, when window is inited.
if (layout.windowLayout == Adaptive::WindowLayout::Normal
&& _controller->window()->positionInited()) {
auto chatWidth = layout.chatWidth;
if (_history->willSwitchToTabbedSelectorWithWidth(chatWidth)) {
auto thirdColumnWidth = _history->tabbedSelectorSectionWidth();
auto twoColumnsWidth = (layout.bodyWidth - thirdColumnWidth);
auto sameRatioChatWidth = twoColumnsWidth - qRound(dialogsWidthRatio * twoColumnsWidth);
auto desiredChatWidth = qMax(sameRatioChatWidth, HistoryLayout::WideChatWidth());
chatWidth -= thirdColumnWidth;
auto extendChatBy = desiredChatWidth - chatWidth;
accumulate_min(extendChatBy, layout.dialogsWidth - st::dialogsWidthMin);
if (extendChatBy > 0) {
layout.dialogsWidth -= extendChatBy;
layout.chatWidth += extendChatBy;
dialogsWidthRatio = float64(layout.dialogsWidth) / layout.bodyWidth;
}
}
}
_controller->dialogsWidthRatio().set(dialogsWidthRatio, true);
_dialogsWidth = layout.dialogsWidth;
if (layout.windowLayout != Global::AdaptiveWindowLayout()) {
Global::SetAdaptiveWindowLayout(layout.windowLayout);