Skip to content

Commit 95234d1

Browse files
authored
[rgui] gui_panel handles empty str (#150)
Restores the 5.0 usage for gui_panel(), which allowed None. Previously, passing None would cause a NULL pointer to be get to GuiPanel(), effectively avoiding the rendering of the panel label.
1 parent 0a9e8b2 commit 95234d1

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

raylib/src/rgui/safe.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,14 @@ pub trait RaylibDrawGui {
218218
/// Panel control, useful to group controls
219219
#[inline]
220220
fn gui_panel(&mut self, bounds: impl Into<ffi::Rectangle>, text: &str) -> bool {
221-
let c_filename = CString::new(text).unwrap();
222-
unsafe { ffi::GuiPanel(bounds.into(), c_filename.as_ptr()) > 0 }
221+
let cstr: CString;
222+
let c_text = if text.is_empty() {
223+
std::ptr::null()
224+
} else {
225+
cstr = CString::new(text).unwrap();
226+
cstr.as_ptr()
227+
};
228+
unsafe { ffi::GuiPanel(bounds.into(), c_text) > 0 }
223229
}
224230
/// Scroll Panel control
225231
#[inline]

0 commit comments

Comments
 (0)