Skip to content

Commit

Permalink
menu
Browse files Browse the repository at this point in the history
  • Loading branch information
igagis committed Aug 27, 2024
1 parent 8769bda commit 019c6f2
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 3 deletions.
35 changes: 35 additions & 0 deletions src/bedsidemon/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <iomanip>

#include <clargs/parser.hpp>
#include <ruis/widget/button/base/push_button.hpp>

#include "spo2/contec_cms50d_plus.hpp"
#include "spo2/setocare_st_t130_u01.hpp"
#include "spo2/spo2_parameter_window.hpp"

#include "gui.hpp"
#include "settings_menu.hpp"

using namespace std::string_literals;
using namespace std::string_view_literals;
Expand All @@ -54,6 +56,9 @@ application::application(bool window, std::string_view res_path) :

auto c = make_root_widgets(this->gui.context);

this->menu_area = c.get().try_get_widget_as<ruis::container>("menu_area"sv);
ASSERT(this->menu_area)

// set up clock update
{
constexpr auto clock_update_interval_ms = 1000;
Expand Down Expand Up @@ -91,6 +96,18 @@ application::application(bool window, std::string_view res_path) :
this->spo2_sensor_v = std::make_unique<setocare_st_t130_u01>(pw, "/dev/ttyUSB0");

pw_container.push_back(pw);

// set up buttons
{
c.get().get_widget_as<ruis::push_button>("home_button"sv).click_handler = [](ruis::push_button& b) {
bedsidemon::application::inst().close_menu();
};

c.get().get_widget_as<ruis::push_button>("settings_button"sv).click_handler = [](ruis::push_button& b) {
auto& app = bedsidemon::application::inst();
app.open_menu(utki::make_shared<settings_menu>(app.gui.context));
};
}
}

std::unique_ptr<application> bedsidemon::create_application(std::string_view executable, utki::span<const char*> args)
Expand All @@ -114,3 +131,21 @@ std::unique_ptr<application> bedsidemon::create_application(std::string_view exe

return std::make_unique<application>(window, res_path);
}

void bedsidemon::application::open_menu(utki::shared_ref<ruis::widget> menu)
{
this->close_menu();

this->menu = menu;

this->menu_area->push_back(menu);
}

void bedsidemon::application::close_menu()
{
if (!this->menu) {
return;
}
this->menu->remove_from_parent();
this->menu.reset();
}
11 changes: 11 additions & 0 deletions src/bedsidemon/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,24 @@ namespace bedsidemon {

class application : public ruisapp::application
{
std::shared_ptr<ruis::container> menu_area;
std::shared_ptr<ruis::widget> menu;

std::unique_ptr<spo2_sensor> spo2_sensor_v;

// timer for updating clock view once a second
std::shared_ptr<ruis::timer> clock_timer;

public:
application(bool window, std::string_view res_path);

static application& inst()
{
return static_cast<application&>(ruisapp::application::inst());
}

void open_menu(utki::shared_ref<ruis::widget> menu);
void close_menu();
};

std::unique_ptr<application> create_application(std::string_view executable, utki::span<const char*> args);
Expand Down
9 changes: 6 additions & 3 deletions src/bedsidemon/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@ std::vector<utki::shared_ref<ruis::widget>> make_buttons(utki::shared_ref<ruis::
{
constexpr const auto button_icon_padding = 5_pp;

auto make_button = [&](std::string_view icon_res_id) {
auto make_button = [&](std::string_view icon_res_id, std::string id) {
// clang-format off
return m::push_button(c,
{
.layout_params = {
.dims = {lp::min, lp::fill}
},
.widget_params = {
.id = std::move(id)
}
},
{
Expand Down Expand Up @@ -91,8 +94,8 @@ std::vector<utki::shared_ref<ruis::widget>> make_buttons(utki::shared_ref<ruis::

// clang-format off
return {
make_button("img_home"sv),
make_button("img_cog"sv)
make_button("img_home"sv, "home_button"),
make_button("img_cog"sv, "settings_button")
};
// clang-format on
}
Expand Down
23 changes: 23 additions & 0 deletions src/bedsidemon/settings_menu.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "settings_menu.hpp"

using namespace bedsidemon;

settings_menu::settings_menu(utki::shared_ref<ruis::context> context) :
ruis::widget(
std::move(context), //
{
.dims = {ruis::lp::fill, ruis::lp::fill}
},
{}
),
ruis::nine_patch(
this->context, //
{
.nine_patch_params =
{
.nine_patch = this->context.get().loader.load<ruis::res::nine_patch>("ruis_npt_window_bg") //
} //
},
{}
)
{}
13 changes: 13 additions & 0 deletions src/bedsidemon/settings_menu.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <ruis/widget/label/nine_patch.hpp>

namespace bedsidemon {

class settings_menu : public ruis::nine_patch
{
public:
settings_menu(utki::shared_ref<ruis::context> context);
};

} // namespace bedsidemon

0 comments on commit 019c6f2

Please sign in to comment.