Skip to content

Commit

Permalink
stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
igagis committed Sep 1, 2024
1 parent aea0e3a commit d080540
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 3 deletions.
13 changes: 12 additions & 1 deletion src/ruis/widget/button/base/selection_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ class static_provider : public selection_box::provider
};
} // namespace

selection_box::selection_box(
utki::shared_ref<ruis::context> context,
container& selection_container,
parameters params
) :
widget(std::move(context), {}, {}),
selection_container(selection_container)
{
this->set_provider(params.provider);
}

selection_box::selection_box(
const utki::shared_ref<ruis::context>& c,
const tml::forest& desc,
Expand All @@ -79,7 +90,7 @@ selection_box::selection_box(
void selection_box::set_provider(std::shared_ptr<provider> item_provider)
{
if (item_provider && item_provider->dd) {
throw std::logic_error(
throw std::invalid_argument(
"selection_box::setItemsProvider(): given provider is already set to some selection_box"
);
}
Expand Down
7 changes: 7 additions & 0 deletions src/ruis/widget/button/base/selection_box.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,15 @@ class selection_box : virtual public widget

/**
* @brief Notify about change of items model.
* The user is supposed to invoke this function when items model change.
*/
void notify_data_set_changed();
};

struct parameters {
std::shared_ptr<selection_box::provider> provider;
};

private:
std::shared_ptr<provider> item_provider;

Expand All @@ -105,6 +110,8 @@ class selection_box : virtual public widget
protected:
selection_box(const utki::shared_ref<ruis::context>& c, const tml::forest& desc, container& selection_container);

selection_box(utki::shared_ref<ruis::context> context, container& selection_container, parameters params);

public:
selection_box(const selection_box&) = delete;
selection_box& operator=(const selection_box&) = delete;
Expand Down
60 changes: 58 additions & 2 deletions src/ruis/widget/button/drop_down_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "../label/color.hpp"
#include "../proxy/mouse_proxy.hpp"

using namespace std::string_view_literals;

using namespace ruis;

namespace {
Expand Down Expand Up @@ -124,6 +126,42 @@ drop_down_box::drop_down_box(const utki::shared_ref<ruis::context>& c, const tml
};
}

namespace {
std::vector<utki::shared_ref<widget>> make_drop_down_box_widget_structure(utki::shared_ref<ruis::context> c)
{
// clang-format off
return {
// TODO:
};
// clang-format on
}
} // namespace

drop_down_box::drop_down_box(utki::shared_ref<ruis::context> context, all_parameters params) :
widget(std::move(context), std::move(params.layout_params), std::move(params.widget_params)),
button(this->context, button::parameters{}),
nine_patch_push_button(
this->context, //
{
.nine_patch_button_params = std::move(params.nine_patch_button_params) //
},
make_drop_down_box_widget_structure(this->context)
),
selection_box(
this->context, //
this->get_widget_as<ruis::container>("ruis_dropdown_selection"),
std::move(params.selection_params)
)
{
this->pressed_change_handler = [this](button& b) {
if (!b.is_pressed()) {
return;
}

this->show_drop_down_menu();
};
}

bool drop_down_box::on_mouse_button(const mouse_button_event& e)
{
if (e.is_down) {
Expand Down Expand Up @@ -203,8 +241,7 @@ void drop_down_box::show_drop_down_menu()
};

this->current_drop_down_menu =
olay->show_popup(np, this->pos_in_ancestor(vector2(0), olay) + vector2(0, this->rect().d.y()))
.to_shared_ptr();
olay->show_popup(np, this->pos_in_ancestor(vector2(0), olay) + vector2(0, this->rect().d.y())).to_shared_ptr();
}

void drop_down_box::handle_mouse_button_up(bool is_first_button_up_event)
Expand Down Expand Up @@ -266,3 +303,22 @@ utki::shared_ref<widget> drop_down_box::wrap_item(const utki::shared_ref<widget>

return wd;
}

utki::shared_ref<ruis::drop_down_box> ruis::make::drop_down_box(
utki::shared_ref<ruis::context> context, //
drop_down_box::all_parameters params
)
{
if(!params.nine_patch_button_params.unpressed_nine_patch){
params.nine_patch_button_params.unpressed_nine_patch = context.get().loader.load<res::nine_patch>("ruis_npt_button_normal"sv);
}

if(!params.nine_patch_button_params.pressed_nine_patch){
params.nine_patch_button_params.pressed_nine_patch = context.get().loader.load<res::nine_patch>("ruis_npt_button_pressed"sv);
}

return utki::make_shared<ruis::drop_down_box>(
std::move(context), //
std::move(params)
);
}
16 changes: 16 additions & 0 deletions src/ruis/widget/button/drop_down_box.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ class drop_down_box :
unsigned num_mouse_buttons_pressed = 0;

public:
struct all_parameters {
ruis::layout_parameters layout_params;
ruis::widget::parameters widget_params;
nine_patch_button::parameters nine_patch_button_params;
selection_box::parameters selection_params;
};

drop_down_box(utki::shared_ref<ruis::context> context, all_parameters params);

drop_down_box(const utki::shared_ref<ruis::context>& c, const tml::forest& desc);

drop_down_box(const drop_down_box&) = delete;
Expand All @@ -61,4 +70,11 @@ class drop_down_box :
void handle_mouse_button_up(bool is_first_button_up_event);
};

namespace make {
utki::shared_ref<ruis::drop_down_box> drop_down_box(
utki::shared_ref<ruis::context> context, //
drop_down_box::all_parameters params
);
} // namespace make

} // namespace ruis

0 comments on commit d080540

Please sign in to comment.