Skip to content

Commit 71711da

Browse files
committed
styles as resources
1 parent ca4b75b commit 71711da

8 files changed

Lines changed: 19 additions & 21 deletions

File tree

res/ruis_res/main.res

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
11
include{ui.res}
2-
// include{fonts/font.res}
3-
include_subdirs
42

5-
// TODO: remove
6-
ruis_gui_defs{
7-
file{defs.gui}
8-
}
3+
include_subdirs

res/ruis_res/styles/main.res

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ruis_tml_style_dark{
2+
file{style_dark.tml}
3+
}
4+
5+
ruis_tml_style_light{
6+
file{style_light.tml}
7+
}

src/ruis/gui.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,17 @@ void gui::init_standard_widgets(const fsif::file& fi)
6767
continue;
6868
}
6969

70-
fi.set_path(utki::cat(s, "style_dark.tml"));
71-
this->context.get().style_provider.get().set(utki::make_shared<style_sheet>(tml::read(fi)));
72-
7370
mounted = true;
7471
break;
7572
}
7673

7774
if (!mounted) {
7875
throw std::runtime_error("gui::init_standard_widgets(): could not mount default resource pack");
7976
}
77+
78+
// TODO: pass which style to load via parameter
79+
auto style_res = this->context.get().loader().load<ruis::res::tml>("ruis_tml_style_dark"sv);
80+
this->context.get().style_provider.get().set(utki::make_shared<style_sheet>(style_res.get().forest));
8081
}
8182

8283
void gui::set_viewport(const ruis::rect& rect)

src/ruis/res/tml.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ using namespace std::string_view_literals;
2828

2929
using namespace ruis::res;
3030

31-
ruis::res::tml::tml(::tml::forest tml_forest) :
32-
tml_forest(std::move(tml_forest))
31+
ruis::res::tml::tml(::tml::forest forest) :
32+
forest(std::move(forest))
3333
{}
3434

3535
utki::shared_ref<ruis::res::tml> ruis::res::tml::load( //

src/ruis/res/tml.hpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ class tml : public resource
4646
{
4747
friend class ruis::resource_loader;
4848

49-
::tml::forest tml_forest;
50-
5149
public:
5250
/**
5351
* @brief Create tml resource.
@@ -63,10 +61,7 @@ class tml : public resource
6361

6462
~tml() override = default;
6563

66-
const ::tml::forest& forest() const noexcept
67-
{
68-
return this->tml_forest;
69-
}
64+
const ::tml::forest forest;
7065

7166
private:
7267
static utki::shared_ref<tml> load( //

tests/unit/src/style.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ const tst::set set("style", [](tst::suite& suite){
212212

213213
auto tml_sv = s.get<ruis::res::tml>("tml_style_value"sv);
214214
tst::check(tml_sv.get(), SL);
215-
tst::check_eq(tml_sv.get()->forest(), tml::read("Hello world!"s), SL);
215+
tst::check_eq(tml_sv.get()->forest, tml::read("Hello world!"s), SL);
216216

217217
auto ss2 = utki::make_shared<ruis::style_sheet>(
218218
tml::read(
@@ -227,12 +227,12 @@ const tst::set set("style", [](tst::suite& suite){
227227

228228
s.set(ss2);
229229

230-
tst::check_eq(tml_sv.get()->forest(), tml::read("World, hello!"s), SL);
230+
tst::check_eq(tml_sv.get()->forest, tml::read("World, hello!"s), SL);
231231

232232
{
233233
auto tml_sv = s.get<ruis::res::tml>("tml_style_value"sv);
234234
tst::check(tml_sv.get(), SL);
235-
tst::check_eq(tml_sv.get()->forest(), tml::read("World, hello!"s), SL);
235+
tst::check_eq(tml_sv.get()->forest, tml::read("World, hello!"s), SL);
236236
}
237237
});
238238

@@ -268,7 +268,7 @@ const tst::set set("style", [](tst::suite& suite){
268268

269269
ruis::styled<ruis::res::tml> tml = std::make_shared<ruis::res::tml>(tml::read("Hello{world!}"));
270270
tst::check(tml.get() != nullptr, SL);
271-
tst::check_eq(tml.get()->forest(), tml::read("Hello{world!}"), SL);
271+
tst::check_eq(tml.get()->forest, tml::read("Hello{world!}"), SL);
272272
});
273273
});
274274
}

0 commit comments

Comments
 (0)