From 418da225d547c8145d860d36bfcb40bc22fb626d Mon Sep 17 00:00:00 2001 From: Ray Date: Sat, 3 Feb 2024 19:59:59 +0100 Subject: [PATCH] REVIEWED: custom_input_box #378 --- examples/custom_input_box/custom_input_box.c | 43 ++------------------ 1 file changed, 3 insertions(+), 40 deletions(-) diff --git a/examples/custom_input_box/custom_input_box.c b/examples/custom_input_box/custom_input_box.c index bb2b991..f5d91d0 100644 --- a/examples/custom_input_box/custom_input_box.c +++ b/examples/custom_input_box/custom_input_box.c @@ -11,14 +11,13 @@ * **********************************************************************************************/ -#include +#include "raylib.h" #define RAYGUI_IMPLEMENTATION -#include +#include "raygui.h" -int guiFloatingPointIndex = 0; // Global variable shared by all GuiFLoatBox() +int guiFloatingPointIndex = 0; // Global variable shared by all GuiFloatBox() -float TextToFloat(const char* text); // Helper function that converts text to float int GuiFloatBox(Rectangle bounds, const char* text, float* value, int minValue, int maxValue, bool editMode); // Custom input box that works with float values. Basicly GuiValueBox(), but with some changes int main() @@ -83,42 +82,6 @@ int main() CloseWindow(); } -// Get float value from text -float TextToFloat(const char* text) -{ - float value = 0.0f; - float floatingPoint = 0.0f; - int sign = 1; - - // deal with the sign - if ((text[0] == '+') || (text[0] == '-')) - { - if (text[0] == '-') sign = -1; - text++; - } - - // convert text to float - for (int i = 0; (((text[i] >= '0') && (text[i] <= '9')) || text[i] == '.'); i++) - { - if (text[i] == '.') - { - if (floatingPoint > 0.0f) break; - - floatingPoint = 10.0f; - continue; - } - if (floatingPoint > 0.0f) // after encountering decimal separator - { - value += (float)(text[i] - '0') / floatingPoint; - floatingPoint *= 10.0f; - } - else // before decimal separator - value = value * 10.0f + (float)(text[i] - '0'); - } - - return value * sign; -} - // Float Box control, updates input text with numbers int GuiFloatBox(Rectangle bounds, const char* text, float* value, int minValue, int maxValue, bool editMode) {