raygui icon indicating copy to clipboard operation
raygui copied to clipboard

`GuiListView()` always returns 0

Open terenctbrobots opened this issue 10 months ago • 3 comments

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?

terenctbrobots avatar Jan 05 '25 00:01 terenctbrobots

GuiListViewEx initializes result value at the top, here https://github.com/raysan5/raygui/blob/54bff64d7dbaefea877b0b2e32323761fc5692f2/src/raygui.h#L3389-L3391 and then it just returns it at the very end, here https://github.com/raysan5/raygui/blob/54bff64d7dbaefea877b0b2e32323761fc5692f2/src/raygui.h#L3532-L3534 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 avatar Jan 25 '25 19:01 sleeptightAnsiC

Same issue as https://github.com/raysan5/raygui/issues/439 , https://github.com/raysan5/raygui/issues/402 and https://github.com/raysan5/raygui/issues/371

sleeptightAnsiC avatar Jan 25 '25 19:01 sleeptightAnsiC

@terenctbrobots Yeah, return values should be reviewed: https://github.com/raysan5/raygui/issues/402

raysan5 avatar Feb 01 '25 20:02 raysan5