Skip to content

Commit d07b4a7

Browse files
committed
modernize tab
1 parent 250e0ac commit d07b4a7

File tree

10 files changed

+104
-5
lines changed

10 files changed

+104
-5
lines changed

src/ruis/widget/button/choice_button.cpp

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

2626
using namespace ruis;
2727

28+
choice_button::choice_button(utki::shared_ref<ruis::context> context) :
29+
widget(std::move(context), {}, {}),
30+
button(this->context, ruis::button::parameters{}),
31+
toggle_button(this->context)
32+
{}
33+
2834
choice_button::choice_button(const utki::shared_ref<ruis::context>& c, const tml::forest& desc) :
2935
widget(c, desc),
3036
button(this->context, desc),

src/ruis/widget/button/choice_button.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ class choice_button : virtual public toggle_button
4444

4545
choice_button(const utki::shared_ref<ruis::context>& c, const tml::forest& desc);
4646

47+
choice_button(utki::shared_ref<ruis::context> context);
48+
4749
public:
4850
choice_button(const choice_button&) = delete;
4951
choice_button& operator=(const choice_button&) = delete;

src/ruis/widget/button/impl/nine_patch_toggle.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,32 @@ void nine_patch_toggle::on_pressed_change()
2929
this->toggle_button::on_pressed_change();
3030
}
3131

32+
nine_patch_toggle::nine_patch_toggle(
33+
utki::shared_ref<ruis::context> context, //
34+
container::parameters container_params,
35+
button::parameters button_params,
36+
blending_widget::parameters blending_params,
37+
nine_patch::parameters nine_patch_params,
38+
nine_patch_button::parameters nine_patch_button_params,
39+
utki::span<const utki::shared_ref<ruis::widget>> children
40+
) :
41+
widget(std::move(context), {}, {}),
42+
button(
43+
this->context, //
44+
std::move(button_params)
45+
),
46+
toggle_button(this->context),
47+
nine_patch_button(
48+
this->context, //
49+
std::move(container_params),
50+
button::parameters{},
51+
std::move(blending_params),
52+
std::move(nine_patch_params),
53+
std::move(nine_patch_button_params),
54+
children
55+
)
56+
{}
57+
3258
nine_patch_toggle::nine_patch_toggle(const utki::shared_ref<ruis::context>& c, const tml::forest& desc) :
3359
widget(c, desc),
3460
button(this->context, desc),

src/ruis/widget/button/impl/nine_patch_toggle.hpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,17 @@ class nine_patch_toggle :
3030
virtual public toggle_button, //
3131
public nine_patch_button
3232
{
33-
public:
33+
protected:
34+
nine_patch_toggle(//
35+
utki::shared_ref<ruis::context> context,
36+
container::parameters container_params,
37+
button::parameters button_params,
38+
blending_widget::parameters blending_params,
39+
nine_patch::parameters nine_patch_params,
40+
nine_patch_button::parameters nine_patch_button_params,
41+
utki::span<const utki::shared_ref<ruis::widget>> children
42+
);
43+
3444
nine_patch_toggle(const utki::shared_ref<ruis::context>& c, const tml::forest& desc);
3545

3646
protected:

src/ruis/widget/button/tab.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,44 @@ void tab::on_pressed_change()
8585
this->nine_patch_toggle::on_pressed_change();
8686
}
8787

88+
tab::tab(
89+
utki::shared_ref<ruis::context> context, //
90+
all_parameters params,
91+
utki::span<const utki::shared_ref<ruis::widget>> children
92+
) :
93+
widget(
94+
std::move(context), //
95+
std::move(params.layout_params),
96+
std::move(params.widget_params)
97+
),
98+
button(this->context, ruis::button::parameters{}),
99+
toggle_button(this->context),
100+
choice_button(this->context),
101+
nine_patch_toggle(
102+
this->context,
103+
std::move(params.container_params),
104+
std::move(params.button_params),
105+
std::move(params.blending_params),
106+
std::move(params.nine_patch_params),
107+
std::move(params.nine_patch_button_params),
108+
children
109+
)
110+
{
111+
if (!this->get_pressed_nine_patch()) {
112+
this->set_pressed_nine_patch(
113+
this->context.get().loader.load<res::nine_patch>("ruis_npt_tab_active").to_shared_ptr()
114+
);
115+
}
116+
if (!this->get_unpressed_nine_patch()) {
117+
this->set_unpressed_nine_patch(
118+
this->context.get().loader.load<res::nine_patch>("ruis_npt_tab_inactive").to_shared_ptr()
119+
);
120+
}
121+
122+
// initialize nine-patch
123+
this->tab::on_pressed_change();
124+
}
125+
88126
tab::tab(const utki::shared_ref<ruis::context>& c, const tml::forest& desc) :
89127
widget(c, desc),
90128
button(this->context, desc),

src/ruis/widget/button/tab.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,22 @@ class tab :
3838
public:
3939
tab(const utki::shared_ref<ruis::context>& c, const tml::forest& desc);
4040

41+
struct all_parameters {
42+
ruis::layout_parameters layout_params;
43+
ruis::widget::parameters widget_params;
44+
container::parameters container_params;
45+
button::parameters button_params;
46+
blending_widget::parameters blending_params;
47+
nine_patch::parameters nine_patch_params;
48+
nine_patch_button::parameters nine_patch_button_params;
49+
};
50+
51+
tab( //
52+
utki::shared_ref<ruis::context> context,
53+
all_parameters params,
54+
utki::span<const utki::shared_ref<ruis::widget>> children
55+
);
56+
4157
tab(const tab&) = delete;
4258
tab& operator=(const tab&) = delete;
4359

src/ruis/widget/container.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ class container : virtual public widget
254254
*/
255255
widget_list::const_reverse_iterator erase(widget_list::const_reverse_iterator child)
256256
{
257-
return widget_list::const_reverse_iterator(this->erase(--child.base())
257+
return widget_list::const_reverse_iterator(
258+
this->erase(--child.base())
258259
); // the base iterator points to the next element to the one the reverse iterator points, so use decrement
259260
}
260261

0 commit comments

Comments
 (0)