Skip to content

Commit 02be9e6

Browse files
committed
modernize busy test app
1 parent 4f116ee commit 02be9e6

File tree

8 files changed

+163
-32
lines changed

8 files changed

+163
-32
lines changed

src/ruis/widget/label/busy.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,30 @@ busy::busy(const utki::shared_ref<ruis::context>& c, const tml::forest& desc) :
2828
spinner(this->context, desc)
2929
{}
3030

31+
busy::busy(
32+
utki::shared_ref<ruis::context> context, //
33+
all_parameters params
34+
) :
35+
widget(
36+
std::move(context), //
37+
std::move(params.layout_params),
38+
std::move(params.widget_params)
39+
),
40+
spinner(
41+
this->context, //
42+
// clang-format off
43+
{
44+
.image_params = std::move(params.image_params),
45+
.blending_params = std::move(params.blending_params)
46+
}
47+
// clang-format on
48+
)
49+
{
50+
if (!this->get_image()) {
51+
this->set_image(this->context.get().loader.load<ruis::res::image>("ruis_img_busy"));
52+
}
53+
}
54+
3155
void busy::set_active(bool active)
3256
{
3357
this->set_visible(active);

src/ruis/widget/label/busy.hpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,32 @@ class busy : public spinner
3434
public:
3535
busy(const utki::shared_ref<ruis::context>& c, const tml::forest& desc);
3636

37+
struct all_parameters {
38+
layout_parameters layout_params;
39+
widget::parameters widget_params;
40+
image::parameters image_params;
41+
blending_widget::parameters blending_params;
42+
};
43+
44+
busy(
45+
utki::shared_ref<ruis::context> context, //
46+
all_parameters params
47+
);
48+
3749
void set_active(bool active);
3850
};
3951

52+
namespace make {
53+
inline utki::shared_ref<ruis::busy> busy(
54+
utki::shared_ref<ruis::context> context, //
55+
ruis::busy::all_parameters params
56+
)
57+
{
58+
return utki::make_shared<ruis::busy>(
59+
std::move(context), //
60+
std::move(params)
61+
);
62+
}
63+
} // namespace make
64+
4065
} // namespace ruis

src/ruis/widget/label/spinner.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2525

2626
#include <utki/math.hpp>
2727

28+
using namespace std::string_view_literals;
29+
2830
using namespace ruis;
2931

3032
spinner::spinner(const utki::shared_ref<ruis::context>& c, const tml::forest& desc) :
@@ -72,3 +74,21 @@ void spinner::update(uint32_t dt_ms)
7274
{
7375
angle += real(utki::pi) / real(std::milli::den) * real(dt_ms);
7476
}
77+
78+
utki::shared_ref<ruis::spinner> ruis::make::refresh(
79+
utki::shared_ref<ruis::context> context, //
80+
spinner::all_parameters params
81+
)
82+
{
83+
if (!params.image_params.img) {
84+
params.image_params.img = context.get().loader.load<res::image>("ruis_img_refresh"sv);
85+
}
86+
if (!params.image_params.disabled_img) {
87+
params.image_params.disabled_img = context.get().loader.load<res::image>("ruis_img_refresh_disabled"sv);
88+
}
89+
90+
return utki::make_shared<ruis::spinner>(
91+
std::move(context), //
92+
std::move(params)
93+
);
94+
}

src/ruis/widget/label/spinner.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ inline utki::shared_ref<ruis::spinner> spinner(
6767
return utki::make_shared<ruis::spinner>(std::move(context), std::move(params));
6868
}
6969

70+
utki::shared_ref<ruis::spinner> refresh(
71+
utki::shared_ref<ruis::context> context, //
72+
spinner::all_parameters params
73+
);
74+
7075
} // namespace make
7176

7277
} // namespace ruis

tests/busy/res/test.gui

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

tests/busy/src/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <ruis/widget/button/push_button.hpp>
88
#include <ruis/widget/label/busy.hpp>
99

10+
#include "root_gui.hpp"
11+
1012
class application : public ruisapp::application{
1113
public:
1214
application() :
@@ -18,9 +20,7 @@ class application : public ruisapp::application{
1820
{
1921
this->gui.init_standard_widgets(*this->get_res_file("../../res/ruis_res/"));
2022

21-
auto c = this->gui.context.get().inflater.inflate(
22-
*this->get_res_file("res/test.gui")
23-
);
23+
auto c = make_root_gui(this->gui.context);
2424
this->gui.set_root(c);
2525

2626
{

tests/busy/src/root_gui.cpp

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#include "root_gui.hpp"
2+
3+
#include <ruis/widget/label/busy.hpp>
4+
#include <ruis/widget/button/push_button.hpp>
5+
#include <ruis/widget/label/text.hpp>
6+
7+
using namespace std::string_literals;
8+
using namespace std::string_view_literals;
9+
10+
namespace m{
11+
using namespace ruis::make;
12+
}
13+
14+
utki::shared_ref<ruis::widget> make_root_gui(utki::shared_ref<ruis::context> c){
15+
// clang-format off
16+
return m::pile(c,
17+
{},
18+
{
19+
m::column(c,
20+
{},
21+
{
22+
m::busy(c,
23+
{
24+
.widget_params{
25+
.id = "busy_spinner"s,
26+
.visible = false
27+
}
28+
}
29+
),
30+
m::push_button(c,
31+
{
32+
.widget_params{
33+
.id = "busy_toggle_button"s
34+
}
35+
},
36+
{
37+
m::text(c,
38+
{},
39+
U"toggle busy spinner"s
40+
)
41+
}
42+
),
43+
m::busy(c,
44+
{
45+
.widget_params{
46+
.id = "busy_spinner2"s
47+
}
48+
}
49+
),
50+
m::push_button(c,
51+
{
52+
.widget_params{
53+
.id = "refresh_toggle_button"s
54+
}
55+
},
56+
{
57+
m::refresh(c,
58+
{
59+
.widget_params{
60+
.id = "refresh_spinner"s
61+
}
62+
}
63+
)
64+
}
65+
),
66+
m::push_button(c,
67+
{
68+
.widget_params{
69+
.id = "refresh_disable_button"s
70+
}
71+
},
72+
{
73+
m::refresh(c, {})
74+
}
75+
)
76+
}
77+
)
78+
}
79+
);
80+
// clang-format on
81+
}

tests/busy/src/root_gui.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#pragma once
2+
3+
#include <ruis/widget/widget.hpp>
4+
5+
utki::shared_ref<ruis::widget> make_root_gui(utki::shared_ref<ruis::context> c);

0 commit comments

Comments
 (0)