diff --git a/libs/ui/include/psemek/ui/label.hpp b/libs/ui/include/psemek/ui/label.hpp index 80f131ba..60838cd9 100644 --- a/libs/ui/include/psemek/ui/label.hpp +++ b/libs/ui/include/psemek/ui/label.hpp @@ -83,6 +83,7 @@ namespace psemek::ui }; mutable std::optional cached_state_; + mutable std::optional cached_state_inf_; void update_cached_state() const; cached_state cached_state_for(geom::box const & bbox) const; diff --git a/libs/ui/source/label.cpp b/libs/ui/source/label.cpp index 4cbc6e67..b856741a 100644 --- a/libs/ui/source/label.cpp +++ b/libs/ui/source/label.cpp @@ -56,9 +56,10 @@ namespace psemek::ui { static float const inf = std::numeric_limits::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(); }