Support custom buttons padding in boxes.
This commit is contained in:
parent
37f777e230
commit
42209dc545
5 changed files with 50 additions and 29 deletions
|
|
@ -42,7 +42,7 @@ QPointer<RoundButton> BoxContent::addLeftButton(
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoxContent::setInner(object_ptr<TWidget> inner) {
|
void BoxContent::setInner(object_ptr<TWidget> inner) {
|
||||||
setInner(std::move(inner), st::boxLayerScroll);
|
setInner(std::move(inner), st::boxScroll);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoxContent::setInner(object_ptr<TWidget> inner, const style::ScrollArea &st) {
|
void BoxContent::setInner(object_ptr<TWidget> inner, const style::ScrollArea &st) {
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ namespace style {
|
||||||
struct RoundButton;
|
struct RoundButton;
|
||||||
struct IconButton;
|
struct IconButton;
|
||||||
struct ScrollArea;
|
struct ScrollArea;
|
||||||
|
struct Box;
|
||||||
} // namespace style
|
} // namespace style
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
|
|
@ -43,6 +44,7 @@ class BoxContent;
|
||||||
class BoxContentDelegate {
|
class BoxContentDelegate {
|
||||||
public:
|
public:
|
||||||
virtual void setLayerType(bool layerType) = 0;
|
virtual void setLayerType(bool layerType) = 0;
|
||||||
|
virtual void setStyle(const style::Box &st) = 0;
|
||||||
virtual void setTitle(rpl::producer<TextWithEntities> title) = 0;
|
virtual void setTitle(rpl::producer<TextWithEntities> title) = 0;
|
||||||
virtual void setAdditionalTitle(rpl::producer<QString> additional) = 0;
|
virtual void setAdditionalTitle(rpl::producer<QString> additional) = 0;
|
||||||
virtual void setCloseByOutsideClick(bool close) = 0;
|
virtual void setCloseByOutsideClick(bool close) = 0;
|
||||||
|
|
@ -157,6 +159,9 @@ public:
|
||||||
void updateButtonsGeometry() {
|
void updateButtonsGeometry() {
|
||||||
getDelegate()->updateButtonsPositions();
|
getDelegate()->updateButtonsPositions();
|
||||||
}
|
}
|
||||||
|
void setStyle(const style::Box &st) {
|
||||||
|
getDelegate()->setStyle(st);
|
||||||
|
}
|
||||||
|
|
||||||
virtual void setInnerFocus() {
|
virtual void setInnerFocus() {
|
||||||
setFocus();
|
setFocus();
|
||||||
|
|
|
||||||
|
|
@ -67,32 +67,36 @@ void BoxLayerWidget::setLayerType(bool layerType) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int BoxLayerWidget::titleHeight() const {
|
int BoxLayerWidget::titleHeight() const {
|
||||||
return _layerType ? st::boxLayerTitleHeight : st::boxTitleHeight;
|
return st::boxTitleHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
const style::Box &BoxLayerWidget::st() const {
|
||||||
|
return _st
|
||||||
|
? *_st
|
||||||
|
: _layerType
|
||||||
|
? st::layerBox
|
||||||
|
: st::defaultBox;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BoxLayerWidget::setStyle(const style::Box &st) {
|
||||||
|
_st = &st;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BoxLayerWidget::buttonsHeight() const {
|
int BoxLayerWidget::buttonsHeight() const {
|
||||||
const auto padding = _layerType
|
const auto padding = st().buttonPadding;
|
||||||
? st::boxLayerButtonPadding
|
return padding.top() + st().buttonHeight + padding.bottom();
|
||||||
: st::boxButtonPadding;
|
|
||||||
return padding.top() + st::defaultBoxButton.height + padding.bottom();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int BoxLayerWidget::buttonsTop() const {
|
int BoxLayerWidget::buttonsTop() const {
|
||||||
const auto padding = _layerType
|
const auto padding = st().buttonPadding;
|
||||||
? st::boxLayerButtonPadding
|
return height() - padding.bottom() - st().buttonHeight;
|
||||||
: st::boxButtonPadding;
|
|
||||||
return height() - padding.bottom() - st::defaultBoxButton.height;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QRect BoxLayerWidget::loadingRect() const {
|
QRect BoxLayerWidget::loadingRect() const {
|
||||||
const auto padding = _layerType
|
const auto padding = st().buttonPadding;
|
||||||
? st::boxLayerButtonPadding
|
|
||||||
: st::boxButtonPadding;
|
|
||||||
const auto size = st::boxLoadingSize;
|
const auto size = st::boxLoadingSize;
|
||||||
const auto skipx = _layerType
|
const auto skipx = st::boxTitlePosition.x();
|
||||||
? st::boxLayerTitlePosition.x()
|
const auto skipy = (st().buttonHeight - size) / 2;
|
||||||
: st::boxTitlePosition.x();
|
|
||||||
const auto skipy = (st::defaultBoxButton.height - size) / 2;
|
|
||||||
return QRect(
|
return QRect(
|
||||||
skipx,
|
skipx,
|
||||||
height() - padding.bottom() - skipy - size,
|
height() - padding.bottom() - skipy - size,
|
||||||
|
|
@ -132,9 +136,9 @@ void BoxLayerWidget::paintEvent(QPaintEvent *e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoxLayerWidget::paintAdditionalTitle(Painter &p) {
|
void BoxLayerWidget::paintAdditionalTitle(Painter &p) {
|
||||||
p.setFont(st::boxLayerTitleAdditionalFont);
|
p.setFont(st::boxTitleAdditionalFont);
|
||||||
p.setPen(st::boxTitleAdditionalFg);
|
p.setPen(st::boxTitleAdditionalFg);
|
||||||
p.drawTextLeft(_titleLeft + (_title ? _title->width() : 0) + st::boxLayerTitleAdditionalSkip, _titleTop + st::boxTitleFont->ascent - st::boxLayerTitleAdditionalFont->ascent, width(), _additionalTitle.current());
|
p.drawTextLeft(_titleLeft + (_title ? _title->width() : 0) + st::boxTitleAdditionalSkip, _titleTop + st::boxTitleFont->ascent - st::boxTitleAdditionalFont->ascent, width(), _additionalTitle.current());
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoxLayerWidget::parentResized() {
|
void BoxLayerWidget::parentResized() {
|
||||||
|
|
@ -193,7 +197,7 @@ void BoxLayerWidget::updateSize() {
|
||||||
|
|
||||||
void BoxLayerWidget::updateButtonsPositions() {
|
void BoxLayerWidget::updateButtonsPositions() {
|
||||||
if (!_buttons.empty() || _leftButton) {
|
if (!_buttons.empty() || _leftButton) {
|
||||||
auto padding = _layerType ? st::boxLayerButtonPadding : st::boxButtonPadding;
|
auto padding = st().buttonPadding;
|
||||||
auto right = padding.right();
|
auto right = padding.right();
|
||||||
auto top = buttonsTop();
|
auto top = buttonsTop();
|
||||||
if (_leftButton) {
|
if (_leftButton) {
|
||||||
|
|
@ -214,8 +218,8 @@ QPointer<QWidget> BoxLayerWidget::outerContainer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoxLayerWidget::updateTitlePosition() {
|
void BoxLayerWidget::updateTitlePosition() {
|
||||||
_titleLeft = _layerType ? st::boxLayerTitlePosition.x() : st::boxTitlePosition.x();
|
_titleLeft = st::boxTitlePosition.x();
|
||||||
_titleTop = _layerType ? st::boxLayerTitlePosition.y() : st::boxTitlePosition.y();
|
_titleTop = st::boxTitlePosition.y();
|
||||||
if (_title) {
|
if (_title) {
|
||||||
_title->resizeToWidth(qMin(_title->naturalWidth(), width() - _titleLeft * 2));
|
_title->resizeToWidth(qMin(_title->naturalWidth(), width() - _titleLeft * 2));
|
||||||
_title->moveToLeft(_titleLeft, _titleTop);
|
_title->moveToLeft(_titleLeft, _titleTop);
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ namespace style {
|
||||||
struct RoundButton;
|
struct RoundButton;
|
||||||
struct IconButton;
|
struct IconButton;
|
||||||
struct ScrollArea;
|
struct ScrollArea;
|
||||||
|
struct Box;
|
||||||
} // namespace style
|
} // namespace style
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
|
|
@ -43,6 +44,7 @@ public:
|
||||||
void parentResized() override;
|
void parentResized() override;
|
||||||
|
|
||||||
void setLayerType(bool layerType) override;
|
void setLayerType(bool layerType) override;
|
||||||
|
void setStyle(const style::Box &st) override;
|
||||||
void setTitle(rpl::producer<TextWithEntities> title) override;
|
void setTitle(rpl::producer<TextWithEntities> title) override;
|
||||||
void setAdditionalTitle(rpl::producer<QString> additional) override;
|
void setAdditionalTitle(rpl::producer<QString> additional) override;
|
||||||
void showBox(
|
void showBox(
|
||||||
|
|
@ -107,6 +109,7 @@ private:
|
||||||
void paintAdditionalTitle(Painter &p);
|
void paintAdditionalTitle(Painter &p);
|
||||||
void updateTitlePosition();
|
void updateTitlePosition();
|
||||||
|
|
||||||
|
[[nodiscard]] const style::Box &st() const;
|
||||||
[[nodiscard]] bool hasTitle() const;
|
[[nodiscard]] bool hasTitle() const;
|
||||||
[[nodiscard]] int titleHeight() const;
|
[[nodiscard]] int titleHeight() const;
|
||||||
[[nodiscard]] int buttonsHeight() const;
|
[[nodiscard]] int buttonsHeight() const;
|
||||||
|
|
@ -117,6 +120,7 @@ private:
|
||||||
[[nodiscard]] QRect loadingRect() const;
|
[[nodiscard]] QRect loadingRect() const;
|
||||||
void updateSize();
|
void updateSize();
|
||||||
|
|
||||||
|
const style::Box *_st = nullptr;
|
||||||
not_null<LayerStackWidget*> _layer;
|
not_null<LayerStackWidget*> _layer;
|
||||||
int _fullHeight = 0;
|
int _fullHeight = 0;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,11 @@ ServiceCheck {
|
||||||
duration: int;
|
duration: int;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Box {
|
||||||
|
buttonPadding: margins;
|
||||||
|
buttonHeight: pixels;
|
||||||
|
}
|
||||||
|
|
||||||
boxDuration: 200;
|
boxDuration: 200;
|
||||||
boxRadius: 3px;
|
boxRadius: 3px;
|
||||||
|
|
||||||
|
|
@ -82,11 +87,9 @@ boxTitle: FlatLabel(defaultFlatLabel) {
|
||||||
}
|
}
|
||||||
boxTitlePosition: point(23px, 16px);
|
boxTitlePosition: point(23px, 16px);
|
||||||
boxTitleHeight: 56px;
|
boxTitleHeight: 56px;
|
||||||
boxLayerTitlePosition: point(23px, 16px);
|
boxTitleAdditionalSkip: 9px;
|
||||||
boxLayerTitleHeight: 56px;
|
boxTitleAdditionalFont: normalFont;
|
||||||
boxLayerTitleAdditionalSkip: 9px;
|
boxScroll: defaultSolidScroll;
|
||||||
boxLayerTitleAdditionalFont: normalFont;
|
|
||||||
boxLayerScroll: defaultSolidScroll;
|
|
||||||
|
|
||||||
boxRowPadding: margins(23px, 0px, 23px, 0px);
|
boxRowPadding: margins(23px, 0px, 23px, 0px);
|
||||||
|
|
||||||
|
|
@ -123,8 +126,13 @@ boxMaxListHeight: 492px;
|
||||||
boxLittleSkip: 10px;
|
boxLittleSkip: 10px;
|
||||||
boxMediumSkip: 20px;
|
boxMediumSkip: 20px;
|
||||||
|
|
||||||
boxButtonPadding: margins(8px, 12px, 13px, 12px);
|
defaultBox: Box {
|
||||||
boxLayerButtonPadding: margins(8px, 8px, 8px, 8px);
|
buttonPadding: margins(8px, 12px, 13px, 12px);
|
||||||
|
buttonHeight: 36px;
|
||||||
|
}
|
||||||
|
layerBox: Box(defaultBox) {
|
||||||
|
buttonPadding: margins(8px, 8px, 8px, 8px);
|
||||||
|
}
|
||||||
boxLabel: FlatLabel(defaultFlatLabel) {
|
boxLabel: FlatLabel(defaultFlatLabel) {
|
||||||
minWidth: 274px;
|
minWidth: 274px;
|
||||||
align: align(topleft);
|
align: align(topleft);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue