Fix build with updated lib_ui.

This commit is contained in:
John Preston 2024-05-27 17:54:03 +04:00
parent ad6e34f3a4
commit 7357b40ba1
4 changed files with 3 additions and 42 deletions

View file

@ -1068,7 +1068,7 @@ void EditTagBox(
}
}, field->lifetime());
AddLengthLimitLabel(field, kTagNameLimit);
Ui::AddLengthLimitLabel(field, kTagNameLimit);
const auto save = [=] {
const auto text = field->getLastText();
@ -1828,40 +1828,4 @@ bool ItemHasTtl(HistoryItem *item) {
: false;
}
void AddLengthLimitLabel(not_null<Ui::InputField*> field, int limit) {
struct State {
rpl::variable<int> length;
};
const auto state = field->lifetime().make_state<State>();
state->length = rpl::single(
rpl::empty
) | rpl::then(field->changes()) | rpl::map([=] {
return int(field->getLastText().size());
});
auto warningText = state->length.value() | rpl::map([=](int count) {
const auto threshold = std::min(limit / 2, 9);
const auto left = limit - count;
return (left < threshold) ? QString::number(left) : QString();
});
const auto warning = Ui::CreateChild<Ui::FlatLabel>(
field.get(),
std::move(warningText),
st::editTagLimit);
state->length.value() | rpl::map(
rpl::mappers::_1 > limit
) | rpl::start_with_next([=](bool exceeded) {
warning->setTextColorOverride(exceeded
? st::attentionButtonFg->c
: std::optional<QColor>());
}, warning->lifetime());
rpl::combine(
field->sizeValue(),
warning->sizeValue()
) | rpl::start_with_next([=] {
warning->moveToRight(0, 0);
}, warning->lifetime());
warning->setAttribute(Qt::WA_TransparentForMouseEvents);
}
} // namespace HistoryView

View file

@ -123,6 +123,4 @@ void AddEmojiPacksAction(
[[nodiscard]] bool ItemHasTtl(HistoryItem *item);
void AddLengthLimitLabel(not_null<Ui::InputField*> field, int limit);
} // namespace HistoryView

View file

@ -164,7 +164,7 @@ private:
current),
st::settingsChatIntroFieldMargins);
field->setMaxLength(limit);
AddLengthLimitLabel(field, limit);
Ui::AddLengthLimitLabel(field, limit);
return field;
}

View file

@ -11,7 +11,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/application.h"
#include "data/business/data_shortcut_messages.h"
#include "data/data_session.h"
#include "history/view/history_view_context_menu.h" // AddLengthLimitLabel.
#include "lang/lang_keys.h"
#include "main/main_account.h"
#include "main/main_session.h"
@ -214,7 +213,7 @@ void EditShortcutNameBox(
field->selectAll();
field->setMaxLength(kShortcutLimit * 2);
HistoryView::AddLengthLimitLabel(field, kShortcutLimit);
Ui::AddLengthLimitLabel(field, kShortcutLimit);
const auto callback = [=] {
const auto name = field->getLastText().trimmed();