57
57
glib::Object<PangoLayout> GetLayoutForContext(CairoGraphics& cairo);
58
58
void SetAttributes(glib::Object<PangoLayout> const& layout);
59
void UpdateTexExtents(bool force = false);
60
void UpdateTexture(bool force = false);
60
61
void OnFontChanged();
62
63
static void FontChanged(GObject* gobject, GParamSpec* pspec, gpointer data);
64
65
StaticCairoText* parent_;
65
66
bool accept_key_nav_focus_;
66
bool need_new_extent_cache_;
67
67
Size cached_extent_;
88
88
StaticCairoText::Impl::Impl(StaticCairoText* parent, std::string const& text)
90
90
, accept_key_nav_focus_(false)
91
, need_new_extent_cache_(true)
94
93
, text_color_(color::White)
191
190
void StaticCairoText::SetLines(int lines)
192
if (pimpl->lines_ == lines)
193
195
pimpl->lines_ = lines;
196
pimpl->UpdateTexExtents(true);
194
197
pimpl->UpdateTexture();
198
201
void StaticCairoText::SetLineSpacing(float line_spacing)
203
if (pimpl->lines_ == line_spacing)
200
206
pimpl->line_spacing_ = line_spacing;
207
pimpl->UpdateTexExtents(true);
201
208
pimpl->UpdateTexture();
298
305
void StaticCairoText::SetText(std::string const& text, bool escape_text)
300
std::string tmp_text = escape_text ? GetEscapedText(text) : text;
307
std::string const& tmp_text = escape_text ? GetEscapedText(text) : text;
302
309
if (pimpl->text_ != tmp_text)
304
311
pimpl->text_ = tmp_text;
305
pimpl->need_new_extent_cache_ = true;
312
pimpl->UpdateTexExtents(true);
306
313
pimpl->UpdateTexture();
307
314
sigTextChanged.emit(this);
323
330
if (w != GetMaximumWidth())
325
pimpl->need_new_extent_cache_ = true;
326
332
View::SetMaximumSize(w, h);
333
pimpl->UpdateTexExtents(true);
327
334
pimpl->UpdateTexture();
373
380
if (pimpl->font_ != font)
375
382
pimpl->font_ = font;
376
pimpl->need_new_extent_cache_ = true;
377
Size s = GetTextExtents();
378
SetMinimumHeight(s.height);
383
pimpl->UpdateTexture(true);
384
pimpl->UpdateTexture();
385
SetMinimumHeight(GetTextExtents().height);
380
388
sigFontChanged.emit(this);
391
399
if (pimpl->underline_ != underline)
393
401
pimpl->underline_ = underline;
394
pimpl->need_new_extent_cache_ = true;
395
Size s = GetTextExtents();
396
SetMinimumHeight(s.height);
402
pimpl->UpdateTexture(true);
403
pimpl->UpdateTexture();
404
SetMinimumHeight(GetTextExtents().height);
531
void StaticCairoText::Impl::UpdateTexture()
540
void StaticCairoText::Impl::UpdateTexExtents(bool force)
533
auto old_extents = cached_extent_;
535
if (need_new_extent_cache_)
537
CairoGraphics dummy_cg(CAIRO_FORMAT_A1, 1, 1);
538
auto const& layout = GetLayoutForContext(dummy_cg);
540
pango_layout_get_pixel_size(layout, &cached_extent_.width, &cached_extent_.height);
541
baseline_ = PANGO_PIXELS(pango_layout_get_baseline(layout));
542
actual_lines_ = pango_layout_get_line_count(layout);
543
need_new_extent_cache_ = false;
547
if (texture_ && old_extents == cached_extent_)
549
// We're confident that nothing changed. No need to generate the texture again.
542
if (texture_ && !force)
545
CairoGraphics dummy_cg(CAIRO_FORMAT_A1, 1, 1);
546
auto const& layout = GetLayoutForContext(dummy_cg);
548
pango_layout_get_pixel_size(layout, &cached_extent_.width, &cached_extent_.height);
549
baseline_ = PANGO_PIXELS(pango_layout_get_baseline(layout));
550
actual_lines_ = pango_layout_get_line_count(layout);
554
void StaticCairoText::Impl::UpdateTexture(bool force)
558
if (texture_ && !force)
560
nux::Size old_extents(texture_->GetWidth(), texture_->GetHeight());
562
if (old_extents == cached_extent_)
564
// We're confident that nothing changed. No need to generate the texture again.
553
569
CairoGraphics cg(CAIRO_FORMAT_ARGB32, cached_extent_.width, cached_extent_.height);