CComponentsFrmClock: use only space char for minimal separator width

Calculate of minimal separator width by a space char should be enough
in all cases.
A switch statement should be also unnecessary, if we check for digits.
This commit is contained in:
2013-12-03 20:43:35 +01:00
parent e2d920660e
commit 08fed0f5d6

View File

@@ -36,6 +36,7 @@
#include <pthread.h> #include <pthread.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#include <ctype.h>
using namespace std; using namespace std;
@@ -151,10 +152,9 @@ void CComponentsFrmClock::initCCLockItems()
} }
} }
//calculate minimal separator width, we use a space char...should be enough
int minSepWidth = 0; int minSepWidth = 0;
minSepWidth = std::max((*getClockFont())->getRenderWidth(" ", true), minSepWidth); minSepWidth = max((*getClockFont())->getRenderWidth("\x20", true), minSepWidth);
minSepWidth = std::max((*getClockFont())->getRenderWidth(".", true), minSepWidth);
minSepWidth = std::max((*getClockFont())->getRenderWidth(":", true), minSepWidth);
//modify available label items with current segment chars //modify available label items with current segment chars
for (size_t i = 0; i < v_cc_items.size(); i++) for (size_t i = 0; i < v_cc_items.size(); i++)
@@ -176,20 +176,11 @@ void CComponentsFrmClock::initCCLockItems()
string stmp = s_time.substr(i, 1); string stmp = s_time.substr(i, 1);
//get width of current segment //get width of current segment
int wtmp; int wtmp = 0;
char c = stmp.at(0); if (isdigit(stmp.at(0)) ) //check for digits, if true, we use digit width
switch (c) { wtmp = (*getClockFont())->getMaxDigitWidth();
case '0' ... '9': else //not digit found, we use render width or minimal width
wtmp = (*getClockFont())->getMaxDigitWidth(); wtmp = max((*getClockFont())->getRenderWidth(stmp, true), minSepWidth);
break;
case ' ':
case '.':
case ':':
wtmp = minSepWidth;
break;
default:
wtmp = (*getClockFont())->getRenderWidth(stmp, true);
}
//set size, text, color of current item //set size, text, color of current item
lbl->setDimensionsAll(cl_x, cl_y, wtmp, cl_h); lbl->setDimensionsAll(cl_x, cl_y, wtmp, cl_h);