From 1ce447208bb583c7623f42b8bcefe9b50eac9554 Mon Sep 17 00:00:00 2001 From: Sara Gerretsen Date: Mon, 22 Sep 2025 21:43:43 +0200 Subject: [PATCH] fix: stepping being inconsistent while running --- src/application.cpp | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/src/application.cpp b/src/application.cpp index f8b3743..52a8410 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -30,23 +30,22 @@ static void StepSimulationButton(Clay_ElementId element, Clay_PointerData pointe } static void StepControl() { - static uint64_t lastStep = 0; - if (isSimulating) { - double deltaTime{ (double)(SDL_GetTicks() - lastStep) * 0.001 }; - if (deltaTime > 0.16) { - simulation::Step(); - } - } - CLAY_AUTO_ID({ + CLAY_AUTO_ID(style::PanelContainer(1, { .layout = { - .childGap = 16 - } - }) { - if (isSimulating) { - elements::TextButton(CLAY_STRING("Pause"), style::warningButton, &SetSimulatingButton, false); - } else { - elements::TextButton(CLAY_STRING("Start"), style::proceedButton, &SetSimulatingButton, true); - elements::TextButton(CLAY_STRING("Step"), style::actionButton, &StepSimulationButton); + .sizing = { CLAY_SIZING_GROW(), CLAY_SIZING_FIT() }, + }, + })) { + CLAY_AUTO_ID({ + .layout = { + .childGap = 16 + } + }) { + if (isSimulating) { + elements::TextButton(CLAY_STRING("Pause"), style::warningButton, &SetSimulatingButton, false); + } else { + elements::TextButton(CLAY_STRING("Start"), style::proceedButton, &SetSimulatingButton, true); + elements::TextButton(CLAY_STRING("Step"), style::actionButton, &StepSimulationButton); + } } } } @@ -131,7 +130,11 @@ static void PrimaryControls() { }) { StepControl(); if (!isSimulating) { - CLAY_AUTO_ID(style::PanelContainer(1, {})) { + CLAY_AUTO_ID(style::PanelContainer(1, { + .layout = { + .sizing = { CLAY_SIZING_GROW(), CLAY_SIZING_FIT() } + } + })) { elements::TextButton(CLAY_STRING("Randomize"), style::actionButton, &RandomizeFieldButton); } } @@ -145,6 +148,13 @@ static void PrimaryControls() { } Clay_RenderCommandArray RenderApplication() { + static uint64_t lastStep = 0; + if (isSimulating) { + double deltaTime{ (double)(SDL_GetTicks() - lastStep) * 0.001 }; + if (deltaTime > 0.16) { + simulation::Step(); + } + } Clay_BeginLayout(); CLAY(CLAY_ID("OuterContainer"), style::Window()) { simulation::SetSimulationHovered(Clay_Hovered());