Skip to content

Commit 4f116ee

Browse files
committed
modernize book test app 2
1 parent fac13b4 commit 4f116ee

File tree

6 files changed

+41
-21
lines changed

6 files changed

+41
-21
lines changed

src/ruis/gui.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,13 +349,13 @@ void gui::set_viewport(const ruis::vector2& size)
349349
this->root_widget.get().resize(this->viewport_size);
350350
}
351351

352-
void gui::set_root(const utki::shared_ref<ruis::widget>& w)
352+
void gui::set_root(utki::shared_ref<ruis::widget> w)
353353
{
354354
if (w.get().parent()) {
355355
throw std::invalid_argument("given widget is already added to some container");
356356
}
357357

358-
this->root_widget = w;
358+
this->root_widget = std::move(w);
359359

360360
this->root_widget.get().move_to(ruis::vector2(0));
361361
this->root_widget.get().resize(this->viewport_size);

src/ruis/gui.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class gui final
5656
* @brief Set the root widget of the application.
5757
* @param w - the widget to set as a root widget.
5858
*/
59-
void set_root(const utki::shared_ref<ruis::widget>& w);
59+
void set_root(utki::shared_ref<ruis::widget> w);
6060

6161
/**
6262
* @brief Get current root widget.

src/ruis/widget/group/book.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2828

2929
using namespace ruis;
3030

31-
book::book(utki::shared_ref<ruis::context> context, all_parameters params) :
31+
book::book(utki::shared_ref<ruis::context> context, //
32+
all_parameters params) :
3233
widget( //
3334
std::move(context),
3435
std::move(params.layout_params),
3536
std::move(params.widget_params)
3637
),
37-
container(this->context, {.container_params = {.layout = layout::pile}}, {})
38+
container(
39+
this->context,
40+
{.container_params = {.layout = layout::pile}},
41+
{}
42+
)
3843
{}
3944

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

src/ruis/widget/group/book.hpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ class book :
9191
widget::parameters widget_params;
9292
};
9393

94-
book(utki::shared_ref<ruis::context> context, all_parameters params);
94+
book(
95+
utki::shared_ref<ruis::context> context, //
96+
all_parameters params
97+
);
9598

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

@@ -132,9 +135,15 @@ class book :
132135
};
133136

134137
namespace make {
135-
inline utki::shared_ref<ruis::book> book(utki::shared_ref<ruis::context> context, ruis::book::all_parameters params)
138+
inline utki::shared_ref<ruis::book> book(
139+
utki::shared_ref<ruis::context> context, //
140+
ruis::book::all_parameters params
141+
)
136142
{
137-
return utki::make_shared<ruis::book>(std::move(context), std::move(params));
143+
return utki::make_shared<ruis::book>(
144+
std::move(context), //
145+
std::move(params)
146+
);
138147
}
139148
} // namespace make
140149

tests/book/res/test.gui

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/book/src/main.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,25 @@ class application : public ruisapp::application{
3636

3737
this->gui.context.get().loader.mount_res_pack(*this->get_res_file("res/"));
3838

39-
auto c = this->gui.context.get().inflater.inflate(
40-
*this->get_res_file("res/test.gui")
41-
);
39+
// clang-format off
40+
auto c = m::column(this->gui.context,
41+
{},
42+
{
43+
m::book(this->gui.context,
44+
{
45+
.layout_params{
46+
.dims = {ruis::dim::fill, ruis::dim::max},
47+
.weight = 1
48+
},
49+
.widget_params{
50+
.id = "book"s
51+
}
52+
}
53+
)
54+
}
55+
);
56+
// clang-format on
57+
4258
this->gui.set_root(c);
4359

4460
auto& book = c.get().get_widget_as<ruis::book>("book");

0 commit comments

Comments
 (0)