Closed Raidez closed 1 year ago
@Raidez I'm afraid that's not possible on current raygui implementation, keep in mind that raygui is an immediate-mode library and it implies some limitations.
Not sure if I really understood your issue, just re-reading it... you can just enable a boolean on button pressed, for example:
bool enabledOption = false;
...
if (GuiButton(WIDHT/2 - 50, HEIGHT/2 + 80, 100, 30), "press me")) enabledOption = !enabledOption;
if (enabledOption)
{
// Do/draw something
}
It will enable/disable some option every time the button is pressed.
The problem is when I click on the GuiButton, it trigger the IsMouseButtonPressed too. I found a wacky way :
from raylib import *
# define constants
WIDHT, HEIGHT = 800, 450
TITLE = b"RPG : Dice & Retry"
FPS = 60
################################################################################
InitWindow(WIDHT, HEIGHT, TITLE) # type: ignore
InitPhysics()
SetTargetFPS(FPS)
enabledOption = False
# main loop
while not WindowShouldClose():
# update
UpdatePhysics()
# check if GuiButton presed first
if GuiButton((WIDHT // 2 - 50, HEIGHT // 2 + 80, 100, 30), b"press me"):
enabledOption = not enabledOption
elif IsMouseButtonReleased(MOUSE_BUTTON_LEFT): # check mouse button release only
CreatePhysicsBodyCircle(GetMousePosition(), GetRandomValue(10, 45), 10)
# draw
BeginDrawing()
ClearBackground(BLACK)
if enabledOption:
ClearBackground(WHITE)
for i in range(GetPhysicsBodiesCount()):
if body := GetPhysicsBody(i):
vertices_count = GetPhysicsShapeVerticesCount(i)
for j in range(vertices_count):
vertex0 = GetPhysicsShapeVertex(body, j)
jj = j + 1 if j + 1 < vertices_count else 0
vertex1 = GetPhysicsShapeVertex(body, jj)
DrawLineV(vertex0, vertex1, GREEN)
EndDrawing()
# cleanup
ClosePhysics()
CloseWindow()
A simple question but how can I use a simple button but stop the event to not activate the code, when pressing the left mouse button, further.
Yeah, I know it's not C code, but I don't think this problem is specific to Python binding.