Skip to content

Commit 042d00a

Browse files
committed
moderinze paint test app
1 parent 02be9e6 commit 042d00a

File tree

2 files changed

+140
-57
lines changed

2 files changed

+140
-57
lines changed

src/ruis/widget/label/margins.hpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,17 @@ class margins : public frame_widget
5050
};
5151

5252
namespace make {
53-
inline utki::shared_ref<margins> margins(
54-
utki::shared_ref<context> context,
53+
inline utki::shared_ref<ruis::margins> margins(
54+
utki::shared_ref<context> context, //
5555
margins::all_parameters params,
5656
utki::span<const utki::shared_ref<ruis::widget>> children
5757
)
5858
{
59-
return utki::make_shared<ruis::margins>(std::move(context), std::move(params), children);
59+
return utki::make_shared<ruis::margins>(
60+
std::move(context), //
61+
std::move(params),
62+
children
63+
);
6064
}
6165
} // namespace make
6266

tests/paint/src/main.cpp

Lines changed: 133 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,27 @@
55
#include <ruis/widget/widget.hpp>
66
#include <ruis/paint/path_vao.hpp>
77
#include <ruis/paint/frame_vao.hpp>
8+
#include <ruis/widget/label/margins.hpp>
9+
#include <ruis/widget/slider/scroll_bar.hpp>
10+
#include <ruis/widget/button/push_button.hpp>
11+
#include <ruis/widget/label/text.hpp>
12+
13+
using namespace std::string_literals;
814

915
class path_widget : virtual public ruis::widget{
1016
ruis::path_vao vao;
1117
public:
12-
path_widget(const utki::shared_ref<ruis::context>& c, const tml::forest& desc) :
13-
ruis::widget(c, desc),
14-
vao(this->context.get().renderer)
18+
struct all_parameters{
19+
ruis::layout_parameters layout_params;
20+
ruis::widget::parameters widget_params;
21+
};
22+
23+
path_widget(
24+
utki::shared_ref<ruis::context> context, //
25+
all_parameters params
26+
) :
27+
widget(std::move(context), std::move(params.layout_params), std::move(params.widget_params)),
28+
vao(this->context.get().renderer)
1529
{}
1630

1731
void render(const ruis::matrix4& matrix)const override{
@@ -30,12 +44,33 @@ class path_widget : virtual public ruis::widget{
3044
}
3145
};
3246

47+
namespace make{
48+
inline utki::shared_ref<::path_widget> path_widget(
49+
utki::shared_ref<ruis::context> context,
50+
::path_widget::all_parameters params
51+
)
52+
{
53+
return utki::make_shared<::path_widget>(
54+
std::move(context),
55+
std::move(params)
56+
);
57+
}
58+
}
59+
3360
class frame_widget : virtual public ruis::widget{
3461
ruis::frame_vao vao;
3562
public:
36-
frame_widget(const utki::shared_ref<ruis::context>& c, const tml::forest& desc) :
37-
ruis::widget(c, desc),
38-
vao(this->context.get().renderer)
63+
struct all_parameters{
64+
ruis::layout_parameters layout_params;
65+
ruis::widget::parameters widget_params;
66+
};
67+
68+
frame_widget(
69+
utki::shared_ref<ruis::context> context, //
70+
all_parameters params
71+
) :
72+
widget(std::move(context), std::move(params.layout_params), std::move(params.widget_params)),
73+
vao(this->context.get().renderer)
3974
{}
4075

4176
void render(const ruis::matrix4& matrix)const override{
@@ -50,6 +85,97 @@ class frame_widget : virtual public ruis::widget{
5085
}
5186
};
5287

88+
namespace make{
89+
inline utki::shared_ref<::frame_widget> frame_widget(
90+
utki::shared_ref<ruis::context> context,
91+
::frame_widget::all_parameters params
92+
)
93+
{
94+
return utki::make_shared<::frame_widget>(
95+
std::move(context),
96+
std::move(params)
97+
);
98+
}
99+
}
100+
101+
namespace m{
102+
using namespace ruis::make;
103+
using namespace ::make;
104+
}
105+
106+
utki::shared_ref<ruis::widget> make_root_widget(utki::shared_ref<ruis::context> c){
107+
// clang-format off
108+
return m::pile(c,
109+
{},
110+
{
111+
m::path_widget(c,
112+
{
113+
.layout_params{
114+
.dims = {ruis::dim::fill, ruis::dim::fill}
115+
}
116+
}
117+
),
118+
m::margins(c,
119+
{
120+
.layout_params{
121+
.dims = {ruis::dim::fill, ruis::dim::fill}
122+
},
123+
.container_params{
124+
.layout = ruis::layout::pile
125+
},
126+
.frame_params{
127+
.borders = {
128+
ruis::length::make_pp(5),
129+
ruis::length::make_pp(5),
130+
ruis::length::make_pp(5),
131+
ruis::length::make_pp(5)
132+
}
133+
}
134+
},
135+
{
136+
m::frame_widget(c,
137+
{
138+
.layout_params{
139+
.dims = {ruis::dim::fill, ruis::dim::fill}
140+
}
141+
}
142+
)
143+
}
144+
),
145+
m::scroll_bar(c,
146+
{
147+
.layout_params{
148+
.dims = {ruis::dim::min, ruis::dim::max}
149+
},
150+
.oriented_params{
151+
.vertical = true
152+
}
153+
}
154+
),
155+
m::scroll_bar(c,
156+
{
157+
.layout_params{
158+
.dims = {ruis::dim::max, ruis::dim::min}
159+
},
160+
.oriented_params{
161+
.vertical = false
162+
}
163+
}
164+
),
165+
m::push_button(c,
166+
{},
167+
{
168+
m::text(c,
169+
{},
170+
U"stuff"s
171+
)
172+
}
173+
)
174+
}
175+
);
176+
// clang-format on
177+
}
178+
53179
class application : public ruisapp::application{
54180
public:
55181
application() :
@@ -63,54 +189,7 @@ class application : public ruisapp::application{
63189
{
64190
this->gui.init_standard_widgets(*this->get_res_file("../../res/ruis_res/"));
65191

66-
this->gui.context.get().inflater.register_widget<path_widget>("path_widget");
67-
this->gui.context.get().inflater.register_widget<frame_widget>("frame_widget");
68-
69-
// this->gui.set_root(std::make_shared<path_widget>(this->gui.context, tml::forest()));
70-
71-
this->gui.set_root(
72-
this->gui.context.get().inflater.inflate(tml::read(R"(
73-
@pile{
74-
@path_widget{
75-
lp{
76-
dx{fill} dy{fill}
77-
}
78-
}
79-
80-
@margins{
81-
left{5dp}
82-
right{5dp}
83-
top{5dp}
84-
bottom{5dp}
85-
86-
lp{
87-
dx{fill} dy{fill}
88-
}
89-
90-
@frame_widget{
91-
lp{
92-
dx{fill} dy{fill}
93-
}
94-
}
95-
}
96-
97-
@vertical_scroll_bar{
98-
lp{
99-
dx{min} dy{max}
100-
}
101-
}
102-
@horizontal_scroll_bar{
103-
lp{
104-
dx{max} dy{min}
105-
}
106-
}
107-
@push_button{
108-
@text{
109-
text{stuff}
110-
}
111-
}
112-
}
113-
)")));
192+
this->gui.set_root(make_root_widget(this->gui.context));
114193
}
115194
};
116195

0 commit comments

Comments
 (0)