diff --git a/include/text.h b/include/text.h index dbbd0e4..c5a3ccd 100644 --- a/include/text.h +++ b/include/text.h @@ -205,6 +205,7 @@ class Text { u8 GetAdvance(u32 ucs); u8 GetAdvance(u32 ucs, u8 style); u8 GetCharCode(const char* txt, u32* code); + u8 GetCharCountInsideWidth(const char *txt, u8 style, u8 pixels); FT_Face GetFace() { return face; } FT_Face GetFace(u8 style) { return faces[style]; } string GetFontFile(u8 style); diff --git a/source/app_browser.cpp b/source/app_browser.cpp index a4543e6..2d80b0e 100644 --- a/source/app_browser.cpp +++ b/source/app_browser.cpp @@ -164,15 +164,15 @@ void App::browser_init(void) buttons[i]->SetLabel2(*(book->GetAuthor())); } buttonprev.Init(ts); - buttonprev.Move(2,240); + buttonprev.Move(2,238); buttonprev.Resize(60,16); buttonprev.Label("prev"); buttonnext.Init(ts); - buttonnext.Move(130,240); + buttonnext.Move(130,238); buttonnext.Resize(60,16); buttonnext.Label("next"); buttonprefs.Init(ts); - buttonprefs.Move(66,240); + buttonprefs.Move(66,238); buttonprefs.Resize(60,16); buttonprefs.Label("prefs"); diff --git a/source/button.cpp b/source/button.cpp index b916271..e160e46 100644 --- a/source/button.cpp +++ b/source/button.cpp @@ -79,15 +79,17 @@ void Button::Draw(u16 *fb, bool highlight) { } } - // u16 bordercolor = RGB15(22,22,22) | BIT(15); - // for (x=ul.x;xGetInvert(); ts->SetScreen(fb); @@ -97,13 +99,9 @@ void Button::Draw(u16 *fb, bool highlight) { ts->SetPen(ul.x+6, ul.y + ts->GetHeight()); if(highlight) ts->usebgcolor = true; - // FIXME request a string fitting into the bounding box instead. ts->SetPixelSize(ts->GetPixelSize()+1); - if(text.length() > 30) - ts->PrintString((const char*)text.substr(0,30).append("...").c_str(), - TEXT_STYLE_BROWSER); - else - ts->PrintString((const char*)text.c_str(), TEXT_STYLE_BROWSER); + uint8_t len = ts->GetCharCountInsideWidth(text.c_str(), TEXT_STYLE_BROWSER, SCREEN_HEIGHT); + ts->PrintString((const char*)text.substr(0, len).c_str(), TEXT_STYLE_BROWSER); ts->SetPixelSize(ts->GetPixelSize()-1); if (text2.length()) { diff --git a/source/text.cpp b/source/text.cpp index 81dc449..5c990f3 100644 --- a/source/text.cpp +++ b/source/text.cpp @@ -408,6 +408,21 @@ u8 Text::GetStringWidth(const char *txt, FT_Face face) return width; } +u8 Text::GetCharCountInsideWidth(const char *txt, u8 style, u8 pixels) { + u8 n = 0; + u8 width = 0; + const char *c; + for(c = txt; c != NULL; c++) + { + u32 ucs = 0; + GetCharCode(c, &ucs); + width += GetAdvance(ucs, GetFace(style)); + if (width > pixels) return n; + n++; + } + return n; +} + u8 Text::GetCharCode(const char *utf8, u32 *ucs) { //! Given a UTF-8 encoding, fill in the Unicode/UCS code point. //! Return the bytelength of the encoding, for advancing