Index: source/gui/COList.h =================================================================== --- source/gui/COList.h +++ source/gui/COList.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2016 Wildfire Games. +/* Copyright (C) 2017 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -25,11 +25,10 @@ */ struct COListColumn { - CColor m_TextColor; - CStr m_Id; - float m_Width; - CStrW m_Heading; - + CColor m_TextColor; + CStr m_Id; + float m_Width; + CStrW m_Heading; }; /** @@ -60,6 +59,8 @@ virtual CRect GetListRect() const; + float GetColumnWidth(const COListColumn& column) const; + /** * Available columns. */ @@ -68,6 +69,7 @@ private: // Width of space available for columns float m_TotalAvailableColumnWidth; + float m_TotalAvailableRelativeColumnWidth; }; #endif // INCLUDED_COLIST Index: source/gui/COList.cpp =================================================================== --- source/gui/COList.cpp +++ source/gui/COList.cpp @@ -66,12 +66,28 @@ if (scrollbar && GetScrollBar(0).GetStyle()) width -= GetScrollBar(0).GetStyle()->m_Width; - m_TotalAvailableColumnWidth = width; + m_TotalAvailableRelativeColumnWidth = m_TotalAvailableColumnWidth = width; + float total_sum = 0.f; + for (const COListColumn& column : m_Columns) + { + bool hidden = false; + GUI::GetSetting(this, "hidden_" + column.m_Id, hidden); + if (hidden) + continue; + if (column.m_Width < 1) + total_sum += column.m_Width; + else + m_TotalAvailableRelativeColumnWidth -= column.m_Width; + } + // In normal case total_sum should be equal to 1.0 (all columns in total give 100%) + // So normalize availabe relative width + if (total_sum > 0.f) + m_TotalAvailableRelativeColumnWidth /= total_sum; float buffer_zone = 0.f; GUI::GetSetting(this, "buffer_zone", buffer_zone); - for (COListColumn column : m_Columns) + for (const COListColumn& column : m_Columns) { SGUIText* text = new SGUIText(); CGUIString gui_string; @@ -155,17 +171,14 @@ GUI::GetSetting(this, "heading_height", headingHeight); float xpos = 0; - for (COListColumn column : m_Columns) + for (const COListColumn& column : m_Columns) { bool hidden = false; GUI::GetSetting(this, "hidden_" + column.m_Id, hidden); if (hidden) continue; - float width = column.m_Width; - // Check if it's a decimal value, and if so, assume relative positioning. - if (column.m_Width < 1 && column.m_Width > 0) - width *= m_TotalAvailableColumnWidth; + float width = GetColumnWidth(column); CPos leftTopCorner = m_CachedActualSize.TopLeft() + CPos(xpos, 0); if (mouse.x >= leftTopCorner.x && mouse.x < leftTopCorner.x + width && @@ -400,11 +413,7 @@ if (hidden) continue; - // Check if it's a decimal value, and if so, assume relative positioning. - float width = m_Columns[col].m_Width; - if (m_Columns[col].m_Width < 1 && m_Columns[col].m_Width > 0) - width *= m_TotalAvailableColumnWidth; - + float width = GetColumnWidth(m_Columns[col]); CPos leftTopCorner = m_CachedActualSize.TopLeft() + CPos(xpos, 0); // Draw sort arrows in colum header @@ -468,10 +477,7 @@ // Determine text position and width const CPos textPos = rect.TopLeft() + CPos(xpos, -scroll + m_ItemsYPositions[i]); - float width = m_Columns[col].m_Width; - // Check if it's a decimal value, and if so, assume relative positioning. - if (m_Columns[col].m_Width < 1 && m_Columns[col].m_Width > 0) - width *= m_TotalAvailableColumnWidth; + float width = GetColumnWidth(m_Columns[col]); // Clip text to the column (to prevent drawing text into the neighboring column) CRect cliparea2 = cliparea; @@ -484,3 +490,10 @@ } } } + +float COList::GetColumnWidth(const COListColumn& column) const +{ + // Check if it's a decimal value, and if so, assume relative positioning. + return column.m_Width < 1 && column.m_Width > 0 ? + column.m_Width * m_TotalAvailableRelativeColumnWidth : column.m_Width; +}