@@ -21,32 +21,88 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2121
2222#include " scroll_area_page.hpp"
2323
24+ #include < ruis/res/tml.hpp>
25+ #include < ruis/standard_widgets.hpp>
26+ #include < ruis/style/style_sheet.hpp>
2427#include < ruis/widget/button/impl/rectangle_push_button.hpp>
28+ #include < ruis/widget/button/selection_box.hpp>
2529#include < ruis/widget/group/touch/scroll_area.hpp>
2630#include < ruis/widget/label/text.hpp>
2731#include < ruis/widget/slider/scroll_bar.hpp>
2832
2933#include " style.hpp"
3034
3135using namespace std ::string_literals;
36+ using namespace std ::string_view_literals;
3237
3338using namespace ruis ::length_literals;
3439
3540namespace {
3641
42+ void apply_theme (
43+ ruis::context& c, //
44+ ruis::theme theme
45+ )
46+ {
47+ auto style_res = c.loader ().load <ruis::res::tml>(ruis::to_resource_id (theme));
48+ c.style ().set (utki::make_shared<ruis::style_sheet>(style_res.get ().forest ));
49+ }
50+
51+ class theme_selection_provider : public ruis ::list_provider
52+ {
53+ std::vector<std::u32string> items;
54+
55+ public:
56+ theme_selection_provider (utki::shared_ref<ruis::context> context) :
57+ ruis::list_provider (std::move(context)),
58+ items{U" Dark" s, U" Light" s}
59+ {}
60+
61+ size_t count () const noexcept override
62+ {
63+ return this ->items .size ();
64+ }
65+
66+ utki::shared_ref<ruis::widget> get_widget (size_t index) override
67+ {
68+ return m::text (this ->context , {}, this ->items .at (index));
69+ }
70+ };
71+
3772ruis::widget_list make_scroll_area_page_contents (utki::shared_ref<ruis::context> c)
3873{
3974 // clang-format off
40- auto button_1 = m::push_button (c,
41- {
42- .layout_params {
43- .dims = {ruis::dim::fill, 200_pp}
44- }
45- },
46- {
47- m::text (c, {}, U" Button 1" s)
48- }
49- );
75+ auto theme_selector = m::selection_box (c,
76+ {
77+ .layout_params {
78+ .dims = {ruis::dim::max, ruis::dim::min}
79+ },
80+ .list_params {
81+ .provider = utki::make_shared<theme_selection_provider>(c)
82+ }
83+ }
84+ );
85+ // clang-format on
86+
87+ theme_selector.get ().set_selection (size_t (ruis::theme::dark));
88+ theme_selector.get ().selection_handler = [](ruis::selection_box& sb) {
89+ apply_theme (
90+ sb.context .get (), //
91+ ruis::theme (sb.get_selection ())
92+ );
93+ };
94+
95+ // clang-format off
96+ auto button_1 = m::push_button (c,
97+ {
98+ .layout_params {
99+ .dims = {ruis::dim::fill, 200_pp}
100+ }
101+ },
102+ {
103+ m::text (c, {}, U" Button 1" s)
104+ }
105+ );
50106 // clang-format on
51107
52108 button_1.get ().click_handler = [](ruis::push_button&) {
@@ -56,26 +112,37 @@ ruis::widget_list make_scroll_area_page_contents(utki::shared_ref<ruis::context>
56112 };
57113
58114 // clang-format off
59- return {
60- button_1,
61- m::scroll_bar (c,
62- {
63- .layout_params {
64- .dims {50_pp, 1000_pp}
65- },
66- .fraction_params {
67- .fraction = ruis::real (0.25 )
68- },
69- .fraction_band_params {
70- .band_fraction = ruis::real (0.2 )
71- },
72- .oriented_params {
73- .vertical = true
74- }
75- }
76- ),
77- m::text (c, {}, U" some text" s)
78- };
115+ return {
116+ m::row (c,
117+ {
118+ .layout_params {
119+ .dims = {ruis::dim::fill, ruis::dim::min}
120+ }
121+ },
122+ {
123+ m::text (c, {}, U" Theme:" s),
124+ theme_selector
125+ }
126+ ),
127+ button_1,
128+ m::scroll_bar (c,
129+ {
130+ .layout_params {
131+ .dims {50_pp, 1000_pp}
132+ },
133+ .fraction_params {
134+ .fraction = ruis::real (0.25 )
135+ },
136+ .fraction_band_params {
137+ .band_fraction = ruis::real (0.2 )
138+ },
139+ .oriented_params {
140+ .vertical = true
141+ }
142+ }
143+ ),
144+ m::text (c, {}, U" some text" s)
145+ };
79146 // clang-format on
80147}
81148
@@ -86,31 +153,31 @@ class scroll_area_page :
86153public:
87154 scroll_area_page (utki::shared_ref<ruis::context> c) :
88155 // clang-format off
89- ruis::widget (
90- std::move (c),
91- {},
92- {
93- .clip = true
94- }
95- ),
156+ ruis::widget (
157+ std::move (c),
158+ {},
159+ {
160+ .clip = true
161+ }
162+ ),
96163 // clang-format on
97164 ruis::page (this ->context, {}),
98165 // clang-format off
99- ruis::touch::scroll_area (
100- this ->context,
101- {},
102- {
103- m::column (
104- this ->context ,
105- {
106- .layout_params {
107- .dims = {ruis::dim::fill, ruis::dim::min}
108- }
109- },
110- make_scroll_area_page_contents (this ->context )
111- )
112- }
113- )
166+ ruis::touch::scroll_area (
167+ this ->context,
168+ {},
169+ {
170+ m::column (
171+ this ->context ,
172+ {
173+ .layout_params {
174+ .dims = {ruis::dim::fill, ruis::dim::min}
175+ }
176+ },
177+ make_scroll_area_page_contents (this ->context )
178+ )
179+ }
180+ )
114181 // clang-format on
115182 {}
116183};
0 commit comments