From aa16cd0c166c663173b830928d7a6ad3bf400fe5 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 19 Oct 2021 19:57:17 +0400 Subject: [PATCH] Allow custom rounded corners in boxes. --- ui/layers/box_content.cpp | 5 +++++ ui/layers/box_content.h | 4 ++++ ui/layers/box_layer_widget.cpp | 21 +++++++++++++-------- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/ui/layers/box_content.cpp b/ui/layers/box_content.cpp index fffe8b1..8e45c8e 100644 --- a/ui/layers/box_content.cpp +++ b/ui/layers/box_content.cpp @@ -12,6 +12,7 @@ #include "ui/widgets/shadow.h" #include "ui/wrap/fade_wrap.h" #include "ui/text/text_utilities.h" +#include "ui/rect_part.h" #include "ui/painter.h" #include "base/timer.h" #include "styles/style_layers.h" @@ -103,6 +104,10 @@ void BoxContent::scrollToWidget(not_null widget) { } } +RectParts BoxContent::customCornersFilling() { + return {}; +} + void BoxContent::onScrollToY(int top, int bottom) { if (_scroll) { _scroll->scrollToY(top, bottom); diff --git a/ui/layers/box_content.h b/ui/layers/box_content.h index d5eb32e..1870a99 100644 --- a/ui/layers/box_content.h +++ b/ui/layers/box_content.h @@ -15,6 +15,9 @@ #include "ui/text/text_entity.h" #include "ui/rp_widget.h" +enum class RectPart; +using RectParts = base::flags; + namespace style { struct RoundButton; struct IconButton; @@ -128,6 +131,7 @@ public: virtual void showFinished() { } + virtual RectParts customCornersFilling(); void clearButtons() { getDelegate()->clearButtons(); } diff --git a/ui/layers/box_layer_widget.cpp b/ui/layers/box_layer_widget.cpp index 02a7d75..cd2b494 100644 --- a/ui/layers/box_layer_widget.cpp +++ b/ui/layers/box_layer_widget.cpp @@ -115,16 +115,21 @@ QRect BoxLayerWidget::loadingRect() const { void BoxLayerWidget::paintEvent(QPaintEvent *e) { Painter p(this); - auto clip = e->rect(); - auto paintTopRounded = clip.intersects(QRect(0, 0, width(), st::boxRadius)); - auto paintBottomRounded = clip.intersects(QRect(0, height() - st::boxRadius, width(), st::boxRadius)); + + const auto custom = _content->customCornersFilling(); + const auto clip = e->rect(); + const auto paintTopRounded = !(custom & RectPart::FullTop) + && clip.intersects(QRect(0, 0, width(), st::boxRadius)); + const auto paintBottomRounded = !(custom & RectPart::FullBottom) + && clip.intersects( + QRect(0, height() - st::boxRadius, width(), st::boxRadius)); if (paintTopRounded || paintBottomRounded) { - auto parts = RectPart::None | 0; - if (paintTopRounded) parts |= RectPart::FullTop; - if (paintBottomRounded) parts |= RectPart::FullBottom; - _roundRect.paint(p, rect(), parts); + _roundRect.paint(p, rect(), RectPart::None + | (paintTopRounded ? RectPart::FullTop : RectPart::None) + | (paintBottomRounded ? RectPart::FullBottom : RectPart::None)); } - auto other = e->region().intersected(QRect(0, st::boxRadius, width(), height() - 2 * st::boxRadius)); + const auto other = e->region().intersected( + QRect(0, st::boxRadius, width(), height() - 2 * st::boxRadius)); if (!other.isEmpty()) { for (const auto &rect : other) { p.fillRect(rect, st().bg);