Allow menu items to update height.
This commit is contained in:
parent
515f215c05
commit
d805dca4c7
2 changed files with 20 additions and 15 deletions
|
|
@ -27,8 +27,12 @@ public:
|
||||||
_hiddenCallback = std::move(callback);
|
_hiddenCallback = std::move(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<not_null<QAction*>> &actions() const;
|
[[nodiscard]] const std::vector<not_null<QAction*>> &actions() const;
|
||||||
bool empty() const;
|
[[nodiscard]] bool empty() const;
|
||||||
|
|
||||||
|
[[nodiscard]] not_null<Menu::Menu*> menu() const {
|
||||||
|
return _menu;
|
||||||
|
}
|
||||||
|
|
||||||
~DropdownMenu();
|
~DropdownMenu();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -129,28 +129,29 @@ not_null<QAction*> Menu::addAction(base::unique_qptr<ItemBase> widget) {
|
||||||
const auto raw = widget.get();
|
const auto raw = widget.get();
|
||||||
_actionWidgets.push_back(std::move(widget));
|
_actionWidgets.push_back(std::move(widget));
|
||||||
|
|
||||||
raw->minWidthValue(
|
rpl::combine(
|
||||||
|
raw->minWidthValue(),
|
||||||
|
raw->heightValue()
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=] {
|
||||||
const auto newWidth = _forceWidth
|
const auto newWidth = _forceWidth
|
||||||
? _forceWidth
|
? _forceWidth
|
||||||
: std::clamp(
|
: std::clamp(
|
||||||
_actionWidgets.empty()
|
_actionWidgets.empty()
|
||||||
? 0
|
? 0
|
||||||
: (*ranges::max_element(
|
: (*ranges::max_element(
|
||||||
_actionWidgets,
|
_actionWidgets,
|
||||||
std::less<>(),
|
std::less<>(),
|
||||||
&ItemBase::minWidth))->minWidth(),
|
&ItemBase::minWidth))->minWidth(),
|
||||||
_st.widthMin,
|
_st.widthMin,
|
||||||
_st.widthMax);
|
_st.widthMax);
|
||||||
resizeFromInner(newWidth, height());
|
const auto newHeight = ranges::accumulate(
|
||||||
|
_actionWidgets,
|
||||||
|
0,
|
||||||
|
ranges::plus(),
|
||||||
|
&ItemBase::height);
|
||||||
|
resizeFromInner(newWidth, newHeight);
|
||||||
}, raw->lifetime());
|
}, raw->lifetime());
|
||||||
|
|
||||||
const auto newHeight = ranges::accumulate(
|
|
||||||
_actionWidgets,
|
|
||||||
0,
|
|
||||||
ranges::plus(),
|
|
||||||
&ItemBase::height);
|
|
||||||
resizeFromInner(width(), newHeight);
|
|
||||||
updateSelected(QCursor::pos());
|
updateSelected(QCursor::pos());
|
||||||
|
|
||||||
return action;
|
return action;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue