# Using raygui with raylib

**URL:** <https://ziggit.dev/t/using-raygui-with-raylib/3399>\
**Category:** Help\
**Tags:** ecosystem, raylib\
**Created:** [February 29, 2024, 1:49am UTC](https://ziggit.dev/t/using-raygui-with-raylib/3399 "2024-02-29T01:49:00Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![Sze](https://ziggit.dev/user_avatar/ziggit.dev/sze/32/496_2.png) [@Sze](https://ziggit.dev/u/Sze)\
**Post date:** [February 29, 2024, 10:14am UTC](https://ziggit.dev/t/using-raygui-with-raylib/3399/7 "2024-02-29T10:14:01Z")

</div>

> [@jiangbo](#):
>
> ```zig
> fileDataPtr += @as([*c]u8, @ptrFromInt(@sizeOf(c_int)));
> ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> ```

I also got that error.  
I modified the source to ~~`fileDataPtr += @as(usize, @sizeOf(c_int));`~~ to make it more similar like other lines and with that I got a few similar errors.  
(I currently don’t know why these don’t get generated correctly, automatically)

After that it compiled and segfaulted, because of a null pointer being dereferenced.  
I had to change the code to:

```zig
    ...
    const rec = ray.Rectangle{ .x = 600, .y = 40, .width = 120, .height = 20 };
    var value: f32 = 0;

    while (!ray.WindowShouldClose()) {

        // Update

        // Draw
        ray.BeginDrawing();
        defer ray.EndDrawing();
        ray.ClearBackground(ray.RAYWHITE);

        _ = ray.GuiSliderBar(rec, "StartAngle", null, &value, -450, 450);

        ray.DrawFPS(10, 10);
    }

```

The `&value` parameter expects a pointer to a float variable that can be set to the value of the slider.

With that it worked.

It seems the cImport generates code that doesn’t work, I wonder whether there are more cases in other functions (that just aren’t used yet).  
I don’t know whether there is a general solution to this, or if maybe raygui uses something that isn’t well supported by cImport.  
~~It seems the `sscanf` calls in `GuiLoadStyle` don’t always get converted correctly.~~

* * *

> <https://github.com/raysan5/raygui/blob/bc67f42209cc32965c7d1c00028e3ed0c4158659/src/raygui.h#L4429>

Somehow becomes:

```zig
fileDataPtr += @as([*c]u8, @ptrFromInt(@sizeOf(c_int)));

```

I think it should just be:

```zig
fileDataPtr += @as(usize, @intCast(recsDataCompressedSize));
// and the next ones:
// fileDataPtr += @as([*c]u8, @ptrFromInt(@sizeOf(Rectangle)));
fileDataPtr += @as(usize, @sizeOf(Rectangle));
// fileDataPtr += @as([*c]u8, @ptrFromInt(@sizeOf(c_int)));
fileDataPtr += @as(usize, @sizeOf(c_int));

```

It seems cImport gets confused by the pointer arithmetic and instead wants to add a pointer to the pointer instead of adding an integer value to the pointer.

* * *

Edit:  
I think the whole issue can be avoided by only applying translate-c to the cImported header file of raygui, but using a c source file for the implementation part. Raylib does this in its `build.zig`: [raylib/src/build.zig at 30f9ca7eb60d527e623066bbdc7257474da2baef · raysan5/raylib · GitHub](https://github.com/raysan5/raylib/blob/30f9ca7eb60d527e623066bbdc7257474da2baef/src/build.zig#L239)

This uses raygui directly via the `addRaylib` function provided by raylib: [Adding raygui · Issue #5 · SimonLSchlee/zigraylib · GitHub](https://github.com/SimonLSchlee/zigraylib/issues/5) and commit [added raygui #5 · SimonLSchlee/zigraylib@60b2ed0 · GitHub](https://github.com/SimonLSchlee/zigraylib/commit/60b2ed0af9634421a936308152315c0017194c3b)

---

_[View the full topic](https://ziggit.dev/t/using-raygui-with-raylib/3399)._
