Update the truncate number function to use decimal point (#333)

* Fixed to truncate as "1.234M" instead of "1234K"

* Optimized by switching to strings to avoid divisions

* Changed FP constants to strings

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
MeirGavish
2025-12-23 07:52:30 +02:00
committed by GitHub
co-authored by Copilot
parent f76c25614c
commit 6575fc7f94
8 changed files with 304 additions and 84 deletions
+22 -19
View File
@@ -6,24 +6,16 @@
#ifndef FONT_H
#define FONT_H
#include <tonc.h>
extern const TFont gbalatro_sys8Font;
extern const unsigned int gbalatro_sys8Glyphs[192];
/** @name Decimal Point Fonts
* @brief A set of macros to map the fonts decimal-point values (e.g. ".1")
* to their replaced characters.
*
* "FP#" -> Font "Point" "number"
*
* This is used at compile time directly with the help of libtonc's XSTR() macro
* **Note**: This should **ONLY** be used with the XSTR() macro, otherwise it
* is undefined behavior.
*
* For example:
* ```c
* tte_printf("Testing " XSTR(FP0_CHAR) " Something!");
* tte_printf("Testing " FP0_STR " Something!");
* ```
* prints "Testing .0 Something!"
*
@@ -44,16 +36,16 @@ extern const unsigned int gbalatro_sys8Glyphs[192];
*
* @{
*/
#define FP0_CHAR & // .0
#define FP1_CHAR ^ // .1
#define FP2_CHAR } // .2
#define FP3_CHAR { // .3
#define FP4_CHAR | // .4
#define FP5_CHAR ` // .5
#define FP6_CHAR < // .6
#define FP7_CHAR > // .7
#define FP8_CHAR _ // .8
#define FP9_CHAR ; // .9
#define FP0_STR "&" // .0
#define FP1_STR "^" // .1
#define FP2_STR "}" // .2
#define FP3_STR "{" // .3
#define FP4_STR "|" // .4
#define FP5_STR "`" // .5
#define FP6_STR "<" // .6
#define FP7_STR ">" // .7
#define FP8_STR "_" // .8
#define FP9_STR ";" // .9
/** @} */
/**
@@ -67,4 +59,15 @@ extern const unsigned int gbalatro_sys8Glyphs[192];
*/
const char* get_font_point_str(int val);
/**
* @brief Get the decimal point char equivalent of 0-9 from char param.
*
* @param digit_char A char of a digit between '0'-'9' to get '.0' to '.9' equivalents. Note that
* if a char outside of range is passed it the return value will be within limits
* but is not defined with any relationship to the input.
*
* @return A char representing a value in the font within the range of '.0' to '.9'
*/
char digit_char_to_font_point(char digit_char);
#endif // FONT_H
+9
View File
@@ -0,0 +1,9 @@
#ifndef GBALATRO_SYS8_FONT_H
#define GBALATRO_SYS8_FONT_H
#include <tonc.h>
extern const TFont gbalatro_sys8Font;
extern const unsigned int gbalatro_sys8Glyphs[192];
#endif