Skip to content

Commit

Permalink
add language setting to menu
Browse files Browse the repository at this point in the history
  • Loading branch information
igagis committed Oct 6, 2024
1 parent e75a663 commit 6b308c3
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 1 deletion.
109 changes: 108 additions & 1 deletion src/bedsidemon/settings_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,90 @@ class sweep_speed_selection_box_provider : public ruis::selection_box::provider
};
} // namespace

namespace{
class language_selection_box_provider : public ruis::selection_box::provider
{
public:
language_selection_box_provider() = default;

size_t count() const noexcept override
{
return settings::language_id_to_name_mapping.size();
}

utki::shared_ref<ruis::widget> get_widget(size_t index) override
{
const auto& lang_mapping = settings::language_id_to_name_mapping;

ASSERT(index < lang_mapping.size())

auto lang_name = utki::next(lang_mapping.begin(), index)->second;

auto& c = this->get_selection_box()->context;

// clang-format off
return m::margins(c,
{
.container_params = {
.layout = ruis::layout::pile
},
.frame_params = {
.borders = {10_pp} // NOLINT(cppcoreguidelines-avoid-magic-numbers, "TODO: fix")
}
},
{
m::text(c,
{
.text_params{
.font_size = style::font_size_setting
}
},
std::u32string(lang_name)
)
}
);
// clang-format on
}
};
}

namespace {
std::vector<utki::shared_ref<ruis::widget>> make_menu_contents(utki::shared_ref<ruis::context> c)
{
// clang-format off
auto language_selection_box = m::selection_box(c,
{
.layout_params = {
.dims = {200_pp, ruis::dim::min}, // NOLINT(cppcoreguidelines-avoid-magic-numbers, "TODO: fix")
.align = {ruis::align::front, ruis::align::center}
},
.selection_params = {
.provider = std::make_shared<language_selection_box_provider>()
}
}
);
// clang-format on

{
constexpr const auto& lang_mapping = settings::language_id_to_name_mapping;

language_selection_box.get().selection_handler = [](ruis::selection_box& sb) {
auto& ss = settings_storage::inst();
auto s = ss.get();

ASSERT(sb.get_selection() < lang_mapping.size())
s.cur_language_index = sb.get_selection();

ss.set(s);
};

auto& ss = settings_storage::inst();
const auto& s = ss.get();
ASSERT(s.cur_language_index < lang_mapping.size())

language_selection_box.get().set_selection(s.cur_language_index);
}

// clang-format off
return {
m::text(c,
Expand Down Expand Up @@ -131,7 +212,33 @@ std::vector<utki::shared_ref<ruis::widget>> make_menu_contents(utki::shared_ref<
.provider = std::make_shared<sweep_speed_selection_box_provider>()
}
}
)
),
m::gap(c,
{
.layout_params = {
.dims{0_px, style::gap_size_between_settings}
}
}
),
m::text(c,
{
.layout_params = {
.align = {ruis::align::front, ruis::align::center}
},
.text_params = {
.font_size = style::font_size_setting
}
},
U"Language:"s
),
m::gap(c,
{
.layout_params = {
.dims{0_px, style::gap_size_setting_label_value}
}
}
),
std::move(language_selection_box)
};
// clang-format on
}
Expand Down
1 change: 1 addition & 0 deletions src/bedsidemon/style.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ constexpr auto font_size_menu_title = ruis::length::make_pp(26);

constexpr auto font_size_setting = ruis::length::make_pp(14);
constexpr auto gap_size_setting_label_value = ruis::length::make_pp(5);
constexpr auto gap_size_between_settings = ruis::length::make_pp(20);

} // namespace bedsidemon::style

Expand Down

0 comments on commit 6b308c3

Please sign in to comment.