Allow custom click handlers in toasts.
This commit is contained in:
parent
2cb10e1d13
commit
6d26132685
3 changed files with 13 additions and 3 deletions
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include "ui/effects/animations.h"
|
||||
#include "ui/text/text_entity.h"
|
||||
#include "ui/click_handler.h"
|
||||
|
||||
namespace Ui {
|
||||
namespace Toast {
|
||||
|
|
@ -17,6 +18,8 @@ class Manager;
|
|||
class Widget;
|
||||
} // namespace internal
|
||||
|
||||
using ClickHandlerFilter = Fn<bool(const ClickHandlerPtr&, Qt::MouseButton)>;
|
||||
|
||||
inline constexpr auto kDefaultDuration = crl::time(1500);
|
||||
struct Config {
|
||||
TextWithEntities text;
|
||||
|
|
@ -26,6 +29,7 @@ struct Config {
|
|||
int maxWidth = 0;
|
||||
int maxLines = 16;
|
||||
bool multiline = false;
|
||||
ClickHandlerFilter filter;
|
||||
};
|
||||
void SetDefaultParent(not_null<QWidget*> parent);
|
||||
void Show(not_null<QWidget*> parent, const Config &config);
|
||||
|
|
|
|||
|
|
@ -24,7 +24,8 @@ Widget::Widget(QWidget *parent, const Config &config)
|
|||
, _maxTextWidth(widthWithoutPadding(_maxWidth))
|
||||
, _maxTextHeight(
|
||||
st::toastTextStyle.font->height * (_multiline ? config.maxLines : 1))
|
||||
, _text(_multiline ? widthWithoutPadding(config.minWidth) : QFIXED_MAX) {
|
||||
, _text(_multiline ? widthWithoutPadding(config.minWidth) : QFIXED_MAX)
|
||||
, _clickHandlerFilter(config.filter) {
|
||||
const auto toastOptions = TextParseOptions{
|
||||
TextParseMultiline,
|
||||
_maxTextWidth,
|
||||
|
|
@ -116,11 +117,14 @@ void Widget::mouseReleaseEvent(QMouseEvent *e) {
|
|||
return;
|
||||
}
|
||||
if (const auto handler = ClickHandler::unpressed()) {
|
||||
handler->onClick({ e->button() });
|
||||
const auto button = e->button();
|
||||
if (!_clickHandlerFilter
|
||||
|| _clickHandlerFilter(handler, button)) {
|
||||
ActivateClickHandler(this, handler, button);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace internal
|
||||
} // namespace Toast
|
||||
} // namespace Ui
|
||||
|
|
|
|||
|
|
@ -49,6 +49,8 @@ private:
|
|||
int _textWidth = 0;
|
||||
Text::String _text;
|
||||
|
||||
ClickHandlerFilter _clickHandlerFilter;
|
||||
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue