mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[escher] Adjust tab width to their content
Change-Id: I564ff70c9067f4fa5fab332809b2be4cac127f40
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user