ListStyle (compact) replacement for two-column tables

by calling CTable::SetStyle(CTable::ListStyle) one can switch from the
bulky and unreadable-on-narrow-devices-or-nonmonospaced-fonts tables to
a more compact list style of output. The first "column" will be bolded
for better visibility and seperated with a colon from the second.

This is currently designed to replace two column tables only.
This commit is contained in:
girst
2019-04-21 17:21:24 +02:00
parent 09a514ba02
commit 3988cfef98
3 changed files with 59 additions and 3 deletions
+29
View File
@@ -760,6 +760,8 @@ void CUtils::SetMessageTags(CString& sLine, const MCString& mssTags) {
}
bool CTable::AddColumn(const CString& sName) {
if (eStyle == ListStyle && m_vsHeaders.size() >= 2)
return false;
for (const CString& sHeader : m_vsHeaders) {
if (sHeader.Equals(sName)) {
return false;
@@ -772,6 +774,19 @@ bool CTable::AddColumn(const CString& sName) {
return true;
}
bool CTable::SetStyle(EStyle eNewStyle) {
switch (eNewStyle) {
case GridStyle:
break;
case ListStyle:
if (m_vsHeaders.size() > 2) return false;
break;
}
eStyle = eNewStyle;
return true;
}
CTable::size_type CTable::AddRow() {
// Don't add a row if no headers are defined
if (m_vsHeaders.empty()) {
@@ -812,6 +827,20 @@ bool CTable::GetLine(unsigned int uIdx, CString& sLine) const {
return false;
}
if (eStyle == ListStyle) {
if (m_vsHeaders.size() > 2) return false; // definition list mode can only do up to two columns
if (uIdx >= size()) return false;
const std::vector<CString>& mRow = (*this)[uIdx];
ssRet << "\x02" << mRow[0] << "\x0f"; //bold first column
if (m_vsHeaders.size() >= 2 && mRow[1] != "") {
ssRet << ": " << mRow[1];
}
sLine = ssRet.str();
return true;
}
if (uIdx == 1) {
ssRet.fill(' ');
ssRet << "| ";