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

GuiListView() always returns 0 #448

Open
terenctbrobots opened this issue Jan 5, 2025 · 3 comments
Open

GuiListView() always returns 0 #448

terenctbrobots opened this issue Jan 5, 2025 · 3 comments

Comments

@terenctbrobots
Copy link

terenctbrobots commented Jan 5, 2025

Currently with this code:

 m_GameObjectSelect =  GuiListView(m_GameObjectListBounds,m_GameObjectListString.c_str(),&m_GameObjectScrollIndex,&m_GameObjectActive);

     spdlog::info("GameObject select {}",m_GameObjectSelect);
     
     if (m_GameObjectActive != -1) 
     {
        spdlog::info("GameObject active {}",m_GameObjectActive);
     }

m_GameObjectSelect is always 0. Shouldnt it be > 0?

@sleeptightAnsiC
Copy link

sleeptightAnsiC commented Jan 25, 2025

GuiListViewEx initializes result value at the top, here

raygui/src/raygui.h

Lines 3389 to 3391 in 54bff64

int GuiListViewEx(Rectangle bounds, const char **text, int count, int *scrollIndex, int *active, int *focus)
{
int result = 0;

and then it just returns it at the very end, here

raygui/src/raygui.h

Lines 3532 to 3534 in 54bff64

return result;
}

but it does not set it anywhere, also there are no early returns from this function, it returns 0 in all cases.

There are a lot of functions that work this way: GuiGroupBox, GuiLine, GuiPanel, GuiScrollPanel, GuiLabel, GuiToggle, GuiToggleGroup, GuiComboBox, GuiProgressBar, GuiStatusBar, GuiDummyRec, GuiListViewEx, GuiColorPanel, GuiColorBarAlpha, GuiColorBarHue, GuiColorPicke, GuiColorPickerHSV, GuiColorPanelHSV, GuiGrid.

This is probably for Forward/Backward Compatibility and for consistency with other functions. All those mentioned functions are usually never expect to fail nor to execute abnormally, and most of them return values by pointer.

For example, GuiListView returns its internal state with int *scrollIndex and int *active parameters.
In your case you should check m_GameObjectActive value to know which value is selected.
Or you may wanna use GuiListViewEx (with Ex) as it also accepts int *focus.

@sleeptightAnsiC
Copy link

sleeptightAnsiC commented Jan 25, 2025

Same issue as #439 , #402 and #371

@raysan5
Copy link
Owner

raysan5 commented Feb 1, 2025

@terenctbrobots Yeah, return values should be reviewed: #402

@raysan5 raysan5 changed the title GuiListView always returns 0 GuiListView() always returns 0 Feb 1, 2025
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

3 participants