Skip to content

Commit

Permalink
clock view
Browse files Browse the repository at this point in the history
  • Loading branch information
igagis committed Aug 17, 2024
1 parent da4b007 commit 790767f
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 19 deletions.
19 changes: 19 additions & 0 deletions src/bedsidemon/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,25 @@ application::application(bool window, std::string_view res_path) :
this->gui.context.get().loader.mount_res_pack(*this->get_res_file(papki::as_dir(res_path)));

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

// set up clock update
{
constexpr auto clock_update_interval_ms = 1000;

this->clock_timer = utki::make_shared<ruis::timer>( //
this->gui.context.get().updater,
[this](uint32_t elapsed_ms) {
// TODO: update time
std::cout << "timeout" << std::endl;
this->clock_timer->stop();
this->clock_timer->start(clock_update_interval_ms);
std::cout << "timeout exit" << std::endl;
ASSERT(this->clock_timer->is_running())
}
);
this->clock_timer->start(0);
}

this->gui.set_root(c);

auto& pw_container = c.get().get_widget_as<ruis::container>("pw_container");
Expand Down
4 changes: 4 additions & 0 deletions src/bedsidemon/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.

#pragma once

#include <ruis/util/timer.hpp>
#include <ruisapp/application.hpp>

#include "spo2/spo2_sensor.hpp"
Expand All @@ -31,6 +32,9 @@ class application : public ruisapp::application
{
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);
};
Expand Down
83 changes: 67 additions & 16 deletions src/bedsidemon/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.

#include <ruis/widget/button/base/push_button.hpp>
#include <ruis/widget/group/margins.hpp>
#include <ruis/widget/label/gap.hpp>
#include <ruis/widget/label/image.hpp>
#include <ruis/widget/label/rectangle.hpp>
#include <ruis/widget/label/text.hpp>

#include "style.hpp"

Expand Down Expand Up @@ -97,14 +99,17 @@ std::vector<utki::shared_ref<ruis::widget>> make_buttons(utki::shared_ref<ruis::
} // namespace

namespace {
utki::shared_ref<ruis::rectangle> make_separator(utki::shared_ref<ruis::context> c)
utki::shared_ref<ruis::rectangle> make_separator(utki::shared_ref<ruis::context> c, bool vertical = false)
{
// clang-format off
return m::rectangle(
std::move(c),
{
.layout_params = {
.dims = {lp::fill, 1_pp}
.dims = {
vertical ? 1_pp : lp::fill,
vertical ? lp::fill : 1_pp
}
},
.color_params = {
.color = style::color_border
Expand All @@ -113,6 +118,16 @@ utki::shared_ref<ruis::rectangle> make_separator(utki::shared_ref<ruis::context>
);
// clang-format on
}

auto make_horizontal_separator(utki::shared_ref<ruis::context> c)
{
return make_separator(c);
}

auto make_vertical_separator(utki::shared_ref<ruis::context> c)
{
return make_separator(c, true);
}
} // namespace

utki::shared_ref<ruis::widget> bedsidemon::make_root_widgets(utki::shared_ref<ruis::context> c)
Expand All @@ -129,43 +144,79 @@ utki::shared_ref<ruis::widget> bedsidemon::make_root_widgets(utki::shared_ref<ru
}
},
{
m::container(c,
m::row(c,
{
.layout_params = {
.dims = {lp::fill, alarms_area_height}
},
.widget_params = {
.id = "notification_area"s,
}
},
{
m::row(c,
{
.layout_params = {
.dims = {lp::fill, lp::fill},
.weight = 1
},
.widget_params = {
.id = "notification_area"s,
}
}
),
make_vertical_separator(c),
m::gap(c,
{
.layout_params = {
.dims = {style::clock_padding, 0_pp}
}
}
),
m::text(c,
{
.layout_params = {
.dims = {lp::min, lp::min}
},
.widget_params = {
.id = "clock_text"s
},
.color_params = {
.color = style::color_info_text
},
.text_params = {
.font_size = style::font_size_label
}
},
U"10:23"s
),
m::gap(c,
{
.layout_params = {
.dims = {style::clock_padding, 0_pp}
}
}
)
}
),
make_separator(c),
m::container(c,
make_horizontal_separator(c),
m::column(c,
{
.layout_params = {
.dims = {lp::fill, lp::fill},
.weight = 1
},
.widget_params = {
.id = "pw_container"s
},
.container_params = {
.layout = ruis::layout::column
}
},
{}
),
make_separator(c),
m::container(c,
make_horizontal_separator(c),
m::row(c,
{
.layout_params = {
.dims = {lp::fill, buttons_area_height}
},
.widget_params = {
.id = "button_area"s
},
.container_params = {
.layout = ruis::layout::row
}
},
make_buttons(c)
Expand Down
5 changes: 2 additions & 3 deletions src/bedsidemon/spo2/spo2_parameter_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ using namespace ruis::length_literals;
constexpr auto color_main_value = 0xffffff00;
constexpr auto color_secondary_value = 0xff00ffff;

constexpr auto numeric_area_padding = 5_pp;

constexpr auto font_size_label = 16_pp;
constexpr auto font_size_main_value = 60_pp;
constexpr auto font_size_secondary_value = 40_pp;
Expand Down Expand Up @@ -178,7 +176,7 @@ std::vector<utki::shared_ref<ruis::widget>> make_widgets(utki::shared_ref<ruis::
.layout = ruis::layout::column
},
.frame_params = {
.borders = {numeric_area_padding, numeric_area_padding, numeric_area_padding, numeric_area_padding}
.borders = {style::pw_padding, style::pw_padding, style::pw_padding, style::pw_padding}
}
},
make_numeric_content(c)
Expand Down Expand Up @@ -266,4 +264,5 @@ void spo2_parameter_window::trigger_heart()
void spo2_parameter_window::on_heart_timer_expired()
{
this->heart.set_visible(false);
std::cout << "heart" << std::endl;
}
6 changes: 6 additions & 0 deletions src/bedsidemon/style.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.

#pragma once

#include <ruis/util/length.hpp>

namespace bedsidemon::style {

constexpr auto color_border = 0xff808080;
constexpr auto color_info_text = 0xff808080;

constexpr auto font_size_label = ruis::length::make_pp(16);
constexpr auto pw_padding = ruis::length::make_pp(5);
constexpr auto clock_padding = ruis::length::make_pp(10);

} // namespace bedsidemon::style

0 comments on commit 790767f

Please sign in to comment.