Skip to content

Commit

Permalink
cache font styles
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Gagis committed Jan 24, 2024
1 parent 2a463f4 commit 4dd0142
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/ruis/res/font.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class font : public ruis::resource
if (ret) {
return ret->get(size);
}
return this->fonts[unsigned(style::normal)]->get(size);
return this->fonts[size_t(style::normal)]->get(size);
}

private:
Expand Down
11 changes: 9 additions & 2 deletions src/ruis/widgets/base/text_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ void text_widget::set_font_size(real size)

this->font_size = size;

this->font = this->font_face.get().get(this->font_size);
for (size_t i = 0; i != size_t(res::font::style::enum_size); ++i) {
this->fonts[i] = this->font_face.get().get(this->font_size, res::font::style(i));
}

this->invalidate_layout();

Expand Down Expand Up @@ -83,7 +85,12 @@ text_widget::text_widget(const utki::shared_ref<ruis::context>& c, const treeml:
// load default font
return this->context.get().loader.load<res::font>("ruis_fnt_text");
}()),
font(this->font_face.get().get(this->font_size))
fonts{
this->font_face.get().get(this->font_size, res::font::style(0)),
this->font_face.get().get(this->font_size, res::font::style(1)),
this->font_face.get().get(this->font_size, res::font::style(2)),
this->font_face.get().get(this->font_size, res::font::style(3))
}
{
for (const auto& p : desc) {
if (!is_property(p)) {
Expand Down
6 changes: 3 additions & 3 deletions src/ruis/widgets/base/text_widget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class text_widget : virtual public widget

utki::shared_ref<const res::font> font_face;

utki::shared_ref<const ruis::font> font;
std::array<utki::shared_ref<const ruis::font>, size_t(res::font::style::enum_size)> fonts;

public:
text_widget(const text_widget&) = delete;
Expand All @@ -55,9 +55,9 @@ class text_widget : virtual public widget

void set_font_face(const utki::shared_ref<const res::font>& font_res);

const ruis::font& get_font() const
const ruis::font& get_font(res::font::style style = res::font::style::normal) const
{
return this->font.get();
return this->fonts[size_t(style)].get();
}

void set_font_size(real size);
Expand Down
2 changes: 1 addition & 1 deletion tests/harness/modules/ruisapp
Submodule ruisapp updated 1 files
+6 −0 debian/changelog

0 comments on commit 4dd0142

Please sign in to comment.