Skip to content

Commit fac13b4

Browse files
committed
modernize book test app
1 parent 8d4e82a commit fac13b4

File tree

10 files changed

+227
-77
lines changed

10 files changed

+227
-77
lines changed

src/ruis/widget/group/book.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,13 @@ page::page(const utki::shared_ref<ruis::context>& c, const tml::forest& desc) :
191191
widget(c, desc)
192192
{}
193193

194+
page::page(
195+
utki::shared_ref<ruis::context> context, //
196+
ruis::widget::parameters widget_params
197+
) :
198+
widget(std::move(context), {}, std::move(widget_params))
199+
{}
200+
194201
utki::shared_ref<page> page::tear_out()
195202
{
196203
if (!this->get_parent_book()) {

src/ruis/widget/group/book.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ class page : public virtual widget
3535
protected:
3636
page(const utki::shared_ref<ruis::context>& c, const tml::forest& desc);
3737

38+
page(
39+
utki::shared_ref<ruis::context> context, //
40+
ruis::widget::parameters widget_params
41+
);
42+
3843
book* parent_book = nullptr;
3944

4045
public:

tests/book/makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ include prorab-test.mk
33

44
this__is_interactive := true
55

6+
# this_cxxflags += -save-temps
7+
68
include $(d)../common.mk

tests/book/src/cube_page.cpp

Lines changed: 56 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,17 @@
44
#include <ruis/render/renderer.hpp>
55
#include <ruis/widget/button/push_button.hpp>
66
#include <ruis/widget/group/book.hpp>
7+
#include <ruis/widget/label/text.hpp>
8+
#include <ruis/widget/label/gap.hpp>
79

810
#include "cube_page.hpp"
911

12+
using namespace std::string_literals;
13+
14+
namespace m{
15+
using namespace ruis::make;
16+
}
17+
1018
namespace{
1119

1220
class cube_widget : public ruis::widget, public ruis::updateable{
@@ -103,27 +111,57 @@ class cube_widget : public ruis::widget, public ruis::updateable{
103111
}
104112

105113
cube_page::cube_page(utki::shared_ref<ruis::context> c) :
106-
widget(std::move(c), tml::forest()),
107-
page(this->context, tml::forest()),
108-
container(this->context, tml::read(R"qwertyuiop(
109-
layout{pile}
110-
@column{
111-
lp{
112-
dx{fill}dy{fill}
113-
}
114-
@widget{
115-
id{placeholder}
116-
lp{dx{fill}dy{fill}weight{1}}
114+
// clang-format off
115+
widget(
116+
std::move(c),
117+
{
118+
.dims = {ruis::dim::fill, ruis::dim::fill}
119+
},
120+
{}
121+
),
122+
page(
123+
this->context,
124+
ruis::widget::parameters{}
125+
),
126+
container(
127+
this->context,
128+
ruis::container::all_parameters{
129+
.container_params{
130+
.layout = ruis::layout::column
131+
}
132+
},
133+
{
134+
m::gap(this->context,
135+
{
136+
.layout_params{
137+
.dims = {ruis::dim::fill, ruis::dim::fill},
138+
.weight = 1
139+
},
140+
.widget_params{
141+
.id = "placeholder"
142+
}
117143
}
118-
@text{text{"cube page"}}
119-
@push_button{
120-
id{back_button}
121-
@text{
122-
text{back}
144+
),
145+
m::text(this->context,
146+
{},
147+
U"cube page"s
148+
),
149+
m::push_button(this->context,
150+
{
151+
.widget_params{
152+
.id = "back_button"s
123153
}
154+
},
155+
{
156+
m::text(this->context,
157+
{},
158+
U"back"s
159+
)
124160
}
125-
}
126-
)qwertyuiop"))
161+
)
162+
}
163+
)
164+
// clang-format on
127165
{
128166
auto& ph = this->get_widget("placeholder");
129167

tests/book/src/main.cpp

Lines changed: 32 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@
1414
#include "pile_page.hpp"
1515
#include "cube_page.hpp"
1616

17+
#include "main_page.hpp"
18+
19+
using namespace std::string_literals;
20+
21+
namespace m{
22+
using namespace ruis::make;
23+
using namespace ::make;
24+
}
25+
1726
class application : public ruisapp::application{
1827
public:
1928
application() :
@@ -35,62 +44,34 @@ class application : public ruisapp::application{
3544
auto& book = c.get().get_widget_as<ruis::book>("book");
3645

3746
{
38-
auto mp = utki::make_shared<pile_page>(
39-
this->gui.context,
40-
tml::read(R"qwertyuiop(
41-
@column{
42-
lp{dx{fill} dy{fill}}
43-
44-
@push_button{
45-
id{cube_button}
46-
47-
lp{
48-
dx{fill}
49-
}
50-
51-
@text{
52-
text{Cube!}
53-
}
54-
}
55-
56-
@push_button{
57-
id{stuff_button}
58-
59-
lp{
60-
dx{fill}
61-
}
62-
63-
@text{
64-
text{Stuff!}
65-
}
66-
}
67-
68-
@push_button{
69-
id{close_button}
70-
71-
lp{
72-
dx{fill}
73-
}
74-
75-
@text{
76-
text{close}
77-
}
78-
}
79-
}
80-
)qwertyuiop")
81-
);
47+
auto mp = make_main_page(this->gui.context);
48+
8249
mp.get().get_widget_as<ruis::push_button>("cube_button").click_handler = [&mp = mp.get()](ruis::push_button& b){
8350
mp.get_parent_book()->push(utki::make_shared<cube_page>(mp.context));
8451
};
8552
mp.get().get_widget_as<ruis::push_button>("stuff_button").click_handler = [&mp = mp.get()](ruis::push_button& b){
86-
auto pg = utki::make_shared<pile_page>(mp.context, tml::read(R"qwertyuiop(
87-
@push_button{
88-
id{back_button}
89-
@text{
90-
text{"Go back"}
91-
}
53+
// clang-format off
54+
auto pg = make::pile_page(
55+
mp.context,
56+
{},
57+
{
58+
m::push_button(mp.context,
59+
{
60+
.widget_params{
61+
.id = "back_button"s
62+
}
63+
},
64+
{
65+
m::text(mp.context,
66+
{},
67+
U"Go back"s
68+
)
69+
}
70+
)
9271
}
93-
)qwertyuiop"));
72+
);
73+
// clang-format on
74+
9475
pg.get().get_widget_as<ruis::push_button>("back_button").click_handler = [&pg = pg.get()](ruis::push_button& b){
9576
b.context.get().post_to_ui_thread([pg = utki::make_shared_from(pg)]{
9677
pg.get().tear_out();

tests/book/src/main_page.cpp

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

tests/book/src/main_page.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/group/book.hpp>
4+
5+
utki::shared_ref<ruis::page> make_main_page(utki::shared_ref<ruis::context> c);

tests/book/src/pile_page.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,20 @@
22

33
#include <ruis/layout/pile_layout.hpp>
44

5-
pile_page::pile_page(const utki::shared_ref<ruis::context>& c, const tml::forest& desc) :
6-
widget(std::move(c), tml::forest()),
7-
page(this->context, tml::forest()),
8-
container(this->context, desc, ruis::layout::pile)
9-
{}
5+
pile_page::pile_page(
6+
utki::shared_ref<ruis::context> context, //
7+
ruis::widget::parameters widget_params,
8+
utki::span<const utki::shared_ref<ruis::widget>> contents
9+
) :
10+
widget(std::move(context), {}, std::move(widget_params)),
11+
page(this->context, ruis::widget::parameters{}),
12+
container(
13+
this->context,//
14+
{
15+
.container_params{
16+
.layout = ruis::layout::pile
17+
}
18+
},
19+
contents
20+
)
21+
{}

tests/book/src/pile_page.hpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ class pile_page :
77
public ruis::container
88
{
99
public:
10-
pile_page(const utki::shared_ref<ruis::context>& c, const tml::forest& desc);
11-
10+
pile_page( //
11+
utki::shared_ref<ruis::context> context,
12+
ruis::widget::parameters widget_params,
13+
utki::span<const utki::shared_ref<ruis::widget>> contents
14+
);
15+
1216
pile_page(const pile_page&) = delete;
1317
pile_page& operator=(const pile_page&) = delete;
1418

@@ -22,3 +26,18 @@ class pile_page :
2226
private:
2327

2428
};
29+
30+
namespace make{
31+
inline utki::shared_ref<::pile_page> pile_page(
32+
utki::shared_ref<ruis::context> context,
33+
ruis::widget::parameters widget_params,
34+
utki::span<const utki::shared_ref<ruis::widget>> contents = {}
35+
)
36+
{
37+
return utki::make_shared<::pile_page>( //
38+
std::move(context),
39+
std::move(widget_params),
40+
contents
41+
);
42+
}
43+
}

tests/common.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ this_srcs += $(call prorab-src-dir, src)
66

77
$(eval $(call prorab-config, ../../config))
88

9-
this_cxxflags += -isystem ../../src -isystem ../harness/modules/ruisapp/src
9+
this_cxxflags += -isystem ../../src
10+
this_cxxflags += -isystem ../harness/modules/ruisapp/src
1011

1112
this__libruis_dir := ../../src/out/$(c)/
1213
this__libruis := $(this__libruis_dir)libruis$(dot_so)

0 commit comments

Comments
 (0)