Skip to content

Commit

Permalink
clock
Browse files Browse the repository at this point in the history
  • Loading branch information
igagis committed Aug 20, 2024
1 parent 790767f commit 49d1a86
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
19 changes: 15 additions & 4 deletions src/bedsidemon/application.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 "application.hpp"

#include <iomanip>

#include <clargs/parser.hpp>

#include "spo2/contec_cms50d_plus.hpp"
Expand All @@ -30,6 +32,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "gui.hpp"

using namespace std::string_literals;
using namespace std::string_view_literals;

using namespace bedsidemon;

Expand All @@ -55,14 +58,22 @@ application::application(bool window, std::string_view res_path) :
{
constexpr auto clock_update_interval_ms = 1000;

auto& time_text_widget = c.get().get_widget_as<ruis::text>("clock_text"sv);

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, time_text_widget = utki::make_shared_from(time_text_widget)](uint32_t elapsed_ms) {
auto now = std::chrono::system_clock::now();
auto time = std::chrono::system_clock::to_time_t(now);
auto tm = *std::localtime(&time);

std::stringstream ss;
ss << std::put_time(&tm, "%T");

time_text_widget.get().set_text(ss.str());

this->clock_timer->stop();
this->clock_timer->start(clock_update_interval_ms);
std::cout << "timeout exit" << std::endl;
ASSERT(this->clock_timer->is_running())
}
);
Expand Down
32 changes: 20 additions & 12 deletions src/bedsidemon/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,22 +170,30 @@ utki::shared_ref<ruis::widget> bedsidemon::make_root_widgets(utki::shared_ref<ru
}
}
),
m::text(c,
m::pile(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
.dims = {100_pp, lp::min},
.align = {lp::align::center, lp::align::center}

}
},
U"10:23"s
{
m::text(c,
{
.widget_params = {
.id = "clock_text"s
},
.color_params = {
.color = style::color_info_text
},
.text_params = {
.font_size = style::font_size_label
}
},
{}
)
}
),
m::gap(c,
{
Expand Down

0 comments on commit 49d1a86

Please sign in to comment.