From 2a110f0d3e5a8b6c41667bf231e5f14cbc8941b4 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 8 Jun 2018 22:26:08 +0300 Subject: [PATCH] Improve passport styles. --- .../view/history_view_top_bar_widget.cpp | 5 +- Telegram/SourceFiles/passport/passport.style | 6 +- .../passport/passport_panel_controller.cpp | 2 +- .../passport/passport_panel_details_row.cpp | 67 ++++++++++++++----- .../passport/passport_panel_details_row.h | 6 +- .../passport/passport_panel_edit_document.cpp | 36 +++++++--- .../passport/passport_panel_form.cpp | 2 +- Telegram/SourceFiles/ui/widgets/buttons.cpp | 4 +- 8 files changed, 96 insertions(+), 32 deletions(-) diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp index 013255c076..527ee50de3 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp @@ -494,8 +494,9 @@ void TopBarWidget::updateControlsGeometry() { buttonsWidth += buttonsLeft + st::topBarActionSkip * 3; auto widthLeft = qMin(width() - buttonsWidth, -2 * st::defaultActiveButton.width); - _forward->setFullWidth(-(widthLeft / 2)); - _delete->setFullWidth(-(widthLeft / 2)); + auto buttonFullWidth = qMin(-(widthLeft / 2), 0); + _forward->setFullWidth(buttonFullWidth); + _delete->setFullWidth(buttonFullWidth); selectedButtonsTop += (height() - _forward->height()) / 2; diff --git a/Telegram/SourceFiles/passport/passport.style b/Telegram/SourceFiles/passport/passport.style index f3a9b8fe99..3b92c6ed89 100644 --- a/Telegram/SourceFiles/passport/passport.style +++ b/Telegram/SourceFiles/passport/passport.style @@ -34,6 +34,7 @@ passportErrorLabel: FlatLabel(passportPasswordLabel) { textFg: boxTextFgError; } passportVerifyErrorLabel: FlatLabel(passportErrorLabel) { + minWidth: 128px; align: align(topleft); } @@ -169,10 +170,11 @@ passportDetailsField: InputField(defaultInputField) { font: normalFont; } passportDetailsDateField: InputField(passportDetailsField) { + textMargins: margins(2px, 8px, 2px, 0px); border: 0px; borderActive: 0px; heightMin: 30px; - placeholderFont: font(semibold 14px); + placeholderFont: semiboldFont; placeholderFgActive: placeholderFgActive; } passportDetailsSeparator: FlatLabel(passportPasswordLabelBold) { @@ -189,7 +191,7 @@ passportDetailsFieldLeft: 116px; passportDetailsFieldTop: 2px; passportDetailsFieldSkipMin: 12px; passportDetailsSkip: 30px; -passportDetailsGenderSkip: 30px; +passportDetailsGenderSkip: 20px; passportRequestTypeSkip: 16px; diff --git a/Telegram/SourceFiles/passport/passport_panel_controller.cpp b/Telegram/SourceFiles/passport/passport_panel_controller.cpp index a1c73a1367..32bac96aa0 100644 --- a/Telegram/SourceFiles/passport/passport_panel_controller.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_controller.cpp @@ -67,7 +67,7 @@ EditDocumentScheme GetDocumentScheme( if (value.isEmpty() || value.size() > kMaxNameSize) { return QString(); } else if (!QRegularExpression( - "^[a-zA-Z\\- ]+$" + "^[a-zA-Z0-9\\.,/&\\-' ]+$" ).match(value).hasMatch()) { return lang(lng_passport_bad_name); } diff --git a/Telegram/SourceFiles/passport/passport_panel_details_row.cpp b/Telegram/SourceFiles/passport/passport_panel_details_row.cpp index e5ec229f3c..01ffa009e2 100644 --- a/Telegram/SourceFiles/passport/passport_panel_details_row.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_details_row.cpp @@ -78,6 +78,7 @@ public: AbstractTextRow( QWidget *parent, const QString &label, + int maxLabelWidth, const QString &value, int limit); @@ -101,6 +102,7 @@ public: QWidget *parent, not_null controller, const QString &label, + int maxLabelWidth, const QString &value); rpl::producer value() const override; @@ -152,7 +154,11 @@ private: class DateRow : public PanelDetailsRow { public: - DateRow(QWidget *parent, const QString &label, const QString &value); + DateRow( + QWidget *parent, + const QString &label, + int maxLabelWidth, + const QString &value); bool setFocusFast() override; rpl::producer value() const override; @@ -206,6 +212,7 @@ public: GenderRow( QWidget *parent, const QString &label, + int maxLabelWidth, const QString &value); rpl::producer value() const override; @@ -247,9 +254,10 @@ template AbstractTextRow::AbstractTextRow( QWidget *parent, const QString &label, + int maxLabelWidth, const QString &value, int limit) -: PanelDetailsRow(parent, label) +: PanelDetailsRow(parent, label, maxLabelWidth) , _field(this, st::passportDetailsField, nullptr, value) , _value(value) { _field->setMaxLength(limit); @@ -299,8 +307,9 @@ CountryRow::CountryRow( QWidget *parent, not_null controller, const QString &label, + int maxLabelWidth, const QString &value) -: PanelDetailsRow(parent, label) +: PanelDetailsRow(parent, label, maxLabelWidth) , _controller(controller) , _link(this, CountryString(value), st::boxLinkButton) , _value(value) { @@ -505,8 +514,9 @@ void DateInput::correctValue( DateRow::DateRow( QWidget *parent, const QString &label, + int maxLabelWidth, const QString &value) -: PanelDetailsRow(parent, label) +: PanelDetailsRow(parent, label, maxLabelWidth) , _day( this, st::passportDetailsDateField, @@ -726,25 +736,26 @@ int DateRow::resizeInner(int left, int top, int width) { const auto right = left + width; const auto &_st = st::passportDetailsDateField; const auto &font = _st.placeholderFont; + const auto addToWidth = st::passportDetailsSeparatorPadding.left(); const auto dayWidth = _st.textMargins.left() + _st.placeholderMargins.left() + font->width(lang(lng_date_input_day)) + _st.placeholderMargins.right() + _st.textMargins.right() - + st::lineWidth; + + addToWidth; const auto monthWidth = _st.textMargins.left() + _st.placeholderMargins.left() + font->width(lang(lng_date_input_month)) + _st.placeholderMargins.right() + _st.textMargins.right() - + st::lineWidth; + + addToWidth; _day->setGeometry(left, top, dayWidth, _day->height()); - left += dayWidth - st::lineWidth; + left += dayWidth - addToWidth; _separator1->resizeToNaturalWidth(width); _separator1->move(left, top); left += _separator1->width(); _month->setGeometry(left, top, monthWidth, _month->height()); - left += monthWidth - st::lineWidth; + left += monthWidth - addToWidth; _separator2->resizeToNaturalWidth(width); _separator2->move(left, top); left += _separator2->width(); @@ -829,8 +840,9 @@ void DateRow::startBorderAnimation() { GenderRow::GenderRow( QWidget *parent, const QString &label, + int maxLabelWidth, const QString &value) -: PanelDetailsRow(parent, label) +: PanelDetailsRow(parent, label, maxLabelWidth) , _group(StringToGender(value).has_value() ? std::make_shared>(*StringToGender(value)) : std::make_shared>()) @@ -938,8 +950,10 @@ void GenderRow::errorAnimationCallback() { PanelDetailsRow::PanelDetailsRow( QWidget *parent, - const QString &label) -: _label(label) { + const QString &label, + int maxLabelWidth) +: _label(label) +, _maxLabelWidth(maxLabelWidth) { } object_ptr PanelDetailsRow::Create( @@ -947,6 +961,7 @@ object_ptr PanelDetailsRow::Create( Type type, not_null controller, const QString &label, + int maxLabelWidth, const QString &value, const QString &error, int limit) { @@ -956,20 +971,35 @@ object_ptr PanelDetailsRow::Create( return object_ptr>( parent, label, + maxLabelWidth, value, limit); case Type::Postcode: return object_ptr>( parent, label, + maxLabelWidth, value, limit); case Type::Country: - return object_ptr(parent, controller, label, value); + return object_ptr( + parent, + controller, + label, + maxLabelWidth, + value); case Type::Gender: - return object_ptr(parent, label, value); + return object_ptr( + parent, + label, + maxLabelWidth, + value); case Type::Date: - return object_ptr(parent, label, value); + return object_ptr( + parent, + label, + maxLabelWidth, + value); default: Unexpected("Type in PanelDetailsRow::Create."); } @@ -981,13 +1011,19 @@ object_ptr PanelDetailsRow::Create( return result; } +int PanelDetailsRow::LabelWidth(const QString &label) { + return st::semiboldFont->width(label); +} + bool PanelDetailsRow::setFocusFast() { return false; } int PanelDetailsRow::resizeGetHeight(int newWidth) { const auto padding = st::passportDetailsPadding; - const auto inputLeft = padding.left() + st::passportDetailsFieldLeft; + const auto inputLeft = padding.left() + std::max( + st::passportDetailsFieldLeft, + _maxLabelWidth + st::passportDetailsFieldSkipMin); const auto inputTop = st::passportDetailsFieldTop; const auto inputRight = padding.right(); const auto inputWidth = std::max(newWidth - inputLeft - inputRight, 0); @@ -997,6 +1033,7 @@ int PanelDetailsRow::resizeGetHeight(int newWidth) { + (_error ? _error->height() : 0) + padding.bottom(); if (_error) { + _error->resizeToWidth(inputWidth); _error->moveToLeft(inputLeft, result - _error->height()); } return result; diff --git a/Telegram/SourceFiles/passport/passport_panel_details_row.h b/Telegram/SourceFiles/passport/passport_panel_details_row.h index 29ee8f7ec9..d1ecd8bd22 100644 --- a/Telegram/SourceFiles/passport/passport_panel_details_row.h +++ b/Telegram/SourceFiles/passport/passport_panel_details_row.h @@ -37,16 +37,19 @@ public: PanelDetailsRow( QWidget *parent, - const QString &label); + const QString &label, + int maxLabelWidth); static object_ptr Create( QWidget *parent, Type type, not_null controller, const QString &label, + int maxLabelWidth, const QString &value, const QString &error, int limit = 0); + static int LabelWidth(const QString &label); virtual bool setFocusFast(); virtual rpl::producer value() const = 0; @@ -69,6 +72,7 @@ private: void startErrorAnimation(bool shown); QString _label; + int _maxLabelWidth = 0; object_ptr> _error = { nullptr }; bool _errorShown = false; bool _errorHideSubscription = false; diff --git a/Telegram/SourceFiles/passport/passport_panel_edit_document.cpp b/Telegram/SourceFiles/passport/passport_panel_edit_document.cpp index 785411756d..4446aed59f 100644 --- a/Telegram/SourceFiles/passport/passport_panel_edit_document.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_edit_document.cpp @@ -326,24 +326,42 @@ not_null PanelEditDocument::setupContent( return ValueField(); }; - for (auto i = 0, count = int(_scheme.rows.size()); i != count; ++i) { - const auto &row = _scheme.rows[i]; - auto fields = (row.valueClass == Scheme::ValueClass::Fields) - ? &data - : scanData; - if (!fields) { - continue; + const auto enumerateRows = [&](auto &&callback) { + for (auto i = 0, count = int(_scheme.rows.size()); i != count; ++i) { + const auto &row = _scheme.rows[i]; + auto fields = (row.valueClass == Scheme::ValueClass::Fields) + ? &data + : scanData; + if (!fields) { + continue; + } + callback(i, row, *fields); } - const auto current = valueOrEmpty(*fields, row.key); + }; + auto maxLabelWidth = 0; + enumerateRows([&]( + int i, + const EditDocumentScheme::Row &row, + const ValueMap &fields) { + accumulate_max( + maxLabelWidth, + PanelDetailsRow::LabelWidth(row.label)); + }); + enumerateRows([&]( + int i, + const EditDocumentScheme::Row &row, + const ValueMap &fields) { + const auto current = valueOrEmpty(fields, row.key); _details.emplace(i, inner->add(PanelDetailsRow::Create( inner, row.inputType, _controller, row.label, + maxLabelWidth, current.text, current.error, row.lengthLimit))); - } + }); inner->add( object_ptr(inner, st::passportDetailsSkip)); diff --git a/Telegram/SourceFiles/passport/passport_panel_form.cpp b/Telegram/SourceFiles/passport/passport_panel_form.cpp index 83f4d9f4ce..70b1bc95e5 100644 --- a/Telegram/SourceFiles/passport/passport_panel_form.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_form.cpp @@ -326,7 +326,7 @@ void PanelForm::updateControlsGeometry() { _topShadow->moveToLeft(0, 0); _bottomShadow->resizeToWidth(width()); _bottomShadow->moveToLeft(0, submitTop - st::lineWidth); - _submit->resizeToWidth(width()); + _submit->setFullWidth(width()); _submit->moveToLeft(0, submitTop); _scroll->updateBars(); diff --git a/Telegram/SourceFiles/ui/widgets/buttons.cpp b/Telegram/SourceFiles/ui/widgets/buttons.cpp index 358330c465..993692c47c 100644 --- a/Telegram/SourceFiles/ui/widgets/buttons.cpp +++ b/Telegram/SourceFiles/ui/widgets/buttons.cpp @@ -281,7 +281,9 @@ QString RoundButton::computeFullText() const { void RoundButton::resizeToText() { int innerWidth = contentWidth(); - if (_fullWidthOverride < 0) { + if (_fullWidthOverride > 0) { + resize(_fullWidthOverride, _st.height + _st.padding.top() + _st.padding.bottom()); + } else if (_fullWidthOverride < 0) { resize(innerWidth - _fullWidthOverride, _st.height + _st.padding.top() + _st.padding.bottom()); } else if (_st.width <= 0) { resize(innerWidth - _st.width + _st.padding.left() + _st.padding.right(), _st.height + _st.padding.top() + _st.padding.bottom());