Allow custom rounded corners in boxes.

This commit is contained in:
John Preston 2021-10-19 19:57:17 +04:00
parent 674391524b
commit aa16cd0c16
3 changed files with 22 additions and 8 deletions

View file

@ -12,6 +12,7 @@
#include "ui/widgets/shadow.h" #include "ui/widgets/shadow.h"
#include "ui/wrap/fade_wrap.h" #include "ui/wrap/fade_wrap.h"
#include "ui/text/text_utilities.h" #include "ui/text/text_utilities.h"
#include "ui/rect_part.h"
#include "ui/painter.h" #include "ui/painter.h"
#include "base/timer.h" #include "base/timer.h"
#include "styles/style_layers.h" #include "styles/style_layers.h"
@ -103,6 +104,10 @@ void BoxContent::scrollToWidget(not_null<QWidget*> widget) {
} }
} }
RectParts BoxContent::customCornersFilling() {
return {};
}
void BoxContent::onScrollToY(int top, int bottom) { void BoxContent::onScrollToY(int top, int bottom) {
if (_scroll) { if (_scroll) {
_scroll->scrollToY(top, bottom); _scroll->scrollToY(top, bottom);

View file

@ -15,6 +15,9 @@
#include "ui/text/text_entity.h" #include "ui/text/text_entity.h"
#include "ui/rp_widget.h" #include "ui/rp_widget.h"
enum class RectPart;
using RectParts = base::flags<RectPart>;
namespace style { namespace style {
struct RoundButton; struct RoundButton;
struct IconButton; struct IconButton;
@ -128,6 +131,7 @@ public:
virtual void showFinished() { virtual void showFinished() {
} }
virtual RectParts customCornersFilling();
void clearButtons() { void clearButtons() {
getDelegate()->clearButtons(); getDelegate()->clearButtons();
} }

View file

@ -115,16 +115,21 @@ QRect BoxLayerWidget::loadingRect() const {
void BoxLayerWidget::paintEvent(QPaintEvent *e) { void BoxLayerWidget::paintEvent(QPaintEvent *e) {
Painter p(this); Painter p(this);
auto clip = e->rect();
auto paintTopRounded = clip.intersects(QRect(0, 0, width(), st::boxRadius)); const auto custom = _content->customCornersFilling();
auto paintBottomRounded = clip.intersects(QRect(0, height() - st::boxRadius, width(), st::boxRadius)); 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) { if (paintTopRounded || paintBottomRounded) {
auto parts = RectPart::None | 0; _roundRect.paint(p, rect(), RectPart::None
if (paintTopRounded) parts |= RectPart::FullTop; | (paintTopRounded ? RectPart::FullTop : RectPart::None)
if (paintBottomRounded) parts |= RectPart::FullBottom; | (paintBottomRounded ? RectPart::FullBottom : RectPart::None));
_roundRect.paint(p, rect(), parts);
} }
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()) { if (!other.isEmpty()) {
for (const auto &rect : other) { for (const auto &rect : other) {
p.fillRect(rect, st().bg); p.fillRect(rect, st().bg);