Allow adding any buttons to BoxContent.
This commit is contained in:
parent
96279cc04d
commit
c468f8b3c6
4 changed files with 111 additions and 88 deletions
|
|
@ -24,6 +24,13 @@ void BoxContent::setTitle(rpl::producer<QString> title) {
|
|||
getDelegate()->setTitle(std::move(title) | Text::ToWithEntities());
|
||||
}
|
||||
|
||||
QPointer<AbstractButton> BoxContent::addButton(
|
||||
object_ptr<AbstractButton> button) {
|
||||
auto result = QPointer<AbstractButton>(button.data());
|
||||
getDelegate()->addButton(std::move(button));
|
||||
return result;
|
||||
}
|
||||
|
||||
QPointer<RoundButton> BoxContent::addButton(
|
||||
rpl::producer<QString> text,
|
||||
Fn<void()> clickCallback) {
|
||||
|
|
@ -33,15 +40,69 @@ QPointer<RoundButton> BoxContent::addButton(
|
|||
getDelegate()->style().button);
|
||||
}
|
||||
|
||||
QPointer<RoundButton> BoxContent::addButton(
|
||||
rpl::producer<QString> text,
|
||||
const style::RoundButton &st) {
|
||||
return addButton(std::move(text), nullptr, st);
|
||||
}
|
||||
|
||||
QPointer<RoundButton> BoxContent::addButton(
|
||||
rpl::producer<QString> text,
|
||||
Fn<void()> clickCallback,
|
||||
const style::RoundButton &st) {
|
||||
auto button = object_ptr<RoundButton>(this, std::move(text), st);
|
||||
auto result = QPointer<RoundButton>(button.data());
|
||||
result->setTextTransform(RoundButton::TextTransform::NoTransform);
|
||||
result->setClickedCallback(std::move(clickCallback));
|
||||
getDelegate()->addButton(std::move(button));
|
||||
return result;
|
||||
}
|
||||
|
||||
QPointer<AbstractButton> BoxContent::addLeftButton(
|
||||
object_ptr<AbstractButton> button) {
|
||||
auto result = QPointer<AbstractButton>(button.data());
|
||||
getDelegate()->addLeftButton(std::move(button));
|
||||
return result;
|
||||
}
|
||||
|
||||
QPointer<RoundButton> BoxContent::addLeftButton(
|
||||
rpl::producer<QString> text,
|
||||
Fn<void()> clickCallback) {
|
||||
return getDelegate()->addLeftButton(
|
||||
return addLeftButton(
|
||||
std::move(text),
|
||||
std::move(clickCallback),
|
||||
getDelegate()->style().button);
|
||||
}
|
||||
|
||||
QPointer<RoundButton> BoxContent::addLeftButton(
|
||||
rpl::producer<QString> text,
|
||||
Fn<void()> clickCallback,
|
||||
const style::RoundButton &st) {
|
||||
auto button = object_ptr<RoundButton>(this, std::move(text), st);
|
||||
const auto result = QPointer<RoundButton>(button.data());
|
||||
result->setTextTransform(RoundButton::TextTransform::NoTransform);
|
||||
result->setClickedCallback(std::move(clickCallback));
|
||||
getDelegate()->addLeftButton(std::move(button));
|
||||
return result;
|
||||
}
|
||||
|
||||
QPointer<AbstractButton> BoxContent::addTopButton(
|
||||
object_ptr<AbstractButton> button) {
|
||||
auto result = QPointer<AbstractButton>(button.data());
|
||||
getDelegate()->addTopButton(std::move(button));
|
||||
return result;
|
||||
}
|
||||
|
||||
QPointer<IconButton> BoxContent::addTopButton(
|
||||
const style::IconButton &st,
|
||||
Fn<void()> clickCallback) {
|
||||
auto button = object_ptr<IconButton>(this, st);
|
||||
const auto result = QPointer<IconButton>(button.data());
|
||||
result->setClickedCallback(std::move(clickCallback));
|
||||
getDelegate()->addTopButton(std::move(button));
|
||||
return result;
|
||||
}
|
||||
|
||||
void BoxContent::setInner(object_ptr<TWidget> inner) {
|
||||
setInner(std::move(inner), st::boxScroll);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ inline object_ptr<BoxType> Box(Args &&...args) {
|
|||
|
||||
namespace Ui {
|
||||
|
||||
class AbstractButton;
|
||||
class RoundButton;
|
||||
class IconButton;
|
||||
class ScrollArea;
|
||||
|
|
@ -60,17 +61,9 @@ public:
|
|||
virtual void setCloseByOutsideClick(bool close) = 0;
|
||||
|
||||
virtual void clearButtons() = 0;
|
||||
virtual QPointer<RoundButton> addButton(
|
||||
rpl::producer<QString> text,
|
||||
Fn<void()> clickCallback,
|
||||
const style::RoundButton &st) = 0;
|
||||
virtual QPointer<RoundButton> addLeftButton(
|
||||
rpl::producer<QString> text,
|
||||
Fn<void()> clickCallback,
|
||||
const style::RoundButton &st) = 0;
|
||||
virtual QPointer<IconButton> addTopButton(
|
||||
const style::IconButton &st,
|
||||
Fn<void()> clickCallback) = 0;
|
||||
virtual void addButton(object_ptr<AbstractButton> button) = 0;
|
||||
virtual void addLeftButton(object_ptr<AbstractButton> button) = 0;
|
||||
virtual void addTopButton(object_ptr<AbstractButton> button) = 0;
|
||||
virtual void showLoading(bool show) = 0;
|
||||
virtual void updateButtonsPositions() = 0;
|
||||
|
||||
|
|
@ -141,40 +134,31 @@ public:
|
|||
void clearButtons() {
|
||||
getDelegate()->clearButtons();
|
||||
}
|
||||
QPointer<AbstractButton> addButton(object_ptr<AbstractButton> button);
|
||||
QPointer<RoundButton> addButton(
|
||||
rpl::producer<QString> text,
|
||||
Fn<void()> clickCallback = nullptr);
|
||||
QPointer<RoundButton> addButton(
|
||||
rpl::producer<QString> text,
|
||||
const style::RoundButton &st);
|
||||
QPointer<RoundButton> addButton(
|
||||
rpl::producer<QString> text,
|
||||
Fn<void()> clickCallback,
|
||||
const style::RoundButton &st);
|
||||
QPointer<AbstractButton> addLeftButton(
|
||||
object_ptr<AbstractButton> button);
|
||||
QPointer<RoundButton> addLeftButton(
|
||||
rpl::producer<QString> text,
|
||||
Fn<void()> clickCallback = nullptr);
|
||||
QPointer<RoundButton> addLeftButton(
|
||||
rpl::producer<QString> text,
|
||||
Fn<void()> clickCallback = nullptr);
|
||||
Fn<void()> clickCallback,
|
||||
const style::RoundButton& st);
|
||||
QPointer<AbstractButton> addTopButton(
|
||||
object_ptr<AbstractButton> button);
|
||||
QPointer<IconButton> addTopButton(
|
||||
const style::IconButton &st,
|
||||
Fn<void()> clickCallback = nullptr) {
|
||||
return getDelegate()->addTopButton(st, std::move(clickCallback));
|
||||
}
|
||||
QPointer<RoundButton> addButton(
|
||||
rpl::producer<QString> text,
|
||||
const style::RoundButton &st) {
|
||||
return getDelegate()->addButton(std::move(text), nullptr, st);
|
||||
}
|
||||
QPointer<RoundButton> addButton(
|
||||
rpl::producer<QString> text,
|
||||
Fn<void()> clickCallback,
|
||||
const style::RoundButton &st) {
|
||||
return getDelegate()->addButton(
|
||||
std::move(text),
|
||||
std::move(clickCallback),
|
||||
st);
|
||||
}
|
||||
QPointer<RoundButton> addLeftButton(
|
||||
rpl::producer<QString> text,
|
||||
Fn<void()> clickCallback,
|
||||
const style::RoundButton& st) {
|
||||
return getDelegate()->addLeftButton(
|
||||
std::move(text),
|
||||
std::move(clickCallback),
|
||||
st);
|
||||
}
|
||||
const style::IconButton &st,
|
||||
Fn<void()> clickCallback = nullptr);
|
||||
void showLoading(bool show) {
|
||||
getDelegate()->showLoading(show);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -263,46 +263,35 @@ void BoxLayerWidget::clearButtons() {
|
|||
_topButton = nullptr;
|
||||
}
|
||||
|
||||
QPointer<RoundButton> BoxLayerWidget::addButton(
|
||||
rpl::producer<QString> text,
|
||||
Fn<void()> clickCallback,
|
||||
const style::RoundButton &st) {
|
||||
_buttons.emplace_back(this, std::move(text), st);
|
||||
auto result = QPointer<RoundButton>(_buttons.back());
|
||||
result->setTextTransform(RoundButton::TextTransform::NoTransform);
|
||||
result->setClickedCallback(std::move(clickCallback));
|
||||
result->show();
|
||||
result->widthValue(
|
||||
void BoxLayerWidget::addButton(object_ptr<AbstractButton> button) {
|
||||
_buttons.push_back(std::move(button));
|
||||
const auto raw = _buttons.back().data();
|
||||
raw->setParent(this);
|
||||
raw->show();
|
||||
raw->widthValue(
|
||||
) | rpl::start_with_next([=] {
|
||||
updateButtonsPositions();
|
||||
}, result->lifetime());
|
||||
return result;
|
||||
}, raw->lifetime());
|
||||
}
|
||||
|
||||
QPointer<RoundButton> BoxLayerWidget::addLeftButton(
|
||||
rpl::producer<QString> text,
|
||||
Fn<void()> clickCallback,
|
||||
const style::RoundButton &st) {
|
||||
_leftButton = object_ptr<RoundButton>(this, std::move(text), st);
|
||||
auto result = QPointer<RoundButton>(_leftButton);
|
||||
result->setTextTransform(RoundButton::TextTransform::NoTransform);
|
||||
result->setClickedCallback(std::move(clickCallback));
|
||||
result->show();
|
||||
result->widthValue(
|
||||
void BoxLayerWidget::addLeftButton(object_ptr<AbstractButton> button) {
|
||||
_leftButton = std::move(button);
|
||||
const auto raw = _leftButton.data();
|
||||
raw->setParent(this);
|
||||
raw->show();
|
||||
raw->widthValue(
|
||||
) | rpl::start_with_next([=] {
|
||||
updateButtonsPositions();
|
||||
}, result->lifetime());
|
||||
return result;
|
||||
}, raw->lifetime());
|
||||
}
|
||||
|
||||
QPointer<IconButton> BoxLayerWidget::addTopButton(const style::IconButton &st, Fn<void()> clickCallback) {
|
||||
_topButton = base::make_unique_q<IconButton>(this, st);
|
||||
auto result = QPointer<IconButton>(_topButton.get());
|
||||
result->setClickedCallback(std::move(clickCallback));
|
||||
result->show();
|
||||
void BoxLayerWidget::addTopButton(object_ptr<AbstractButton> button) {
|
||||
_topButton = base::make_unique_q<AbstractButton>(button.release());
|
||||
const auto raw = _topButton.get();
|
||||
raw->setParent(this);
|
||||
raw->show();
|
||||
updateButtonsPositions();
|
||||
updateTitlePosition();
|
||||
return result;
|
||||
}
|
||||
|
||||
void BoxLayerWidget::showLoading(bool show) {
|
||||
|
|
|
|||
|
|
@ -21,15 +21,12 @@ enum class type : uchar;
|
|||
} // namespace anim
|
||||
|
||||
namespace style {
|
||||
struct RoundButton;
|
||||
struct IconButton;
|
||||
struct Box;
|
||||
} // namespace style
|
||||
|
||||
namespace Ui {
|
||||
|
||||
class RoundButton;
|
||||
class IconButton;
|
||||
class AbstractButton;
|
||||
class FlatLabel;
|
||||
|
||||
class BoxLayerWidget : public LayerWidget, public BoxContentDelegate {
|
||||
|
|
@ -56,17 +53,9 @@ public:
|
|||
}
|
||||
|
||||
void clearButtons() override;
|
||||
QPointer<RoundButton> addButton(
|
||||
rpl::producer<QString> text,
|
||||
Fn<void()> clickCallback,
|
||||
const style::RoundButton &st) override;
|
||||
QPointer<RoundButton> addLeftButton(
|
||||
rpl::producer<QString> text,
|
||||
Fn<void()> clickCallback,
|
||||
const style::RoundButton &st) override;
|
||||
QPointer<IconButton> addTopButton(
|
||||
const style::IconButton &st,
|
||||
Fn<void()> clickCallback) override;
|
||||
void addButton(object_ptr<AbstractButton> button) override;
|
||||
void addLeftButton(object_ptr<AbstractButton> button) override;
|
||||
void addTopButton(object_ptr<AbstractButton> button) override;
|
||||
void showLoading(bool show) override;
|
||||
void updateButtonsPositions() override;
|
||||
QPointer<QWidget> outerContainer() override;
|
||||
|
|
@ -141,9 +130,9 @@ private:
|
|||
int _titleTop = 0;
|
||||
bool _closeByOutsideClick = true;
|
||||
|
||||
std::vector<object_ptr<RoundButton>> _buttons;
|
||||
object_ptr<RoundButton> _leftButton = { nullptr };
|
||||
base::unique_qptr<IconButton> _topButton = { nullptr };
|
||||
std::vector<object_ptr<AbstractButton>> _buttons;
|
||||
object_ptr<AbstractButton> _leftButton = { nullptr };
|
||||
base::unique_qptr<AbstractButton> _topButton = { nullptr };
|
||||
std::unique_ptr<LoadingProgress> _loadingProgress;
|
||||
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue