From 3a911db3127165cfb0837457ebd9df1d421d86bc Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Fri, 26 Jul 2024 20:40:16 +0100 Subject: Helper to draw a fraction as text at point (x, y) --- src/main.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index f33fb55..aae5b72 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -55,6 +55,14 @@ constexpr word_t clamp_to_width(long double value, long double min, return WIDTH / (max - min) * (value - min); } +void draw_fraction(Fraction f, word_t x, word_t y) +{ + std::string s{to_string(f)}; + // Centered at (x, y) + int width = MeasureText(s.c_str(), FONT_SIZE); + DrawText(s.c_str(), x - width / 2, y - FONT_SIZE, FONT_SIZE, WHITE); +} + int main(void) { // NodeAllocator allocator{256}; -- cgit v1.2.3-13-gbd6f