Skip to content

Commit

Permalink
quit dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
igagis committed Sep 13, 2024
1 parent f86948b commit 166a52c
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 38 deletions.
7 changes: 6 additions & 1 deletion src/bedsidemon/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.

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

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

#include "about_menu.hpp"
#include "gui.hpp"
#include "quit_dialog.hpp"
#include "settings_menu.hpp"

using namespace std::string_literals;
Expand Down Expand Up @@ -129,7 +131,10 @@ application::application(bool window, std::string_view res_path) :

c.get().get_widget_as<ruis::push_button>("exit_button"sv).click_handler = [](ruis::push_button& b) {
auto& app = bedsidemon::application::inst();
app.quit();
auto& o = app.gui.get_root().get_widget<ruis::overlay>();
o.context.get().post_to_ui_thread([&o]() {
o.push_back(utki::make_shared<quit_dialog>(o.context));
});
};
}
}
Expand Down
40 changes: 29 additions & 11 deletions src/bedsidemon/dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ using namespace ruis::make;
} // namespace m

namespace {
constexpr auto color_dialog_surroundings = 0xa0000000;
constexpr auto color_dialog_surroundings = 0xb0000000;
} // namespace

namespace {
Expand Down Expand Up @@ -67,17 +67,35 @@ std::vector<utki::shared_ref<widget>> make_root_widget_structure(
}
}
),
m::nine_patch(c,
m::pile(c,
{},
{
.widget_params{
.id = "ruis_nine_patch"s
},
.container_params = std::move(container_params),
.nine_patch_params{
.nine_patch = c.get().loader.load<ruis::res::nine_patch>("ruis_npt_window_bg")
}
},
contents
[&](){
auto mp = m::mouse_proxy(c,
{
.layout_params{
.dims{ruis::dim::fill, ruis::dim::fill}
}
}
);
mp.get().mouse_button_handler = [](mouse_proxy& w, const mouse_button_event&){return true;};
mp.get().mouse_move_handler = [](mouse_proxy& w, const mouse_move_event&){return true;};
mp.get().hovered_change_handler = [](mouse_proxy& w, unsigned pointer_id){return true;};
return mp;
}(),
m::nine_patch(c,
{
.widget_params{
.id = "ruis_nine_patch"s
},
.container_params = std::move(container_params),
.nine_patch_params{
.nine_patch = c.get().loader.load<ruis::res::nine_patch>("ruis_npt_window_bg")
}
},
contents
)
}
)
};
// clang-format on
Expand Down
89 changes: 63 additions & 26 deletions src/bedsidemon/quit_dialog.cpp
Original file line number Diff line number Diff line change
@@ -1,63 +1,90 @@
#include "quit_dialog.hpp"

#include <ruis/widget/label/text.hpp>
#include <ruis/widget/label/gap.hpp>
#include <ruis/widget/button/push_button.hpp>
#include <ruis/widget/label/gap.hpp>
#include <ruis/widget/label/text.hpp>

#include "application.hpp"

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

using namespace ruis::length_literals;

using namespace bedsidemon;

namespace m{
namespace m {
using namespace ruis::make;
}
} // namespace m

namespace{
constexpr auto dimension_buttons_gap = 10_pp;
}
namespace {
constexpr auto dimension_gap = 10_pp;
constexpr auto dimension_button_width = 100_pp;
constexpr auto dimension_button_height = 40_pp;
} // namespace

namespace{
std::vector<utki::shared_ref<ruis::widget>> make_root_widget_structure(utki::shared_ref<ruis::context> c){
auto make_button = [&](std::string id, std::u32string text){
// clang-format off
namespace {
std::vector<utki::shared_ref<ruis::widget>> make_root_widget_structure(utki::shared_ref<ruis::context> c)
{
auto make_button = [&](std::string id, std::u32string text) {
// clang-format off
return m::push_button(c,
{},
{
.layout_params{
.dims = {dimension_button_width, dimension_button_height}
},
.widget_params{
.id = std::move(id)
}
},
{
m::text(c,
{},
std::move(text)
)
}
);
// clang-format on
};
// clang-format on
};

// clang-format off
// clang-format off
return {
m::text(c,
{},
U"Quit program?"s
),
m::gap(c,
{
.layout_params{
.dims = {0_px, dimension_gap}
}
}
),
m::row(c,
{},
{
make_button("yet_button", U"Yes"s),
make_button("yes_button"s, U"Yes"s),
m::gap(c,
{
.layout_params{
.dims = {dimension_buttons_gap, 0_px}
.dims = {dimension_gap, 0_px}
}
}
),
make_button("no_button", U"No"s),
make_button("no_button"s, U"No"s),
}
),
m::gap(c,
{
.layout_params{
.dims = {0_px, dimension_gap}
}
}
)
};
// clang-format on
}
// clang-format on
}
} // namespace

quit_dialog::quit_dialog(utki::shared_ref<ruis::context> context) :
ruis::widget(
Expand All @@ -69,11 +96,21 @@ quit_dialog::quit_dialog(utki::shared_ref<ruis::context> context) :
),
ruis::dialog(
this->context, //
{
.container_params{
.layout = ruis::layout::column
}
},
{.container_params{.layout = ruis::layout::column}},
make_root_widget_structure(this->context)
)
{}
{
{
auto& b = this->get_widget_as<ruis::push_button>("yes_button"sv);
b.click_handler = [](ruis::push_button& b) {
bedsidemon::application::inst().quit();
};
}

{
auto& b = this->get_widget_as<ruis::push_button>("no_button"sv);
b.click_handler = [this](ruis::push_button& b) {
this->close();
};
}
}

0 comments on commit 166a52c

Please sign in to comment.