Cache inf cached state for labels

This commit is contained in:
Nikita Lisitsa 2022-02-27 19:40:18 +03:00
parent 5d116ad79a
commit 512e9b51b7
2 changed files with 5 additions and 2 deletions

View file

@ -83,6 +83,7 @@ namespace psemek::ui
};
mutable std::optional<cached_state> cached_state_;
mutable std::optional<cached_state> cached_state_inf_;
void update_cached_state() const;
cached_state cached_state_for(geom::box<float, 2> const & bbox) const;

View file

@ -56,9 +56,10 @@ namespace psemek::ui
{
static float const inf = std::numeric_limits<float>::infinity();
auto state = cached_state_for({{{0.f, inf}, {0.f, inf}}});
if (!cached_state_inf_)
cached_state_inf_ = cached_state_for({{{0.f, inf}, {0.f, inf}}});
return {{{state.size[0], inf}, {state.size[1], inf}}};
return {{{cached_state_inf_->size[0], inf}, {cached_state_inf_->size[1], inf}}};
}
void label::draw(painter & p) const
@ -82,6 +83,7 @@ namespace psemek::ui
void label::on_state_changed()
{
cached_state_.reset();
cached_state_inf_.reset();
post_reshape();
}