gen2brain / raylib-go

Go bindings for raylib, a simple and easy-to-use library to enjoy videogames programming.
zlib License
1.36k stars 146 forks source link

Unable to remove status bar from raygui Panels #386

Closed michaeldelgado1 closed 2 weeks ago

michaeldelgado1 commented 2 weeks ago

Code example:

container := rl.Rectangle{
  X: 20,
  Y: 20,
  Width: 100,
  Height: 100,
}

rg.Panel(container, "")

Expected Result: A panel is drawn with no status bar

Actual Result: A panel is drawn with a status bar and no text

gen2brain commented 2 weeks ago

Why do you think that the expected result is a panel with no status bar? Does that behavior differ from C behavior? The function just says bounds and text, with no mention of the status bar.

michaeldelgado1 commented 2 weeks ago

Yes it's in the C implementation. https://github.com/raysan5/raygui/blob/12804826d01bfb636e36f816bda19eaa23b4ace7/src/raygui.h#L1793

I've used it pretty recently. I'm not familiar with cgo, but if you do a length check in the string, I assume you can pass null instead of a blank string.

michaeldelgado1 commented 2 weeks ago

Here's a better link: https://github.com/raysan5/raygui/blob/12804826d01bfb636e36f816bda19eaa23b4ace7/src/raygui.h#L1891

gen2brain commented 2 weeks ago

Some reproducible example would be nice, you mention Panel, and then you link to ScrollPanel. I am guessing based on the checks you sent that some function should pass nil if the string is empty but that is just a guess.

michaeldelgado1 commented 2 weeks ago

The implementation is the same for both panel and scroll panel... https://github.com/raysan5/raygui/blob/12804826d01bfb636e36f816bda19eaa23b4ace7/src/raygui.h#L1693

As far as an example goes, I don't have much time to provide one at the moment. Both your project and the original C implement have Scroll panel examples. It's possible to check those

JupiterRider commented 2 weeks ago

Some reproducible example would be nice, you mention Panel, and then you link to ScrollPanel. I am guessing based on the checks you sent that some function should pass nil if the string is empty but that is just a guess.

@gen2brain I think you are right.

Here is the current state (I ran the example gui/scroll_panel/scroll_panel.go): Screenshot_20240516_190912

And here with a nil passed (https://github.com/JupiterRider/raylib-go/commit/c212c3388657742aa15f3996db911dac0cf53961): Screenshot_20240516_190942

michaeldelgado1 commented 2 weeks ago

Nice implementation @JupiterRider my only gripe would be to do a nil check in the free so we don't attempt to free a nil pointer

JupiterRider commented 2 weeks ago

@michaeldelgado1 The free is inside the if statement:

var ctext *C.char
if len(text) > 0 {
    ctext = C.CString(text)
    defer C.free(unsafe.Pointer(ctext))
}
michaeldelgado1 commented 2 weeks ago

I totally missed that. Thanks for pointing it out. I was reading on mobile 🤦

gen2brain commented 2 weeks ago

@JupiterRider Nice, can you send the PR? Is that the only function/place where it needs nil?

JupiterRider commented 2 weeks ago

@gen2brain I don't know every place, where a NULL string affects the appearance, but C-raygui has NULL-checks, so we can safely pass them instead of an empty string.