REVIEWED: custom_input_box #378
This commit is contained in:
parent
58411f4cce
commit
418da225d5
@ -11,14 +11,13 @@
|
|||||||
*
|
*
|
||||||
**********************************************************************************************/
|
**********************************************************************************************/
|
||||||
|
|
||||||
#include <raylib.h>
|
#include "raylib.h"
|
||||||
|
|
||||||
#define RAYGUI_IMPLEMENTATION
|
#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 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()
|
int main()
|
||||||
@ -83,42 +82,6 @@ int main()
|
|||||||
CloseWindow();
|
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
|
// Float Box control, updates input text with numbers
|
||||||
int GuiFloatBox(Rectangle bounds, const char* text, float* value, int minValue, int maxValue, bool editMode)
|
int GuiFloatBox(Rectangle bounds, const char* text, float* value, int minValue, int maxValue, bool editMode)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user