Browse Source

REVIEWED: custom_input_box #378

Ray 1 year ago
parent
commit
418da225d5
1 changed files with 3 additions and 40 deletions
  1. 3 40
      examples/custom_input_box/custom_input_box.c

+ 3 - 40
examples/custom_input_box/custom_input_box.c

@@ -11,14 +11,13 @@
 *
 **********************************************************************************************/
 
-#include <raylib.h>
+#include "raylib.h"
 
 #define RAYGUI_IMPLEMENTATION
-#include <raygui.h>
+#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)
 {