Centralize retained panel popup attachment

This commit is contained in:
2026-06-06 10:46:29 +02:00
parent 5ff2992c0e
commit ab36af0a8f
9 changed files with 49 additions and 14 deletions

View File

@@ -3,6 +3,7 @@
#include "legacy_quick_ui_services.h"
#include "app.h"
#include "legacy_ui_overlay_services.h"
#include "node_image.h"
#include "node_stroke_preview.h"
@@ -95,7 +96,7 @@ private:
popup->SetHeight(glm::max(hh, 400.f));
popup->SetPositioning(YGPositionTypeAbsolute);
popup->SetPosition(popup_pos);
panel_.root()->add_child(popup);
(void)attach_legacy_overlay_node_to_root(panel_, popup);
panel_.root()->update();
popup->tick(0);
@@ -153,7 +154,7 @@ private:
popup->SetPositioning(YGPositionTypeAbsolute);
popup->SetPosition(popup_pos);
panel_.root()->add_child(popup);
(void)attach_legacy_overlay_node_to_root(panel_, popup);
panel_.root()->update();
popup->tick(0);

View File

@@ -32,6 +32,23 @@ pp::foundation::Status attach_legacy_overlay_node(
return pp::foundation::Status::success();
}
pp::foundation::Status attach_legacy_overlay_node_to_root(
Node& anchor,
const std::shared_ptr<Node>& node) noexcept
{
if (!node) {
return pp::foundation::Status::invalid_argument("legacy overlay node is null");
}
auto* root = anchor.root();
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,

View File

@@ -16,6 +16,10 @@ void initialize_legacy_overlay_node(App& app, Node& node);
App& app,
const std::shared_ptr<Node>& node) noexcept;
[[nodiscard]] pp::foundation::Status attach_legacy_overlay_node_to_root(
Node& anchor,
const std::shared_ptr<Node>& node) noexcept;
[[nodiscard]] pp::foundation::Result<std::shared_ptr<NodePopupMenu>> add_legacy_popup_menu(
App& app,
const char* template_id,

View File

@@ -4,6 +4,7 @@
#include "assets/brush_package.h"
#include "app_core/brush_ui.h"
#include "legacy_brush_ui_services.h"
#include "legacy_ui_overlay_services.h"
#include "asset.h"
#include "texture.h"
@@ -579,7 +580,7 @@ void NodePanelBrushPreset::init()
m_btn_menu->on_click = [this](Node* b) {
auto popup = add_child_file<NodePopupMenu>("data/dialogs/panel-brushes.xml", "tpl-brush-popup");
popup->SetPosition(b->m_pos.x + b->m_size.x, b->m_pos.y);
root()->add_child(popup);
(void)pp::panopainter::attach_legacy_overlay_node_to_root(*this, popup);
root()->update();
auto bounds = root()->GetSize() - zw(popup->get_children_rect());
popup->SetPosition(glm::clamp(popup->m_pos, { 0, 0 }, bounds));

View File

@@ -1,6 +1,7 @@
#include "pch.h"
#include "app_core/brush_ui.h"
#include "legacy_brush_ui_services.h"
#include "legacy_ui_overlay_services.h"
#include "log.h"
#include "node_panel_stroke.h"
#include "canvas.h"
@@ -316,7 +317,7 @@ void NodePanelStroke::init_controls()
m_preset_button->on_click = [this](Node*) {
auto screen = root()->m_size;
glm::vec2 pos = m_preset_button->m_pos + glm::vec2(m_preset_button->m_size.x, 0);
root()->add_child(App::I->presets);
(void)pp::panopainter::attach_legacy_overlay_node_to_root(*this, App::I->presets);
auto tick = root()->add_child<NodeImage>();
tick->SetPositioning(YGPositionTypeAbsolute);
tick->SetSize(16, 32);
@@ -367,7 +368,7 @@ void NodePanelStroke::init_controls()
m_brush_button->on_click = [this](Node*) {
auto screen = root()->m_size;
glm::vec2 pos = m_brush_button->m_pos + glm::vec2(m_brush_button->m_size.x, 0);
root()->add_child(m_brush_popup);
(void)pp::panopainter::attach_legacy_overlay_node_to_root(*this, m_brush_popup);
auto tick = root()->add_child<NodeImage>();
tick->SetPositioning(YGPositionTypeAbsolute);
tick->SetSize(16, 32);
@@ -403,7 +404,7 @@ void NodePanelStroke::init_controls()
m_dual_brush_button->on_click = [this](Node*) {
auto screen = root()->m_size;
glm::vec2 pos = m_dual_brush_button->m_pos + glm::vec2(m_dual_brush_button->m_size.x, 0);
root()->add_child(m_brush_popup);
(void)pp::panopainter::attach_legacy_overlay_node_to_root(*this, m_brush_popup);
auto tick = root()->add_child<NodeImage>();
tick->SetPositioning(YGPositionTypeAbsolute);
tick->SetSize(16, 32);
@@ -439,7 +440,7 @@ void NodePanelStroke::init_controls()
m_pattern_button->on_click = [this](Node*) {
auto screen = root()->m_size;
glm::vec2 pos = m_pattern_button->m_pos + glm::vec2(m_pattern_button->m_size.x, 0);
root()->add_child(m_pattern_popup);
(void)pp::panopainter::attach_legacy_overlay_node_to_root(*this, m_pattern_popup);
auto tick = root()->add_child<NodeImage>();
tick->SetPositioning(YGPositionTypeAbsolute);
tick->SetSize(16, 32);