Skip to content

Commit 5365ebd

Browse files
committed
add touch::tab_button
1 parent 138ab62 commit 5365ebd

3 files changed

Lines changed: 134 additions & 87 deletions

File tree

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#include "tab_button.hpp"
2+
3+
#include "../../label/padding.hpp"
4+
5+
using namespace ruis::touch;
6+
7+
using namespace ruis::length_literals;
8+
9+
tab_button::tab_button(
10+
utki::shared_ref<ruis::context> context, //
11+
all_parameters params,
12+
ruis::string text
13+
) :
14+
widget(
15+
std::move(context), //
16+
std::move(params.layout_params),
17+
std::move(params.widget_params)
18+
),
19+
button(
20+
this->context,
21+
{
22+
}
23+
),
24+
toggle_button(this->context),
25+
choice_button(this->context),
26+
// clang-format off
27+
ruis::container(
28+
this->context, //
29+
{
30+
.container_params = {
31+
.layout = ruis::layout::pile
32+
}
33+
},
34+
{
35+
ruis::make::padding(
36+
this->context,
37+
{
38+
.layout_params = {
39+
.dims = {ruis::dim::fill, ruis::dim::fill}
40+
},
41+
.container_params = {
42+
.layout = ruis::layout::column
43+
},
44+
.padding_params = {
45+
.borders = {10_pp}
46+
}
47+
},
48+
{
49+
ruis::make::image(this->context,
50+
{
51+
.layout_params = {
52+
.dims = {ruis::dim::min, ruis::dim::fill},
53+
.weight = 1
54+
},
55+
.image_params = std::move(params.image_params)
56+
}
57+
),
58+
ruis::make::text(this->context,
59+
{
60+
.layout_params = {
61+
.dims = {ruis::dim::min, ruis::dim::min},
62+
.align = {ruis::align::center, ruis::align::center}
63+
}
64+
},
65+
std::move(text)
66+
)
67+
}
68+
)
69+
}
70+
)
71+
// clang-format on
72+
{}
73+
74+
ruis::event_status tab_button::on_mouse_button(const ruis::mouse_button_event& event)
75+
{
76+
return this->choice_button::on_mouse_button(event);
77+
}
78+
79+
utki::shared_ref<ruis::touch::tab_button> ruis::touch::make::tab_button(
80+
utki::shared_ref<ruis::context> context, //
81+
ruis::touch::tab_button::all_parameters params,
82+
ruis::string text
83+
)
84+
{
85+
return utki::make_shared<ruis::touch::tab_button>(
86+
std::move(context),
87+
std::move(params),
88+
std::move(text)
89+
);
90+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#pragma once
2+
3+
#include "../choice_button.hpp"
4+
#include "../../label/image.hpp"
5+
#include "../../label/text.hpp"
6+
7+
namespace ruis::touch{
8+
9+
class tab_button :
10+
public ruis::choice_button, //
11+
private ruis::container
12+
{
13+
public:
14+
struct all_parameters {
15+
ruis::layout::parameters layout_params;
16+
ruis::widget::parameters widget_params;
17+
ruis::image::parameters image_params;
18+
ruis::text_widget::parameters text_params;
19+
};
20+
21+
tab_button(
22+
utki::shared_ref<ruis::context> context, //
23+
all_parameters params,
24+
ruis::string text
25+
);
26+
27+
ruis::event_status on_mouse_button(const ruis::mouse_button_event& event) override;
28+
};
29+
30+
namespace make{
31+
utki::shared_ref<ruis::touch::tab_button> tab_button(
32+
utki::shared_ref<ruis::context> context, //
33+
ruis::touch::tab_button::all_parameters params,
34+
ruis::string text
35+
);
36+
}
37+
38+
}

tests/touch/src/gui.cpp

Lines changed: 6 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2727
#include <ruis/widget/label/image.hpp>
2828
#include <ruis/widget/label/padding.hpp>
2929
#include <ruis/widget/label/text.hpp>
30+
#include <ruis/widget/button/touch/tab_button.hpp>
3031

3132
#include "list_page.hpp"
3233
#include "scroll_area_page.hpp"
@@ -39,97 +40,15 @@ using namespace ruis::length_literals;
3940

4041
namespace {
4142

42-
class tab_button :
43-
public ruis::choice_button, //
44-
private ruis::container
45-
{
46-
public:
47-
struct all_parameters {
48-
ruis::layout::parameters layout_params;
49-
ruis::widget::parameters widget_params;
50-
ruis::image::parameters image_params;
51-
ruis::string text;
52-
};
53-
54-
tab_button(
55-
utki::shared_ref<ruis::context> context, //
56-
all_parameters params
57-
) :
58-
widget(
59-
std::move(context), //
60-
std::move(params.layout_params),
61-
std::move(params.widget_params)
62-
),
63-
button(
64-
this->context,
65-
{
66-
}
67-
),
68-
toggle_button(this->context),
69-
choice_button(this->context),
70-
// clang-format off
71-
ruis::container(
72-
this->context, //
73-
{
74-
.container_params = {
75-
.layout = ruis::layout::pile
76-
}
77-
},
78-
{
79-
m::padding(
80-
this->context,
81-
{
82-
.layout_params = {
83-
.dims = {ruis::dim::fill, ruis::dim::fill}
84-
},
85-
.container_params = {
86-
.layout = ruis::layout::column
87-
},
88-
.padding_params = {
89-
.borders = {10_pp}
90-
}
91-
},
92-
{
93-
m::image(this->context,
94-
{
95-
.layout_params = {
96-
.dims = {ruis::dim::min, ruis::dim::fill},
97-
.weight = 1
98-
},
99-
.image_params = std::move(params.image_params)
100-
}
101-
),
102-
m::text(this->context,
103-
{
104-
.layout_params = {
105-
.dims = {ruis::dim::min, ruis::dim::min},
106-
.align = {ruis::align::center, ruis::align::center}
107-
}
108-
},
109-
std::move(params.text)
110-
)
111-
}
112-
)
113-
}
114-
)
115-
// clang-format on
116-
{}
117-
118-
ruis::event_status on_mouse_button(const ruis::mouse_button_event& event) override
119-
{
120-
return this->choice_button::on_mouse_button(event);
121-
}
122-
};
123-
124-
utki::shared_ref<ruis::choice_button> make_tab_button(
43+
utki::shared_ref<ruis::touch::tab_button> make_tab_button(
12544
utki::shared_ref<ruis::context> c, //
12645
utki::shared_ref<const ruis::res::image> icon,
12746
ruis::string text
12847
)
12948
{
13049
// clang-format off
131-
return utki::make_shared<tab_button>(std::move(c),
132-
tab_button::all_parameters{
50+
return ruis::touch::make::tab_button(std::move(c),
51+
ruis::touch::tab_button::all_parameters{
13352
.layout_params = {
13453
.dims = {ruis::dim::fill, 60_pp},
13554
.weight = 1
@@ -138,8 +57,8 @@ utki::shared_ref<ruis::choice_button> make_tab_button(
13857
.img = std::move(icon),
13958
.keep_aspect_ratio = true
14059
},
141-
.text = std::move(text)
142-
}
60+
},
61+
std::move(text)
14362
);
14463
// clang-format on
14564
}

0 commit comments

Comments
 (0)