Skip to content

Commit 4f16aec

Browse files
committed
fix(select): menu label uses width from font
1 parent c49e109 commit 4f16aec

5 files changed

Lines changed: 42 additions & 5 deletions

File tree

src/bkbookmark.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@
3737
<viewdata key="" value=""/>
3838
...
3939
</bookmark>
40+
<bookmark ... >
41+
<viewdata key="" value=""/>
42+
<viewdata key="" value=""/>
43+
<viewdata key="" value=""/>
44+
<viewdata key="" value=""/>
45+
...
46+
</bookmark>
4047
</file>
4148
<lastfile filename=""/>
4249
</bookmarks>
@@ -66,7 +73,6 @@ static void clearXML() {
6673
#else
6774
snprintf(xmlfilename, 1024, BOOKMARK_XML_BASE, FZScreen::basePath().c_str(), BOOKMARK_XML);
6875
#endif
69-
7076

7177
doc->SaveFile(xmlfilename);
7278
}
@@ -92,6 +98,7 @@ static void loadXML() {
9298

9399
if(doc->Error()) {
94100
// probably file not found, create an empty one
101+
printf("doc Error\n");
95102
clearXML();
96103
}
97104

@@ -128,14 +135,27 @@ static void saveXML() {
128135

129136
static XMLNode* fileNode(string& filename) {
130137
#ifdef DEBUG
131-
printf("fileNode\n");
138+
printf("fileNode(%s)\n", filename.c_str());
132139
#endif
133140

141+
#ifdef DEBUG
142+
printf("fileNode - pre load xml\n");
143+
#endif
134144
if (doc == 0)
135145
loadXML();
146+
147+
#ifdef DEBUG
148+
printf("fileNode - post load xml\n");
149+
#endif
136150
XMLElement* file = root->FirstChildElement("file");
151+
#ifdef DEBUG
152+
printf("fileNode - file ass. xml\n");
153+
#endif
137154
while (file) {
138155
const char* name = file->Attribute("filename");
156+
#ifdef DEBUG
157+
printf("fileNode - %s\n", name);
158+
#endif
139159
if (name != 0) {
140160
if (strncmp(filename.c_str(), name, 1024) == 0)
141161
return file;
@@ -258,6 +278,9 @@ static void addBookmarkProto(string& filename, BKBookmark& b, XMLNode* file) {
258278
//bookmark->SetAttribute("zoomvalue", b.zoom);
259279
//bookmark.SetAttribute("thumbnail", );
260280
map<string, int>::iterator it(b.viewData.begin());
281+
#ifdef DEBUG
282+
printf("addBookmarkProto: title: %s page: %i\n", b.title.c_str(), b.page);
283+
#endif
261284
while (it != b.viewData.end()) {
262285
XMLElement *vd = doc->NewElement("viewdata");
263286
vd->SetAttribute("key", (*it).first.c_str());

src/bkdocument.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,10 @@ int BKDocument::processEventsForView() {
278278
}
279279

280280
void BKDocument::buildToolbarMenus() {
281+
#ifdef DEBUG
282+
printf("BKBookmarksManager::buildToolbarMenus\n");
283+
#endif
284+
281285
toolbarMenus[0].clear();
282286
if (isBookmarkable()) {
283287
ToolbarItem i("Add bookmark", "bk_add_bookmark_icon", "Select");
@@ -701,7 +705,7 @@ void BKDocument::render() {
701705
vita2d_draw_rectangle(
702706
60 + toolbarSelMenu*75 - 10,
703707
544 - 140 - (selItemI*55) - 55,
704-
iw,
708+
60 + 20 + iw,
705709
50,
706710
0xf0cccccc);
707711
#endif

src/bklayervita.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ int BKLayer::textWidthRange(char* t, int n, FZFont* font) {
170170
}
171171

172172
int BKLayer::textW(char* t, FZFont* font) {
173-
return 20 * strlen(t);
173+
return font->fontTextWidth(t);
174174
}
175175

176176
void BKLayer::drawTextHC(char* t, FZFont* font, int y) {
@@ -419,7 +419,7 @@ void BKLayer::drawPopup(string& text, string& title, int bg1, int bg2, int fg) {
419419

420420

421421
void BKLayer::drawClockAndBattery(string& extra) {
422-
int ew = textW((char*)extra.c_str(), fontSmall);
422+
// int ew = textW((char*)extra.c_str(), fontSmall);
423423
FZScreen::drawFontText(fontBig, DIALOG_MENU_ITEM_TEXT_OFFSET_X + 565,
424424
DIALOG_ICON_TEXT_OFFSET_Y - 45,
425425
DIALOG_ICON_COLOR, DIALOG_ICON_TEXT_SIZE, extra.c_str());

src/graphics/fzfont.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class FZFont : public FZRefCounted {
7979
void doneUTFFont();
8080
static int get_next_utf8_char(unsigned long*, const char*, int);
8181
FZTexture* getTextureFromString(const char* t,int char_gap);
82+
int fontTextWidth(const char *text);
8283

8384
/**
8485
* Create a new font texture with Freetype.

src/graphics/fzfontvita.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,17 @@ FZFont* FZFont::createFromMemory(unsigned char* buffer, int bufferSize) {
5959
#endif
6060
FZFont* font = new FZFont();
6161
font->v_font = vita2d_load_font_mem(buffer, bufferSize);
62+
font->fontSize = 28;
6263
return font;
6364
}
65+
66+
int FZFont::fontTextWidth(const char *text)
67+
{
68+
#ifdef DEBUG
69+
printf("FZFont::fontTextWidth() - %i\n", vita2d_font_text_width(v_font, fontSize, text));
70+
#endif
71+
return vita2d_font_text_width(v_font, fontSize, text);
72+
}
6473
#elif defined(SWITCH)
6574
FZFont::~FZFont() {
6675
}

0 commit comments

Comments
 (0)