Tabs can now have a minimum tab width when they are auto-sizing based on the text (closes #42)

0.8
Bruno Van de Velde 2017-07-21 23:49:54 +02:00
parent 83e1869c3d
commit 0a54bca136
2 changed files with 48 additions and 1 deletions

View File

@ -295,6 +295,8 @@ namespace tgui
///
/// @param maximumWidth Maximum width of a single tab
///
/// This property only has effect when the tabs are auto-sizing.
///
/// If the text on the tab is longer than this width then it will be cropped to fit inside the tab.
/// By default, the maximum width is 0 which means that there is no limitation.
///
@ -307,6 +309,8 @@ namespace tgui
///
/// @return Maximum tab width
///
/// This property only has effect when the tabs are auto-sizing.
///
/// If the text on the tab is longer than this width then it will be cropped to fit inside the tab.
/// By default, the maximum width is 0 which means that there is no limitation.
///
@ -314,6 +318,32 @@ namespace tgui
float getMaximumTabWidth() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Changes the minimum tab width of the tabs
///
/// @param minimumWidth Minimum width of a single tab
///
/// This property only has effect when the tabs are auto-sizing.
///
/// Every tab is at least as wide as this minimum or twice the distance to side.
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setMinimumTabWidth(float minimumWidth);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the minimum tab width of the tabs
///
/// @return Minimum tab width
///
/// This property only has effect when the tabs are auto-sizing.
///
/// Every tab is at least as wide as this minimum or twice the distance to side.
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
float getMinimumTabWidth() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the amount of tabs
///
@ -413,6 +443,7 @@ namespace tgui
unsigned int m_requestedTextSize = 0;
unsigned int m_textSize = 22;
float m_maximumTabWidth = 0;
float m_minimumTabWidth = 0;
int m_selectedTab = -1;
int m_hoveringTab = -1;
bool m_autoSize = true;

View File

@ -335,6 +335,22 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Tabs::setMinimumTabWidth(float minimumWidth)
{
m_minimumTabWidth = minimumWidth;
recalculateTabsWidth();
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
float Tabs::getMinimumTabWidth() const
{
return m_minimumTabWidth;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
std::size_t Tabs::getTabsCount() const
{
return m_tabTexts.size();
@ -418,7 +434,7 @@ namespace tgui
float totalWidth = 0;
for (unsigned int i = 0; i < m_tabWidth.size(); ++i)
{
m_tabWidth[i] = m_tabTexts[i].getSize().x + (2 * m_distanceToSideCached);
m_tabWidth[i] = m_tabTexts[i].getSize().x + std::max(m_minimumTabWidth, 2 * m_distanceToSideCached);
if ((m_maximumTabWidth > 0) && (m_maximumTabWidth < m_tabWidth[i]))
m_tabWidth[i] = m_maximumTabWidth;