@@ -22,9 +22,82 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2222#include " tabbed_book.hpp"
2323
2424#include " ../button/tab.hpp"
25+ #include " ../button/tab_group.hpp"
26+
27+ using namespace std ::string_literals;
2528
2629using namespace ruis ;
2730
31+ namespace m {
32+ using namespace ruis ::make;
33+ } // namespace m
34+
35+ tabbed_book::tabbed_book (
36+ utki::shared_ref<ruis::context> context, //
37+ all_parameters params
38+ ) :
39+ widget(
40+ std::move (context), //
41+ std::move(params.layout_params),
42+ std::move(params.widget_params)
43+ ),
44+ // clang-format off
45+ container(this ->context,
46+ {
47+ .container_params {
48+ .layout = ruis::layout::column
49+ }
50+ },
51+ {
52+ m::tab_group (this ->context ,
53+ {
54+ .layout_params {
55+ .dims {ruis::dim::fill, ruis::dim::min}
56+ },
57+ .widget_params {
58+ .id = " ruis_tab_group" s
59+ }
60+ }
61+ ),
62+ m::book (this ->context ,
63+ {
64+ .layout_params {
65+ .dims {ruis::dim::fill, ruis::dim::max},
66+ .weight = 1
67+ },
68+ .widget_params {
69+ .id = " ruis_book" s
70+ }
71+ }
72+ )
73+ }
74+ ),
75+ // clang-format on
76+ tab_group(this ->get_widget_as<ruis::tab_group>(" ruis_tab_group" )),
77+ book(this ->get_widget_as<ruis::book>(" ruis_book" ))
78+ {
79+ // on page tear out, remove corresponding tab
80+ this ->book .pages_change_handler = [this ](ruis::book& b, const page& p) {
81+ auto i = this ->find_pair (p);
82+ if (i != this ->tab_page_pairs .end ()) {
83+ ASSERT (i->tab )
84+ this ->activate_another_tab (*i->tab );
85+ i->tab ->remove_from_parent ();
86+ this ->tab_page_pairs .erase (i);
87+ }
88+ };
89+
90+ // on page programmatic activate we need to activate the corresponding tab as well
91+ this ->book .active_page_change_handler = [this ](ruis::book& b) {
92+ ASSERT (b.get_active_page ())
93+ auto i = this ->find_pair (*b.get_active_page ());
94+ if (i != this ->tab_page_pairs .end ()) {
95+ ASSERT (i->tab )
96+ i->tab ->activate ();
97+ }
98+ };
99+ }
100+
28101tabbed_book::tabbed_book (const utki::shared_ref<ruis::context>& context, const tml::forest& desc) :
29102 ruis::widget(context, desc),
30103 ruis::container(this ->context, tml::read(R"(
0 commit comments