Skip to content

Commit

Permalink
menu::on_close()
Browse files Browse the repository at this point in the history
  • Loading branch information
igagis committed Sep 17, 2024
1 parent 3dd223e commit c4e1fd6
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/bedsidemon/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,6 @@ void bedsidemon::application::close_menu()
return;
}
this->menu->remove_from_parent();
this->menu->on_close();
this->menu.reset();
}
2 changes: 2 additions & 0 deletions src/bedsidemon/menu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class menu : public ruis::nine_patch
std::u32string title,
utki::span<const utki::shared_ref<ruis::widget>> contents
);

virtual void on_close() {}
};

} // namespace bedsidemon
2 changes: 1 addition & 1 deletion src/bedsidemon/spo2/spo2_parameter_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ spo2_parameter_window::spo2_parameter_window(utki::shared_ref<ruis::context> con
// menu is already open
return;
}
auto pwm = utki::make_shared<spo2_parameter_window_menu>(this->context);
auto pwm = utki::make_shared<spo2_parameter_window_menu>(this->context, utki::make_weak_from(*this));
this->pw_menu = pwm;
application::inst().open_menu(pwm);
};
Expand Down
2 changes: 2 additions & 0 deletions src/bedsidemon/spo2/spo2_parameter_window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 18 additions & 2 deletions src/bedsidemon/spo2/spo2_parameter_window_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.

#include "spo2_parameter_window_menu.hpp"

#include "spo2_parameter_window.hpp"

using namespace std::string_literals;

using namespace bedsidemon;
Expand All @@ -36,7 +38,10 @@ std::vector<utki::shared_ref<ruis::widget>> make_menu_contents(utki::shared_ref<
}
} // namespace

spo2_parameter_window_menu::spo2_parameter_window_menu(utki::shared_ref<ruis::context> context) :
spo2_parameter_window_menu::spo2_parameter_window_menu(
utki::shared_ref<ruis::context> context, //
std::weak_ptr<spo2_parameter_window> spo2_pw
) :
// clang-format off
ruis::widget(
std::move(context),
Expand All @@ -49,6 +54,17 @@ spo2_parameter_window_menu::spo2_parameter_window_menu(utki::shared_ref<ruis::co
this->context, //
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();
}
10 changes: 9 additions & 1 deletion src/bedsidemon/spo2/spo2_parameter_window_menu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,19 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "../menu.hpp"

namespace bedsidemon {
class spo2_parameter_window;

class spo2_parameter_window_menu : public menu
{
std::weak_ptr<spo2_parameter_window> spo2_pw;

public:
spo2_parameter_window_menu(utki::shared_ref<ruis::context> context);
spo2_parameter_window_menu(
utki::shared_ref<ruis::context> context, //
std::weak_ptr<spo2_parameter_window> spo2_pw
);

void on_close() override;
};

} // namespace bedsidemon

0 comments on commit c4e1fd6

Please sign in to comment.