Fix popup menu with variable item height.
This commit is contained in:
parent
14f5a828fc
commit
4ff70e7dff
1 changed files with 35 additions and 21 deletions
|
|
@ -148,29 +148,44 @@ not_null<QAction*> Menu::addAction(base::unique_qptr<ItemBase> widget) {
|
|||
const auto raw = widget.get();
|
||||
_actionWidgets.push_back(std::move(widget));
|
||||
|
||||
rpl::combine(
|
||||
raw->minWidthValue(),
|
||||
raw->heightValue()
|
||||
) | rpl::start_with_next([=] {
|
||||
const auto newWidth = _forceWidth
|
||||
const auto recountWidth = [=] {
|
||||
return _forceWidth
|
||||
? _forceWidth
|
||||
: std::clamp(
|
||||
_actionWidgets.empty()
|
||||
(_actionWidgets.empty()
|
||||
? 0
|
||||
: (*ranges::max_element(
|
||||
_actionWidgets,
|
||||
std::less<>(),
|
||||
&ItemBase::minWidth))->minWidth(),
|
||||
&ItemBase::minWidth))->minWidth()),
|
||||
_st.widthMin,
|
||||
_st.widthMax);
|
||||
const auto newHeight = ranges::accumulate(
|
||||
_actionWidgets,
|
||||
0,
|
||||
ranges::plus(),
|
||||
&ItemBase::height);
|
||||
resizeFromInner(newWidth, newHeight);
|
||||
};
|
||||
const auto recountHeight = [=] {
|
||||
auto result = 0;
|
||||
for (const auto &widget : _actionWidgets) {
|
||||
if (widget->y() != result) {
|
||||
widget->move(0, result);
|
||||
}
|
||||
result += widget->height();
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
raw->minWidthValue(
|
||||
) | rpl::skip(1) | rpl::filter([=] {
|
||||
return !_forceWidth;
|
||||
}) | rpl::start_with_next([=] {
|
||||
resizeFromInner(recountWidth(), height());
|
||||
}, raw->lifetime());
|
||||
|
||||
raw->heightValue(
|
||||
) | rpl::skip(1) | rpl::start_with_next([=] {
|
||||
resizeFromInner(width(), recountHeight());
|
||||
}, raw->lifetime());
|
||||
|
||||
resizeFromInner(recountWidth(), recountHeight());
|
||||
|
||||
updateSelected(QCursor::pos());
|
||||
|
||||
return action;
|
||||
|
|
@ -204,12 +219,11 @@ bool Menu::empty() const {
|
|||
}
|
||||
|
||||
void Menu::resizeFromInner(int w, int h) {
|
||||
if ((w == width()) && (h == height())) {
|
||||
return;
|
||||
}
|
||||
resize(w, h);
|
||||
if (const auto s = QSize(w, h); s != size()) {
|
||||
resize(s);
|
||||
_resizesFromInner.fire({});
|
||||
}
|
||||
}
|
||||
|
||||
rpl::producer<> Menu::resizesFromInner() const {
|
||||
return _resizesFromInner.events();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue