diff --git a/src/bedsidemon/application.cpp b/src/bedsidemon/application.cpp index d026a79..ed107fb 100644 --- a/src/bedsidemon/application.cpp +++ b/src/bedsidemon/application.cpp @@ -176,5 +176,6 @@ void bedsidemon::application::close_menu() return; } this->menu->remove_from_parent(); + this->menu->on_close(); this->menu.reset(); } diff --git a/src/bedsidemon/menu.hpp b/src/bedsidemon/menu.hpp index 5fc6108..48129b2 100644 --- a/src/bedsidemon/menu.hpp +++ b/src/bedsidemon/menu.hpp @@ -33,6 +33,8 @@ class menu : public ruis::nine_patch std::u32string title, utki::span> contents ); + + virtual void on_close() {} }; } // namespace bedsidemon diff --git a/src/bedsidemon/spo2/spo2_parameter_window.cpp b/src/bedsidemon/spo2/spo2_parameter_window.cpp index 84b89c8..71164b6 100644 --- a/src/bedsidemon/spo2/spo2_parameter_window.cpp +++ b/src/bedsidemon/spo2/spo2_parameter_window.cpp @@ -266,7 +266,7 @@ spo2_parameter_window::spo2_parameter_window(utki::shared_ref con // menu is already open return; } - auto pwm = utki::make_shared(this->context); + auto pwm = utki::make_shared(this->context, utki::make_weak_from(*this)); this->pw_menu = pwm; application::inst().open_menu(pwm); }; diff --git a/src/bedsidemon/spo2/spo2_parameter_window.hpp b/src/bedsidemon/spo2/spo2_parameter_window.hpp index 8b88a0f..c9eeb1b 100644 --- a/src/bedsidemon/spo2/spo2_parameter_window.hpp +++ b/src/bedsidemon/spo2/spo2_parameter_window.hpp @@ -37,6 +37,8 @@ class spo2_parameter_window : virtual public ruis::widget, // private ruis::container { + friend class spo2_parameter_window_menu; + ruis::text& spo2_value; ruis::text& bpm_value; ruis::widget& heart; diff --git a/src/bedsidemon/spo2/spo2_parameter_window_menu.cpp b/src/bedsidemon/spo2/spo2_parameter_window_menu.cpp index 518ec25..3d2f5d2 100644 --- a/src/bedsidemon/spo2/spo2_parameter_window_menu.cpp +++ b/src/bedsidemon/spo2/spo2_parameter_window_menu.cpp @@ -21,6 +21,8 @@ along with this program. If not, see . #include "spo2_parameter_window_menu.hpp" +#include "spo2_parameter_window.hpp" + using namespace std::string_literals; using namespace bedsidemon; @@ -36,7 +38,10 @@ std::vector> make_menu_contents(utki::shared_ref< } } // namespace -spo2_parameter_window_menu::spo2_parameter_window_menu(utki::shared_ref context) : +spo2_parameter_window_menu::spo2_parameter_window_menu( + utki::shared_ref context, // + std::weak_ptr spo2_pw +) : // clang-format off ruis::widget( std::move(context), @@ -49,6 +54,17 @@ spo2_parameter_window_menu::spo2_parameter_window_menu(utki::shared_refcontext, // U"SpO2"s, make_menu_contents(this->context) - ) + ), + spo2_pw(std::move(spo2_pw)) // clang-format on {} + +void spo2_parameter_window_menu::on_close() +{ + auto pw = this->spo2_pw.lock(); + if (!pw) { + return; + } + + pw->pw_menu.reset(); +} diff --git a/src/bedsidemon/spo2/spo2_parameter_window_menu.hpp b/src/bedsidemon/spo2/spo2_parameter_window_menu.hpp index 897553c..3be0b45 100644 --- a/src/bedsidemon/spo2/spo2_parameter_window_menu.hpp +++ b/src/bedsidemon/spo2/spo2_parameter_window_menu.hpp @@ -24,11 +24,19 @@ along with this program. If not, see . #include "../menu.hpp" namespace bedsidemon { +class spo2_parameter_window; class spo2_parameter_window_menu : public menu { + std::weak_ptr spo2_pw; + public: - spo2_parameter_window_menu(utki::shared_ref context); + spo2_parameter_window_menu( + utki::shared_ref context, // + std::weak_ptr spo2_pw + ); + + void on_close() override; }; } // namespace bedsidemon