diff options
| author | Nick Dedekind <nicholas.dedekind@gmail.com> | 2012-08-15 17:21:08 +0100 |
|---|---|---|
| committer | Nick Dedekind <nicholas.dedekind@gmail.com> | 2012-08-15 17:21:08 +0100 |
| commit | 49559f88f8b8fa3eaba9d60cc186eddad46768a9 (patch) | |
| tree | ef58c63202710c4e1b87cd51584dfa475aacbdc2 /unity-shared | |
| parent | 29704403237efe9cef447342c313e395078d20d0 (diff) | |
Update text cached texture when maximum size changes.
Fixes LP: #1037187 (bzr r2568.1.1)
Diffstat (limited to 'unity-shared')
| -rw-r--r-- | unity-shared/StaticCairoText.cpp | 41 | ||||
| -rw-r--r-- | unity-shared/StaticCairoText.h | 3 |
2 files changed, 37 insertions, 7 deletions
diff --git a/unity-shared/StaticCairoText.cpp b/unity-shared/StaticCairoText.cpp index 8f055cbd7..0f51dfb14 100644 --- a/unity-shared/StaticCairoText.cpp +++ b/unity-shared/StaticCairoText.cpp @@ -67,7 +67,7 @@ struct StaticCairoText::Impl StaticCairoText* parent_; bool accept_key_nav_focus_; - bool need_new_extent_cache_; + mutable bool need_new_extent_cache_; // The three following are all set in get text extents. mutable Size cached_extent_; mutable Size cached_base_; @@ -309,6 +309,29 @@ void StaticCairoText::SetText(std::string const& text) } } +void StaticCairoText::SetMaximumSize(int w, int h) +{ + if (w != GetMaximumWidth()) + { + pimpl->need_new_extent_cache_ = true; + View::SetMaximumSize(w, h); + pimpl->UpdateTexture(); + return; + } + + View::SetMaximumSize(w, h); +} + +void StaticCairoText::SetMaximumWidth(int w) +{ + if (w != GetMaximumWidth()) + { + pimpl->need_new_extent_cache_ = true; + View::SetMaximumWidth(w); + pimpl->UpdateTexture(); + } +} + std::string StaticCairoText::GetText() const { return pimpl->text_; @@ -333,12 +356,15 @@ void StaticCairoText::SetTextColor(Color const& textColor) void StaticCairoText::SetFont(std::string const& font) { - pimpl->font_ = font; - pimpl->need_new_extent_cache_ = true; - Size s = GetTextExtents(); - SetMinimumHeight(s.height); - NeedRedraw(); - sigFontChanged.emit(this); + if (pimpl->font_ != font) + { + pimpl->font_ = font; + pimpl->need_new_extent_cache_ = true; + Size s = GetTextExtents(); + SetMinimumHeight(s.height); + NeedRedraw(); + sigFontChanged.emit(this); + } } int StaticCairoText::GetLineCount() const @@ -440,6 +466,7 @@ Size StaticCairoText::Impl::GetTextExtents() const result.height = std::ceil(static_cast<float>(logRect.height) / PANGO_SCALE); cached_extent_ = result; baseline_ = pango_layout_get_baseline(layout) / PANGO_SCALE; + need_new_extent_cache_ = false; // clean up pango_font_description_free(desc); diff --git a/unity-shared/StaticCairoText.h b/unity-shared/StaticCairoText.h index 9fba1fe9d..d3ddf1a8f 100644 --- a/unity-shared/StaticCairoText.h +++ b/unity-shared/StaticCairoText.h @@ -92,6 +92,9 @@ public: void SetAcceptKeyNavFocus(bool accept); + void SetMaximumSize(int w, int h); + void SetMaximumWidth(int w); + protected: // Key navigation virtual bool AcceptKeyNavFocus(); |
