Use TextBlobs to paint tabs

This commit is contained in:
David Capello 2024-11-30 10:00:10 -03:00
parent 6b7aa371ce
commit f10bc52b6c
2 changed files with 25 additions and 2 deletions

View File

@ -172,7 +172,11 @@ void Tabs::updateTabs()
x += tabWidth;
}
tab->text = tab->view->getTabText();
std::string newText = tab->view->getTabText();
if (tab->text != newText) {
tab->text = newText;
tab->textBlob.reset();
}
tab->icon = tab->view->getTabIcon();
tab->color = tab->view->getTabColor();
tab->x = int(x);
@ -480,6 +484,10 @@ void Tabs::onInitTheme(ui::InitThemeEvent& ev)
m_tabsBottomHeight = theme->dimensions.tabsBottomHeight();
setStyle(theme->styles.mainTabs());
}
for (TabPtr& tab : m_list) {
tab->textBlob = nullptr;
}
}
void Tabs::onPaint(PaintEvent& ev)
@ -643,7 +651,19 @@ void Tabs::drawTab(Graphics* g, const gfx::Rect& _box,
Style* stylePtr = theme->styles.tabText();
Style newStyle(nullptr);
if (!tab->textBlob) {
tab->textBlob =
text::TextBlob::MakeWithShaper(
theme->fontMgr(),
AddRef(font()),
tab->text,
nullptr,
text::ShaperFeatures());
}
info.text = &tab->text;
info.textBlob = tab->textBlob;
if (tabColor != gfx::ColorNone) {
// TODO replace these fillRect() with a new theme part (which
// should be painted with the specific user-defined color)
@ -664,6 +684,7 @@ void Tabs::drawTab(Graphics* g, const gfx::Rect& _box,
gfx::Rect(box.x+dx, box.y+dy, box.w-dx, box.h),
info);
info.text = nullptr;
info.textBlob = nullptr;
}
}

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2019-2024 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -10,6 +10,7 @@
#pragma once
#include "base/ref.h"
#include "text/fwd.h"
#include "ui/animated_widget.h"
#include "ui/widget.h"
@ -122,6 +123,7 @@ namespace app {
struct Tab {
TabView* view;
std::string text;
text::TextBlobRef textBlob;
TabIcon icon;
gfx::Color color;
int x, width;