[escher] Adjust tab width to their content

Change-Id: I564ff70c9067f4fa5fab332809b2be4cac127f40
This commit is contained in:
Émilie Feral
2017-01-23 10:43:57 +01:00
parent f531b8d358
commit 237f214fae
3 changed files with 18 additions and 4 deletions

View File

@@ -11,6 +11,7 @@ public:
void setName(const char * name);
void setActive(bool active);
void setSelected(bool selected);
KDSize minimalSizeForOptimalDisplay() override;
protected:
#if ESCHER_VIEW_LOGGING
const char * className() const override;

View File

@@ -68,14 +68,23 @@ View * TabView::subviewAtIndex(int index) {
}
void TabView::layoutSubviews() {
// Simple layout: all tabs have the same length
KDCoordinate tabLength = m_frame.width()/m_numberOfTabs;
KDCoordinate emptyWidth = bounds().width();
for (int i=0; i<m_numberOfTabs; i++) {
emptyWidth -= m_cells[i].minimalSizeForOptimalDisplay().width();
}
KDCoordinate widthUsed = 0;
for (int i=0; i<m_numberOfTabs; i++) {
KDCoordinate tabWidth = m_cells[i].minimalSizeForOptimalDisplay().width() + emptyWidth/m_numberOfTabs;
/* Avoid a unused one-pixel-width vertical on the left due to rounding error */
if (i == m_numberOfTabs - 1) {
tabWidth = bounds().width() - widthUsed;
}
KDRect cellFrame = KDRect(
i*tabLength, 0,
tabLength, m_frame.height() - 5
widthUsed, 0,
tabWidth, m_frame.height() - 5
);
m_cells[i].setFrame(cellFrame);
widthUsed += tabWidth;
}
}

View File

@@ -30,6 +30,10 @@ void TabViewCell::setSelected(bool selected) {
markRectAsDirty(bounds());
}
KDSize TabViewCell::minimalSizeForOptimalDisplay() {
return KDText::stringSize(m_name, KDText::FontSize::Small);
}
void TabViewCell::drawRect(KDContext * ctx, KDRect rect) const {
KDCoordinate height = bounds().height();
KDCoordinate width = bounds().width();