Refactor CutText in horizontal epgview

This commit is contained in:
kamel5 2020-01-08 16:17:08 +01:00
parent c77f74321f
commit ffd3e2c79f
3 changed files with 16 additions and 29 deletions

View File

@ -131,12 +131,7 @@ void cEpgGrid::drawText() {
} }
} }
} else if (config.displayMode == eHorizontal) { } else if (config.displayMode == eHorizontal) {
if (Width() / geoManager.minutePixel < 10) { cString strTitle = CutText(event->Title(), viewportHeight - borderWidth, fontManager.FontGridHorizontal).c_str();
int titleY = (geoManager.rowHeight - fontManager.FontGridHorizontal->Height()) / 2;
pixmap->DrawText(cPoint(borderWidth - 2, titleY), "...", colorText, colorTextBack, fontManager.FontGridHorizontal);
return;
}
cString strTitle = CutText(event->Title(), viewportHeight, fontManager.FontGridHorizontal).c_str();
int titleY = 0; int titleY = 0;
if (config.showTimeInGrid) { // mit Zeitangabe im Grid if (config.showTimeInGrid) { // mit Zeitangabe im Grid
pixmap->DrawText(cPoint(borderWidth, borderWidth), *timeString, colorText, colorTextBack, fontManager.FontGridHorizontalSmall); pixmap->DrawText(cPoint(borderWidth, borderWidth), *timeString, colorText, colorTextBack, fontManager.FontGridHorizontalSmall);

36
tools.c
View File

@ -24,31 +24,23 @@ cPlugin *GetScraperPlugin(void) {
* CUTTEXT * CUTTEXT
****************************************************************************************/ ****************************************************************************************/
std::string CutText(std::string text, int width, const cFont *font) { std::string CutText(std::string text, int width, const cFont *font) {
if (width <= font->Size()) int actWidth = font->Width(text.c_str());
if (actWidth <= width) {
return text.c_str(); return text.c_str();
if (font->Width(text.c_str()) < width) } else {
return text.c_str(); int i = std::max((actWidth - width) / font->Size(), 1);
cTextWrapper twText; do {
twText.Set(text.c_str(), font, width); text = text.substr(0, text.length() - i);
std::string cuttedTextNative = twText.GetLine(0); std::stringstream sstrText;
std::stringstream sstrText; sstrText << text << "....";
sstrText << cuttedTextNative << "..."; actWidth = font->Width(sstrText.str().c_str());
std::string cuttedText = sstrText.str(); i = 1;
int actWidth = font->Width(cuttedText.c_str());
if (actWidth > width) {
int overlap = actWidth - width;
int charWidth = font->Width(".");
if (charWidth == 0)
charWidth = 1;
int cutChars = overlap / charWidth;
if (cutChars > 0) {
cuttedTextNative = cuttedTextNative.substr(0, cuttedTextNative.length() - cutChars);
std::stringstream sstrText2;
sstrText2 << cuttedTextNative << "...";
cuttedText = sstrText2.str();
} }
while ((actWidth > width) && (text.length() > 0));
std::stringstream sstrText2;
sstrText2 << text << "...";
return sstrText2.str();
} }
return cuttedText;
} }
/**************************************************************************************** /****************************************************************************************

2
view.c
View File

@ -116,7 +116,7 @@ void cView::DrawHeader(void) {
int yDateTime = border / 2; int yDateTime = border / 2;
int yTitle = (headerHeight - fontHeaderLarge->Height()) / 2; int yTitle = (headerHeight - fontHeaderLarge->Height()) / 2;
int ySubtitle = headerHeight - fontHeader->Height() - border / 3; int ySubtitle = headerHeight - fontHeader->Height() - border / 3;
int textWidthMax = headerWidth - xText; int textWidthMax = headerWidth - xText - border / 2;
pixmapHeader->DrawText(cPoint(xText, yDateTime), CutText(dateTime, textWidthMax, fontHeader).c_str(), theme.Color(clrFont), theme.Color(clrStatusHeader), fontHeader); pixmapHeader->DrawText(cPoint(xText, yDateTime), CutText(dateTime, textWidthMax, fontHeader).c_str(), theme.Color(clrFont), theme.Color(clrStatusHeader), fontHeader);
pixmapHeader->DrawText(cPoint(xText, yTitle), CutText(title, textWidthMax, fontHeaderLarge).c_str(), theme.Color(clrFont), theme.Color(clrStatusHeader), fontHeaderLarge); pixmapHeader->DrawText(cPoint(xText, yTitle), CutText(title, textWidthMax, fontHeaderLarge).c_str(), theme.Color(clrFont), theme.Color(clrStatusHeader), fontHeaderLarge);
pixmapHeader->DrawText(cPoint(xText, ySubtitle), CutText(subTitle, textWidthMax, fontHeader).c_str(), theme.Color(clrFont), theme.Color(clrStatusHeader), fontHeader); pixmapHeader->DrawText(cPoint(xText, ySubtitle), CutText(subTitle, textWidthMax, fontHeader).c_str(), theme.Color(clrFont), theme.Color(clrStatusHeader), fontHeader);