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