Skip to content

Commit

Permalink
menu close button
Browse files Browse the repository at this point in the history
  • Loading branch information
igagis committed Sep 12, 2024
1 parent 4c7d1e4 commit 7c519d0
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/bedsidemon/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ 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)
void bedsidemon::application::open_menu(utki::shared_ref<bedsidemon::menu> menu)
{
this->close_menu();

Expand Down
5 changes: 3 additions & 2 deletions src/bedsidemon/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.

#include "spo2/spo2_sensor.hpp"

#include "menu.hpp"
#include "settings.hpp"

namespace bedsidemon {

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

std::unique_ptr<spo2_sensor> fake_spo2_sensor_v;
std::unique_ptr<spo2_sensor> real_spo2_sensor_v;
Expand All @@ -52,7 +53,7 @@ class application : public ruisapp::application
return static_cast<application&>(ruisapp::application::inst());
}

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

Expand Down
51 changes: 49 additions & 2 deletions src/bedsidemon/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,27 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "menu.hpp"

#include <ruis/widget/group/margins.hpp>
#include <ruis/widget/label/gap.hpp>
#include <ruis/widget/label/text.hpp>

#include "application.hpp"
#include "rectangle_push_button.hpp"
#include "style.hpp"

using namespace std::string_literals;

using namespace ruis::length_literals;

using namespace bedsidemon;

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

namespace {
constexpr auto size_close_button = 40_pp;
} // namespace

menu::menu(
utki::shared_ref<ruis::context> context, //
std::u32string title,
Expand Down Expand Up @@ -61,6 +70,7 @@ menu::menu(
m::row(this->context,
{
.layout_params{
.dims{ruis::dim::fill, ruis::dim::min},
.align{ruis::align::front, ruis::align::center}
}
},
Expand All @@ -76,7 +86,38 @@ menu::menu(
},
std::move(title)
),

m::gap(this->context,
{
.layout_params = {
.weight = 1
}
}
),
m::rectangle_push_button(this->context,
{
.layout_params{
.dims{size_close_button, size_close_button}
},
.widget_params{
.id = "close_button"s
},
.container_params{
.layout = ruis::layout::pile
}
},
{
m::image(this->context,
{
.layout_params{
.dims{ruis::dim::fill, ruis::dim::fill}
},
.image_params{
.img = this->context.get().loader.load<ruis::res::image>("img_close")
}
}
)
}
)
}
),
m::margins(this->context,
Expand All @@ -97,4 +138,10 @@ menu::menu(
}
)
// clang-format on
{}
{
this->get_widget_as<ruis::push_button>("close_button").click_handler = [](ruis::push_button& b) {
b.context.get().post_to_ui_thread([]() {
bedsidemon::application::inst().close_menu();
});
};
}
26 changes: 26 additions & 0 deletions src/bedsidemon/rectangle_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,29 @@ void rectangle_button::update_color()
this->set_color(this->params.unpressed_color);
}
}

rectangle_button::rectangle_button( //
utki::shared_ref<ruis::context> context,
ruis::container::parameters container_params,
ruis::frame_widget::parameters frame_params,
parameters params,
utki::span<const utki::shared_ref<ruis::widget>> contents
):
widget(std::move(context), {}, {}),
button(this->context, button::parameters{}),
rectangle(
this->context,
rectangle::all_parameters{}
),
margins(
this->context,
{
.container_params = std::move(container_params), //
.frame_params = std::move(frame_params)
},
contents
),
params(std::move(params))
{
this->update_color();
}
4 changes: 2 additions & 2 deletions src/bedsidemon/rectangle_button.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ class rectangle_button :
{
public:
struct parameters {
constexpr static const auto default_pressed_color = 0xffffffff;
constexpr static const auto default_pressed_color = 0xffaaaaaa;
uint32_t pressed_color = default_pressed_color;

constexpr static const auto default_unpressed_color = 0xff808080;
constexpr static const auto default_unpressed_color = 0xff666666;
uint32_t unpressed_color = default_unpressed_color;

// TODO: add disabled_color ?
Expand Down
27 changes: 27 additions & 0 deletions src/bedsidemon/rectangle_push_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,30 @@ void rectangle_push_button::on_pressed_change()
this->rectangle_button::on_pressed_change();
this->push_button::on_pressed_change();
}

rectangle_push_button::rectangle_push_button(
utki::shared_ref<ruis::context> context, //
all_parameters params,
utki::span<const utki::shared_ref<ruis::widget>> contents
) :
widget( //
std::move(context),
std::move(params.layout_params),
std::move(params.widget_params)
),
button( //
this->context,
std::move(params.button_params)
),
push_button( //
this->context,
button::parameters{}
),
rectangle_button( //
this->context,
std::move(params.container_params),
std::move(params.frame_params),
std::move(params.rectangle_button_params),
contents
)
{}
15 changes: 15 additions & 0 deletions src/bedsidemon/rectangle_push_button.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,19 @@ class rectangle_push_button :
}
};

namespace make {
inline utki::shared_ref<ruis::rectangle_push_button> rectangle_push_button(
utki::shared_ref<ruis::context> context,
ruis::rectangle_push_button::all_parameters params,
utki::span<const utki::shared_ref<ruis::widget>> contents
)
{
return utki::make_shared<ruis::rectangle_push_button>(
std::move(context), //
std::move(params),
contents
);
}
} // namespace make

} // namespace ruis

0 comments on commit 7c519d0

Please sign in to comment.