Fix emulator build script, UI rendering, and clean up repo

This commit is contained in:
Adolfo Reyna
2026-02-17 21:49:49 -05:00
parent 6d29e99394
commit b0ca1f1a55
9 changed files with 693 additions and 526 deletions

View File

@@ -671,3 +671,57 @@ int LowLevelRenderer::draw_string_scaled(int x, int y, const char* text, int sca
}
return current_x;
}
int LowLevelRenderer::get_char_width_scaled(char c, int scale) {
if (!current_font)
return 0;
if (c < 32 || c > 127)
return 0;
if (scale < 1)
scale = 1;
int font_idx = c - 32;
const unsigned char *char_data = current_font->get_char_data(font_idx);
if (!char_data)
return 0;
int bytes_per_char = current_font->get_bytes_per_char();
// Find the actual width by skipping trailing empty columns
int actual_width = 0;
for (int col = bytes_per_char - 1; col >= 0; col--) {
if (char_data[col] != 0) {
actual_width = col + 1;
break;
}
}
return actual_width * scale;
}
int LowLevelRenderer::get_string_width_scaled(const char *text, int scale,
int spacing) {
if (!current_font)
return 0;
int width = 0;
int i = 0;
while (text[i] != '\0') {
int char_width = get_char_width_scaled(text[i], scale);
// Add spacing only if it's not the last character, but logic usually adds
// spacing after each char In drawn_string_scaled: current_x += char_width +
// (spacing * scale); So width accumulates char_width + spacing*scale.
// However, the last character shouldn't really have spacing if we want
// exact bounding box, but let's match draw_string_scaled behavior which
// effectively advances cursor. Wait, draw_string_scaled returns
// `current_x`. If x=0, current_x ends up at sum(char_width +
// spacing*scale).
width += char_width + (spacing * scale);
i++;
}
// Correction: draw_string_scaled includes spacing after the last character.
// If we want exact pixel width of the visible text, we might want to subtract
// the last spacing. But for UI alignment, usually cursor advancement is fine.
// Let's stick to returning what draw_string_scaled would add to x.
return width;
}