mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-19 07:37:11 +02:00
Added special field for time input with placeholder.
This commit is contained in:
parent
7bebe699f6
commit
73b4a8b75a
4 changed files with 105 additions and 1 deletions
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "ui/widgets/fields/time_part_input_with_placeholder.h"
|
||||
|
||||
#include "lang/lang_numbers_animation.h"
|
||||
|
||||
namespace Ui {
|
||||
|
||||
void TimePartWithPlaceholder::setPhrase(
|
||||
const tr::phrase<lngtag_count> &phrase) {
|
||||
_phrase = phrase;
|
||||
}
|
||||
|
||||
void TimePartWithPlaceholder::paintAdditionalPlaceholder(Painter &p) {
|
||||
maybeUpdatePlaceholder();
|
||||
|
||||
p.setClipRect(rect());
|
||||
const auto phRect = placeholderRect();
|
||||
|
||||
if (_lastPlaceholder.width < phRect.width()) {
|
||||
placeholderAdditionalPrepare(p);
|
||||
p.drawText(
|
||||
phRect.translated(-_lastPlaceholder.leftOffset, 0),
|
||||
_lastPlaceholder.text,
|
||||
style::al_left);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void TimePartWithPlaceholder::maybeUpdatePlaceholder() {
|
||||
const auto displayedText = getDisplayedText();
|
||||
if (displayedText == _lastPlaceholder.displayedText) {
|
||||
return;
|
||||
}
|
||||
const auto count = displayedText.toUInt();
|
||||
const auto textWithOffset = _phrase(
|
||||
tr::now,
|
||||
lt_count,
|
||||
count,
|
||||
Ui::StringWithNumbers::FromString);
|
||||
_lastPlaceholder = {
|
||||
.width = phFont()->width(textWithOffset.text),
|
||||
.text = textWithOffset.text,
|
||||
.leftOffset = phFont()->width(
|
||||
textWithOffset.text.mid(0, textWithOffset.offset)),
|
||||
.displayedText = displayedText,
|
||||
};
|
||||
if (displayedText.size() > 1 && displayedText.startsWith(_zero)) {
|
||||
_lastPlaceholder.text.insert(textWithOffset.offset, _zero);
|
||||
}
|
||||
|
||||
const auto leftMargins = (width() - _lastPlaceholder.width) / 2
|
||||
+ _lastPlaceholder.leftOffset;
|
||||
setTextMargins({ leftMargins, 0, 0, 0 });
|
||||
}
|
||||
|
||||
} // namespace Ui
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "ui/widgets/fields/time_part_input.h"
|
||||
|
||||
#include "lang_auto.h"
|
||||
|
||||
namespace Ui {
|
||||
|
||||
class TimePartWithPlaceholder final : public TimePart {
|
||||
public:
|
||||
using Ui::TimePart::TimePart;
|
||||
|
||||
void setPhrase(const tr::phrase<lngtag_count> &phrase);
|
||||
|
||||
protected:
|
||||
void paintAdditionalPlaceholder(Painter &p) override;
|
||||
|
||||
private:
|
||||
void maybeUpdatePlaceholder();
|
||||
|
||||
const QChar _zero = QChar('0');
|
||||
tr::phrase<lngtag_count> _phrase;
|
||||
|
||||
struct {
|
||||
int width = 0;
|
||||
QString text;
|
||||
int leftOffset = 0;
|
||||
QString displayedText;
|
||||
} _lastPlaceholder;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Ui
|
|
@ -239,6 +239,8 @@ PRIVATE
|
|||
ui/grouped_layout.h
|
||||
ui/widgets/fields/special_fields.cpp
|
||||
ui/widgets/fields/special_fields.h
|
||||
ui/widgets/fields/time_part_input_with_placeholder.cpp
|
||||
ui/widgets/fields/time_part_input_with_placeholder.h
|
||||
|
||||
ui/ui_pch.h
|
||||
)
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 62002f034bbfd3e5f78a71317f37c685a8846b1f
|
||||
Subproject commit 9f28a0b106311566d2adab8a7b82973accfdd944
|
Loading…
Add table
Reference in a new issue