mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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;
|
duration: 100;
|
||||||
}
|
}
|
||||||
historyComposeFieldMaxHeight: 224px;
|
historyComposeFieldMaxHeight: 224px;
|
||||||
|
historyComposeFieldFadeHeight: 8px;
|
||||||
// historyMinHeight: 56px;
|
// historyMinHeight: 56px;
|
||||||
|
|
||||||
historyAttach: IconButton(defaultIconButton) {
|
historyAttach: IconButton(defaultIconButton) {
|
||||||
|
|
|
@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "base/qthelp_url.h"
|
#include "base/qthelp_url.h"
|
||||||
#include "base/event_filter.h"
|
#include "base/event_filter.h"
|
||||||
#include "ui/layers/generic_box.h"
|
#include "ui/layers/generic_box.h"
|
||||||
|
#include "ui/rect.h"
|
||||||
#include "core/shortcuts.h"
|
#include "core/shortcuts.h"
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
#include "core/core_settings.h"
|
#include "core/core_settings.h"
|
||||||
|
@ -442,6 +443,74 @@ bool HasSendText(not_null<const Ui::InputField*> field) {
|
||||||
return false;
|
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(
|
InlineBotQuery ParseInlineBotQuery(
|
||||||
not_null<Main::Session*> session,
|
not_null<Main::Session*> session,
|
||||||
not_null<const Ui::InputField*> field) {
|
not_null<const Ui::InputField*> field) {
|
||||||
|
|
|
@ -79,6 +79,8 @@ void InitSpellchecker(
|
||||||
|
|
||||||
bool HasSendText(not_null<const Ui::InputField*> field);
|
bool HasSendText(not_null<const Ui::InputField*> field);
|
||||||
|
|
||||||
|
void InitMessageFieldFade(not_null<Ui::InputField*> field);
|
||||||
|
|
||||||
struct InlineBotQuery {
|
struct InlineBotQuery {
|
||||||
QString query;
|
QString query;
|
||||||
QString username;
|
QString username;
|
||||||
|
|
|
@ -398,6 +398,7 @@ HistoryWidget::HistoryWidget(
|
||||||
showPremiumToast(document);
|
showPremiumToast(document);
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
InitMessageFieldFade(_field);
|
||||||
|
|
||||||
_keyboard->sendCommandRequests(
|
_keyboard->sendCommandRequests(
|
||||||
) | rpl::start_with_next([=](Bot::SendCommandRequest r) {
|
) | rpl::start_with_next([=](Bot::SendCommandRequest r) {
|
||||||
|
|
|
@ -1575,6 +1575,7 @@ void ComposeControls::initField() {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
InitMessageFieldFade(_field);
|
||||||
_field->setEditLinkCallback(
|
_field->setEditLinkCallback(
|
||||||
DefaultEditLinkCallback(_show, _field, &_st.boxField));
|
DefaultEditLinkCallback(_show, _field, &_st.boxField));
|
||||||
initAutocomplete();
|
initAutocomplete();
|
||||||
|
|
Loading…
Add table
Reference in a new issue