From 2e9d89e9000474d76d3d97714b245ffe8164f3ea Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Tue, 3 Dec 2013 20:43:35 +0100 Subject: [PATCH] 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. Origin commit data ------------------ Branch: ni/coolstream Commit: https://github.com/neutrino-images/ni-neutrino/commit/08fed0f5d6080403551528c3b460735584bf7502 Author: Thilo Graf Date: 2013-12-03 (Tue, 03 Dec 2013) ------------------ This commit was generated by Migit --- src/gui/components/cc_frm_clock.cpp | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/gui/components/cc_frm_clock.cpp b/src/gui/components/cc_frm_clock.cpp index ad0d17d9f..9b960aae7 100644 --- a/src/gui/components/cc_frm_clock.cpp +++ b/src/gui/components/cc_frm_clock.cpp @@ -36,6 +36,7 @@ #include #include #include +#include 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; - minSepWidth = std::max((*getClockFont())->getRenderWidth(" ", true), minSepWidth); - minSepWidth = std::max((*getClockFont())->getRenderWidth(".", true), minSepWidth); - minSepWidth = std::max((*getClockFont())->getRenderWidth(":", true), minSepWidth); + minSepWidth = max((*getClockFont())->getRenderWidth("\x20", true), minSepWidth); //modify available label items with current segment chars 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); //get width of current segment - int wtmp; - char c = stmp.at(0); - switch (c) { - case '0' ... '9': - wtmp = (*getClockFont())->getMaxDigitWidth(); - break; - case ' ': - case '.': - case ':': - wtmp = minSepWidth; - break; - default: - wtmp = (*getClockFont())->getRenderWidth(stmp, true); - } + int wtmp = 0; + if (isdigit(stmp.at(0)) ) //check for digits, if true, we use digit width + wtmp = (*getClockFont())->getMaxDigitWidth(); + else //not digit found, we use render width or minimal width + wtmp = max((*getClockFont())->getRenderWidth(stmp, true), minSepWidth); //set size, text, color of current item lbl->setDimensionsAll(cl_x, cl_y, wtmp, cl_h);