Narrow retained UI overlay lifetime debt

This commit is contained in:
2026-06-15 19:26:11 +02:00
parent f907d88c26
commit 565564c061
15 changed files with 603 additions and 67 deletions

View File

@@ -2,7 +2,9 @@
#include "app_core/app_dialog.h"
#include "foundation/result.h"
#include "ui_core/overlay_lifetime.h"
#include "node.h"
#include "node_image.h"
#include "shader.h"
#include <functional>
@@ -104,6 +106,13 @@ void release_legacy_mouse_capture(Node& node) noexcept;
void configure_legacy_popup_overlay(Node& node) noexcept;
void activate_legacy_popup_overlay(Node& node) noexcept;
void close_legacy_popup_overlay(Node& node) noexcept;
void close_legacy_overlay_handle_ignoring_status(
Node& anchor,
pp::ui::NodeHandle overlay) noexcept;
void close_legacy_overlay_handles_if_open(
Node& anchor,
const pp::foundation::Result<pp::ui::NodeHandle>& popup_overlay,
const pp::foundation::Result<pp::ui::NodeHandle>& tick_overlay) noexcept;
void close_legacy_dialog_and_hide_keyboard(App& app, Node& node);
void close_legacy_popup_panel(
Node& node,
@@ -117,6 +126,15 @@ void close_legacy_popup_panel(
Node& anchor,
const std::shared_ptr<Node>& node) noexcept;
[[nodiscard]] pp::foundation::Result<pp::ui::NodeHandle> open_legacy_overlay_node_with_handle(
Node& anchor,
const std::shared_ptr<Node>& node,
bool modal = true) noexcept;
[[nodiscard]] pp::foundation::Status close_legacy_overlay_node(
Node& anchor,
pp::ui::NodeHandle overlay) noexcept;
[[nodiscard]] pp::foundation::Result<std::shared_ptr<NodePopupMenu>> add_legacy_popup_menu(
App& app,
const char* template_id,
@@ -163,6 +181,46 @@ std::shared_ptr<T> add_legacy_overlay_node(App& app)
return node;
}
template <typename PopupT>
concept LegacyPopupOverlay = requires(PopupT& popup, const std::function<void(Node*)>& close_cb) {
popup.on_popup_close = close_cb;
};
template <LegacyPopupOverlay PopupT>
bool open_popup_and_tick_overlay(
Node& anchor,
const std::shared_ptr<PopupT>& popup,
const glm::vec2& tick_pos,
float button_height) noexcept
{
if (!popup) {
return false;
}
auto tick = make_legacy_overlay_node_for_anchor<NodeImage>(anchor);
tick->SetPositioning(YGPositionTypeAbsolute);
tick->SetSize(16, 32);
tick->SetPosition(tick_pos.x, tick_pos.y + (button_height - 32) * 0.5f);
tick->set_image("data/ui/popup-tick.png");
tick->m_scale = { 1, 1 };
const auto popup_overlay = open_legacy_overlay_node_with_handle(anchor, popup);
const auto tick_overlay = open_legacy_overlay_node_with_handle(anchor, tick);
if (!popup_overlay || !tick_overlay) {
close_legacy_overlay_handles_if_open(anchor, popup_overlay, tick_overlay);
return false;
}
const auto popup_handle = popup_overlay.value();
const auto tick_handle = tick_overlay.value();
popup->on_popup_close = [&anchor, popup_handle, tick_handle](Node*) {
close_legacy_overlay_handle_ignoring_status(anchor, popup_handle);
close_legacy_overlay_handle_ignoring_status(anchor, tick_handle);
};
return true;
}
template <class PopupT>
void bind_legacy_popup_close_destroys_overlay(
PopupT& popup,