mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-17 22:57:11 +02:00
Added fade effect to input message fields.
This commit is contained in:
parent
dcf4f45a36
commit
113c8a797f
5 changed files with 74 additions and 0 deletions
|
@ -968,6 +968,7 @@ historyComposeField: InputField(defaultInputField) {
|
|||
duration: 100;
|
||||
}
|
||||
historyComposeFieldMaxHeight: 224px;
|
||||
historyComposeFieldFadeHeight: 8px;
|
||||
// historyMinHeight: 56px;
|
||||
|
||||
historyAttach: IconButton(defaultIconButton) {
|
||||
|
|
|
@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "base/qthelp_url.h"
|
||||
#include "base/event_filter.h"
|
||||
#include "ui/layers/generic_box.h"
|
||||
#include "ui/rect.h"
|
||||
#include "core/shortcuts.h"
|
||||
#include "core/application.h"
|
||||
#include "core/core_settings.h"
|
||||
|
@ -442,6 +443,74 @@ bool HasSendText(not_null<const Ui::InputField*> field) {
|
|||
return false;
|
||||
}
|
||||
|
||||
void InitMessageFieldFade(not_null<Ui::InputField*> field) {
|
||||
class Fade final : public Ui::RpWidget {
|
||||
public:
|
||||
using Ui::RpWidget::RpWidget;
|
||||
|
||||
void setFade(QPixmap &&fade) {
|
||||
_fade = std::move(fade);
|
||||
}
|
||||
|
||||
int resizeGetHeight(int newWidth) override {
|
||||
return st::historyComposeFieldFadeHeight;
|
||||
}
|
||||
|
||||
private:
|
||||
void paintEvent(QPaintEvent *event) override {
|
||||
auto p = QPainter(this);
|
||||
p.drawTiledPixmap(rect(), _fade);
|
||||
}
|
||||
|
||||
QPixmap _fade;
|
||||
|
||||
};
|
||||
|
||||
const auto topFade = Ui::CreateChild<Fade>(field.get());
|
||||
const auto bottomFade = Ui::CreateChild<Fade>(field.get());
|
||||
|
||||
const auto generateFade = [=] {
|
||||
const auto size = QSize(1, st::historyComposeFieldFadeHeight);
|
||||
auto fade = QPixmap(size * style::DevicePixelRatio());
|
||||
fade.setDevicePixelRatio(style::DevicePixelRatio());
|
||||
fade.fill(Qt::transparent);
|
||||
{
|
||||
auto p = QPainter(&fade);
|
||||
|
||||
auto gradient = QLinearGradient(0, 1, 0, size.height());
|
||||
gradient.setStops({
|
||||
{ 0., st::historyComposeField.textBg->c },
|
||||
{ .9, Qt::transparent },
|
||||
});
|
||||
p.setPen(Qt::NoPen);
|
||||
p.setBrush(gradient);
|
||||
p.drawRect(Rect(size));
|
||||
}
|
||||
bottomFade->setFade(fade.transformed(QTransform().scale(1, -1)));
|
||||
topFade->setFade(std::move(fade));
|
||||
};
|
||||
generateFade();
|
||||
style::PaletteChanged(
|
||||
) | rpl::start_with_next([=] {
|
||||
generateFade();
|
||||
}, topFade->lifetime());
|
||||
|
||||
field->sizeValue(
|
||||
) | rpl::start_with_next_done([=](const QSize &size) {
|
||||
topFade->resizeToWidth(size.width());
|
||||
bottomFade->resizeToWidth(size.width());
|
||||
bottomFade->move(
|
||||
0,
|
||||
size.height() - st::historyComposeFieldFadeHeight);
|
||||
}, [t = Ui::MakeWeak(topFade), b = Ui::MakeWeak(bottomFade)] {
|
||||
Ui::DestroyChild(t.data());
|
||||
Ui::DestroyChild(b.data());
|
||||
}, topFade->lifetime());
|
||||
|
||||
topFade->show();
|
||||
bottomFade->show();
|
||||
}
|
||||
|
||||
InlineBotQuery ParseInlineBotQuery(
|
||||
not_null<Main::Session*> session,
|
||||
not_null<const Ui::InputField*> field) {
|
||||
|
|
|
@ -79,6 +79,8 @@ void InitSpellchecker(
|
|||
|
||||
bool HasSendText(not_null<const Ui::InputField*> field);
|
||||
|
||||
void InitMessageFieldFade(not_null<Ui::InputField*> field);
|
||||
|
||||
struct InlineBotQuery {
|
||||
QString query;
|
||||
QString username;
|
||||
|
|
|
@ -398,6 +398,7 @@ HistoryWidget::HistoryWidget(
|
|||
showPremiumToast(document);
|
||||
return false;
|
||||
});
|
||||
InitMessageFieldFade(_field);
|
||||
|
||||
_keyboard->sendCommandRequests(
|
||||
) | rpl::start_with_next([=](Bot::SendCommandRequest r) {
|
||||
|
|
|
@ -1575,6 +1575,7 @@ void ComposeControls::initField() {
|
|||
}
|
||||
return false;
|
||||
});
|
||||
InitMessageFieldFade(_field);
|
||||
_field->setEditLinkCallback(
|
||||
DefaultEditLinkCallback(_show, _field, &_st.boxField));
|
||||
initAutocomplete();
|
||||
|
|
Loading…
Add table
Reference in a new issue