77 lines
2.3 KiB
C++
77 lines
2.3 KiB
C++
#include "pch.h"
|
|
#include "legacy_ui_overlay_services.h"
|
|
|
|
#include "app.h"
|
|
#include "node.h"
|
|
#include "node_popup_menu.h"
|
|
|
|
namespace pp::panopainter {
|
|
|
|
void initialize_legacy_overlay_node(App& app, Node& node)
|
|
{
|
|
node.set_manager(&app.layout);
|
|
node.init();
|
|
node.create();
|
|
node.loaded();
|
|
}
|
|
|
|
pp::foundation::Status attach_legacy_overlay_node(
|
|
App& app,
|
|
const std::shared_ptr<Node>& node) noexcept
|
|
{
|
|
if (!node) {
|
|
return pp::foundation::Status::invalid_argument("legacy overlay node is null");
|
|
}
|
|
|
|
auto* root = app.layout[app.main_id];
|
|
if (!root) {
|
|
return pp::foundation::Status::invalid_argument("legacy overlay root is missing");
|
|
}
|
|
|
|
root->add_child(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
|