mirror of
https://github.com/rhaleblian/dslibris.git
synced 2025-06-18 16:55:41 -04:00
Improve button text position and clip
This commit is contained in:
parent
8d1a03a6c9
commit
a04fc81b96
@ -205,6 +205,7 @@ public:
|
||||
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);
|
||||
|
@ -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");
|
||||
|
||||
|
@ -79,15 +79,17 @@ void Button::Draw(u16 *fb, bool highlight) {
|
||||
}
|
||||
}
|
||||
|
||||
// u16 bordercolor = RGB15(22,22,22) | BIT(15);
|
||||
// for (x=ul.x;x<lr.x;x++) {
|
||||
// fb[ul.y*SCREEN_WIDTH + x] = bordercolor;
|
||||
// fb[lr.y*SCREEN_WIDTH + x] = bordercolor;
|
||||
// }
|
||||
// for (y=ul.y;y<lr.y;y++) {
|
||||
// fb[y*SCREEN_WIDTH + ul.x] = bordercolor;
|
||||
// fb[y*SCREEN_WIDTH + lr.x-1] = bordercolor;
|
||||
// }
|
||||
#if 0
|
||||
u16 bordercolor = RGB15(22,22,22) | BIT(15);
|
||||
for (x=ul.x;x<lr.x;x++) {
|
||||
fb[ul.y*SCREEN_WIDTH + x] = bordercolor;
|
||||
fb[lr.y*SCREEN_WIDTH + x] = bordercolor;
|
||||
}
|
||||
for (y=ul.y;y<lr.y;y++) {
|
||||
fb[y*SCREEN_WIDTH + ul.x] = bordercolor;
|
||||
fb[y*SCREEN_WIDTH + lr.x-1] = bordercolor;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool invert = ts->GetInvert();
|
||||
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()) {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user