Centralize retained menu popup attachment
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "app.h"
|
||||
#include "node.h"
|
||||
#include "node_popup_menu.h"
|
||||
|
||||
namespace pp::panopainter {
|
||||
|
||||
@@ -31,4 +32,45 @@ pp::foundation::Status attach_legacy_overlay_node(
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
pp::foundation::Result<std::shared_ptr<NodePopupMenu>> add_legacy_popup_menu(
|
||||
App& app,
|
||||
const char* template_id,
|
||||
float x,
|
||||
float y,
|
||||
float rtl_anchor_width) noexcept
|
||||
{
|
||||
if (!template_id) {
|
||||
return pp::foundation::Result<std::shared_ptr<NodePopupMenu>>::failure(
|
||||
pp::foundation::Status::invalid_argument("legacy popup template id is null"));
|
||||
}
|
||||
|
||||
auto* template_root = app.layout[const_hash(template_id)];
|
||||
if (!template_root || template_root->m_children.empty()) {
|
||||
return pp::foundation::Result<std::shared_ptr<NodePopupMenu>>::failure(
|
||||
pp::foundation::Status::invalid_argument("legacy popup template is missing"));
|
||||
}
|
||||
|
||||
auto popup = template_root->m_children[0]->clone<NodePopupMenu>();
|
||||
if (!popup) {
|
||||
return pp::foundation::Result<std::shared_ptr<NodePopupMenu>>::failure(
|
||||
pp::foundation::Status::invalid_argument("legacy popup clone failed"));
|
||||
}
|
||||
|
||||
popup->update();
|
||||
if (auto* root = app.layout[app.main_id]) {
|
||||
if (YGNodeStyleGetDirection(root->y_node) == YGDirectionRTL) {
|
||||
x = x - popup->m_size.x + rtl_anchor_width;
|
||||
}
|
||||
}
|
||||
popup->SetPositioning(YGPositionTypeAbsolute);
|
||||
popup->SetPosition(x, y);
|
||||
|
||||
const auto status = attach_legacy_overlay_node(app, popup);
|
||||
if (!status.ok()) {
|
||||
return pp::foundation::Result<std::shared_ptr<NodePopupMenu>>::failure(status);
|
||||
}
|
||||
|
||||
return pp::foundation::Result<std::shared_ptr<NodePopupMenu>>::success(popup);
|
||||
}
|
||||
|
||||
} // namespace pp::panopainter
|
||||
|
||||
Reference in New Issue
Block a user