Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible type casting mismatch in GuiListViewEx Binding #5

Open
mr-ema opened this issue Jan 6, 2024 · 0 comments
Open

Possible type casting mismatch in GuiListViewEx Binding #5

mr-ema opened this issue Jan 6, 2024 · 0 comments

Comments

@mr-ema
Copy link

mr-ema commented Jan 6, 2024

Hey, I was creating something similar to raygui custom file dialog for my project but the GuiListViewEx function gives me the following type error: expected type '[*c][*c]const u8', found '[*c]const [*:0]const u8'. Changing the type fixed it, however I'm new in Zig and maybe I did something wrong.

zig version: 0.12.0-dev.1849+bb0f7d55e
raygui.zig commit: 78c8855



Example:

// dir_files.paths ->  [*][*:0]u8
// const paths: [*]const [*:0]const u8 = @ptrCast(state.dir_files.paths);

// This fails too:
const string_arr = [_][*:0]const u8{ "String1", "String2", "String3" };
const paths = &string_arr;

_ = raygui.GuiListViewEx(.{
    .x = state.window_bounds.x + 8,
    .y = state.window_bounds.y + 48 + 20,
    .width = state.window_bounds.width - 16,
    .height = state.window_bounds.height - 60 - 16 - 68,
  },
  paths,
  @bitCast(state.dir_files.count),
  &state.files_list_scroll_index,
  &state.files_list_active,
  &state.item_focused
);


Compiler Error:

libs/raygui/raygui.zig:604:9: error: expected type '[*c][*c]const u8', found '[*c]const [*:0]const u8'
libs/raygui/raygui.zig:604:9: note: cast discards const qualifier


Original Function:

pub fn GuiListViewEx(
    bounds: Rectangle,
    text: [*]const [*:0]const u8,
    count: i32,
    scrollIndex: *i32,
    active: *i32,
    focus: *i32,
) i32 {
    return raygui.mGuiListViewEx(
        @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))),
        @as([*c]const [*:0]const u8, @ptrFromInt(@intFromPtr(text))),
        count,
        @as([*c]i32, @ptrCast(scrollIndex)),
        @as([*c]i32, @ptrCast(active)),
        @as([*c]i32, @ptrCast(focus)),
    );
}


Possible Solution:

pub fn GuiListViewEx(
    bounds: Rectangle,
    text: [*]const [*:0]const u8,
    count: i32,
    scrollIndex: *i32,
    active: *i32,
    focus: *i32,
) i32 {
    return raygui.mGuiListViewEx(
        @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))),

       --> @as([*c][*c]const u8, @ptrFromInt(@intFromPtr(text))), <--

        count,
        @as([*c]i32, @ptrCast(scrollIndex)),
        @as([*c]i32, @ptrCast(active)),
        @as([*c]i32, @ptrCast(focus)),
    );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant