raygui icon indicating copy to clipboard operation
raygui copied to clipboard

``TextToFloat`` was not declared in this scope when compiling a raygui program

Open Justaus3r opened this issue 1 year ago • 7 comments

Whenever i compile the example given in raygui Readme or any other source file that uses raygui. It errors out on following:

In file included from tst.cpp:4:
C:\raylib\raylib\src/raygui.h: In function 'int GuiGroupBox(Rectangle, const char*)':
C:\raylib\raylib\src/raygui.h:1624:180: warning: enumerated mismatch in conditional expression: 'GuiControlProperty' vs 'GuiDefaultProperty' [-Wenum-compare]
 1624 |     GuiDrawRectangle(RAYGUI_CLITERAL(Rectangle){ bounds.x, bounds.y, RAYGUI_GROUPBOX_LINE_THICK, bounds.height }, 0, BLANK, GetColor(GuiGetStyle(DEFAULT, (state == STATE_DISABLED)? BORDER_COLOR_DISABLED : LINE_COLOR)));
      |
              ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\raylib\raylib\src/raygui.h:1625:199: warning: enumerated mismatch in conditional expression: 'GuiControlProperty' vs 'GuiDefaultProperty' [-Wenum-compare]
 1625 |     GuiDrawRectangle(RAYGUI_CLITERAL(Rectangle){ bounds.x, bounds.y + bounds.height - 1, bounds.width, RAYGUI_GROUPBOX_LINE_THICK }, 0, BLANK, GetColor(GuiGetStyle(DEFAULT, (state == STATE_DISABLED)? BORDER_COLOR_DISABLED : LINE_COLOR)));
      |
                                 ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\raylib\raylib\src/raygui.h:1626:199: warning: enumerated mismatch in conditional expression: 'GuiControlProperty' vs 'GuiDefaultProperty' [-Wenum-compare]
 1626 |     GuiDrawRectangle(RAYGUI_CLITERAL(Rectangle){ bounds.x + bounds.width - 1, bounds.y, RAYGUI_GROUPBOX_LINE_THICK, bounds.height }, 0, BLANK, GetColor(GuiGetStyle(DEFAULT, (state == STATE_DISABLED)? BORDER_COLOR_DISABLED : LINE_COLOR)));
      |
                                 ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\raylib\raylib\src/raygui.h: In function 'int GuiLine(Rectangle, const char*)':
C:\raylib\raylib\src/raygui.h:1647:74: warning: enumerated mismatch in conditional expression: 'GuiControlProperty' vs 'GuiDefaultProperty' [-Wenum-compare]
 1647 |     Color color = GetColor(GuiGetStyle(DEFAULT, (state == STATE_DISABLED)? BORDER_COLOR_DISABLED : LINE_COLOR));
      |                                                 ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\raylib\raylib\src/raygui.h: In function 'int GuiPanel(Rectangle, const char*)':
C:\raylib\raylib\src/raygui.h:1695:112: warning: enumerated mismatch in conditional expression: 'GuiControlProperty' vs 'GuiDefaultProperty' [-Wenum-compare]
 1695 |     GuiDrawRectangle(bounds, RAYGUI_PANEL_BORDER_WIDTH, GetColor(GuiGetStyle(DEFAULT, (state == STATE_DISABLED)? BORDER_COLOR_DISABLED: LINE_COLOR)),
      |                                                                                       ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\raylib\raylib\src/raygui.h:1696:77: warning: enumerated mismatch in conditional expression: 'GuiControlProperty' vs 'GuiDefaultProperty' [-Wenum-compare]
 1696 |                      GetColor(GuiGetStyle(DEFAULT, (state == STATE_DISABLED)? BASE_COLOR_DISABLED : BACKGROUND_COLOR)));
      |                                                    ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\raylib\raylib\src/raygui.h: In function 'int GuiValueBoxFloat(Rectangle, const char*, char*, float*, bool)':
C:\raylib\raylib\src/raygui.h:3009:43: error: 'TextToFloat' was not declared in this scope
 3009 |             if (valueHasChanged) *value = TextToFloat(textValue);
      |                                           ^~~~~~~~~~~

At first i thought, i was using incompatible versions with raylib or something. I changed those but it didn't help. I tried with cmake toolchain, installing the packages with vcpkg. But the same error persists. Raylib works perfectly fine for me. The problem only occurs when i try to include raygui. Here's the Screenshot: image

I am on WIndows 11 with w64devkit and gcc V 13.2.0

Justaus3r avatar May 28 '24 20:05 Justaus3r

The following function can be moved from raygui.h to raylib.h

// in raygui.h
static float TextToFloat(const char *text)

raylib.h has similar functions but doesn't include the TextToFloat(const char *text)

// in raylib.h
RLAPI const char *TextToPascal(const char *text);      // Get Pascal case notation version of provided string
RLAPI int TextToInteger(const char *text);            // Get integer value from text (negative values not supported)
.
.

emrekz avatar Jun 01 '24 21:06 emrekz

i had this same issue, and it's caused by a mismatch in the version of raygui and raylib. basically, if you're using the 5.0.1 version of raylib (which is what you'd get from either the releases page or from a package manager), and then try to use the most recent raygui from this repo, you'll get errors since raygui ends up relying on raylib features that aren't yet in the newest released version (like texttofloat). to fix this you can either build raylib from source as described in the raylib wiki, and continue to use the newest possible raygui, or you can use the 5.0.1 version of raylib with something like the 4.0 release of raygui.

sprinkuls avatar Jun 08 '24 02:06 sprinkuls

i had this same issue, and it's caused by a mismatch in the version of raygui and raylib. basically, if you're using the 5.0.1 version of raylib (which is what you'd get from either the releases page or from a package manager), and then try to use the most recent raygui from this repo, you'll get errors since raygui ends up relying on raylib features that aren't yet in the newest released version (like texttofloat). to fix this you can either build raylib from source as described in the raylib wiki, and continue to use the newest possible raygui, or you can use the 5.0.1 version of raylib with something like the 4.0 release of raygui.

Thank you. I did try to build raylib from source and then use the latest version of raygui with it. But the personally built version also didn't work with raygui for me and it kept giving me the same error. In the end I just ditched raygui and ended up going with raylib only for my semester project

Justaus3r avatar Jun 08 '24 08:06 Justaus3r

I had the same issue, but I just put the function from raygui.h

static float TextToFloat(const char *text)
{
...
}

before this function, which is the one screaming

int GuiValueBoxFloat()

And now I can compile without any errors. I'm using raylib/5.0.0 and the latest raygui/4.1-dev

GuillemRamisa avatar Jun 10 '24 15:06 GuillemRamisa

so last raylib and last raygui isnt working....

komatr-supra avatar Jun 12 '24 20:06 komatr-supra

I had the same issue, but I just put the function from raygui.h

static float TextToFloat(const char *text)
{
...
}

before this function, which is the one screaming

int GuiValueBoxFloat()

And now I can compile without any errors. I'm using raylib/5.0.0 and the latest raygui/4.1-dev

Can confirm, works like a charm! Raylib from pkgmanager, versions of raygui and raylib are the same as yours. Thank you :)

413x1nkp avatar Jun 14 '24 20:06 413x1nkp

its working with vcpkg.

komatr-supra avatar Jun 15 '24 07:06 komatr-supra

Made a quick patch to fix the issue. Here it is:

--- a/raygui.h	2024-08-06 06:18:52.461047534 +0700
+++ b/raygui.h	2024-08-06 06:18:15.813622145 +0700
@@ -2971,6 +2971,37 @@
     return result;
 }
 
+// Get float value from text
+// NOTE: This function replaces atof() [stdlib.h]
+// WARNING: Only '.' character is understood as decimal point
+static float TextToFloat(const char *text)
+{
+    float value = 0.0f;
+    float sign = 1.0f;
+
+    if ((text[0] == '+') || (text[0] == '-'))
+    {
+        if (text[0] == '-') sign = -1.0f;
+        text++;
+    }
+
+    int i = 0;
+    for (; ((text[i] >= '0') && (text[i] <= '9')); i++) value = value*10.0f + (float)(text[i] - '0');
+
+    if (text[i++] != '.') value *= sign;
+    else
+    {
+        float divisor = 10.0f;
+        for (; ((text[i] >= '0') && (text[i] <= '9')); i++)
+        {
+            value += ((float)(text[i] - '0'))/divisor;
+            divisor = divisor*10.0f;
+        }
+    }
+
+    return value;
+}
+
 // Floating point Value Box control, updates input val_str with numbers
 // NOTE: Requires static variables: frameCounter
 int GuiValueBoxFloat(Rectangle bounds, const char *text, char *textValue, float *value, bool editMode)
@@ -5605,37 +5636,6 @@
     return value*sign;
 }
 
-// Get float value from text
-// NOTE: This function replaces atof() [stdlib.h]
-// WARNING: Only '.' character is understood as decimal point
-static float TextToFloat(const char *text)
-{
-    float value = 0.0f;
-    float sign = 1.0f;
-
-    if ((text[0] == '+') || (text[0] == '-'))
-    {
-        if (text[0] == '-') sign = -1.0f;
-        text++;
-    }
-
-    int i = 0;
-    for (; ((text[i] >= '0') && (text[i] <= '9')); i++) value = value*10.0f + (float)(text[i] - '0');
-
-    if (text[i++] != '.') value *= sign;
-    else
-    {
-        float divisor = 10.0f;
-        for (; ((text[i] >= '0') && (text[i] <= '9')); i++)
-        {
-            value += ((float)(text[i] - '0'))/divisor;
-            divisor = divisor*10.0f;
-        }
-    }
-
-    return value;
-}
-
 // Encode codepoint into UTF-8 text (char array size returned as parameter)
 static const char *CodepointToUTF8(int codepoint, int *byteSize)
 {

To apply just do patch raygui.h -p1 < this.patch

413x1nkp avatar Aug 05 '24 23:08 413x1nkp

Made a quick patch to fix the issue. Here it is:

--- a/raygui.h	2024-08-06 06:18:52.461047534 +0700
+++ b/raygui.h	2024-08-06 06:18:15.813622145 +0700
@@ -2971,6 +2971,37 @@
     return result;
 }
 
+// Get float value from text
+// NOTE: This function replaces atof() [stdlib.h]
+// WARNING: Only '.' character is understood as decimal point
+static float TextToFloat(const char *text)
+{
+    float value = 0.0f;
+    float sign = 1.0f;
+
+    if ((text[0] == '+') || (text[0] == '-'))
+    {
+        if (text[0] == '-') sign = -1.0f;
+        text++;
+    }
+
+    int i = 0;
+    for (; ((text[i] >= '0') && (text[i] <= '9')); i++) value = value*10.0f + (float)(text[i] - '0');
+
+    if (text[i++] != '.') value *= sign;
+    else
+    {
+        float divisor = 10.0f;
+        for (; ((text[i] >= '0') && (text[i] <= '9')); i++)
+        {
+            value += ((float)(text[i] - '0'))/divisor;
+            divisor = divisor*10.0f;
+        }
+    }
+
+    return value;
+}
+
 // Floating point Value Box control, updates input val_str with numbers
 // NOTE: Requires static variables: frameCounter
 int GuiValueBoxFloat(Rectangle bounds, const char *text, char *textValue, float *value, bool editMode)
@@ -5605,37 +5636,6 @@
     return value*sign;
 }
 
-// Get float value from text
-// NOTE: This function replaces atof() [stdlib.h]
-// WARNING: Only '.' character is understood as decimal point
-static float TextToFloat(const char *text)
-{
-    float value = 0.0f;
-    float sign = 1.0f;
-
-    if ((text[0] == '+') || (text[0] == '-'))
-    {
-        if (text[0] == '-') sign = -1.0f;
-        text++;
-    }
-
-    int i = 0;
-    for (; ((text[i] >= '0') && (text[i] <= '9')); i++) value = value*10.0f + (float)(text[i] - '0');
-
-    if (text[i++] != '.') value *= sign;
-    else
-    {
-        float divisor = 10.0f;
-        for (; ((text[i] >= '0') && (text[i] <= '9')); i++)
-        {
-            value += ((float)(text[i] - '0'))/divisor;
-            divisor = divisor*10.0f;
-        }
-    }
-
-    return value;
-}
-
 // Encode codepoint into UTF-8 text (char array size returned as parameter)
 static const char *CodepointToUTF8(int codepoint, int *byteSize)
 {

To apply just do patch raygui.h -p1 < this.patch

Works super fine

Siddharth1India avatar Sep 01 '24 04:09 Siddharth1India

This needs to be added to the main repo. I could not get my code to compile until I used this patch.

JerC4 avatar Nov 17 '24 17:11 JerC4

I must agree. At the time, i just went with raylib. But now coming back to raygui. i can't use it without applying the patch first

Justaus3r avatar Dec 09 '24 14:12 Justaus3r