Repository: libsdl-org/SDL
File: test/gamepadutils.c (C)

Code before:
        SDL_snprintf(label_text, sizeof(label_text), "Noise Progress: %3.0f%% ", ctx->calibration_phase_progress_fraction * 100.0f);
    } else if (ctx->current_calibration_phase == GYRO_CALIBRATION_PHASE_DRIFT_PROFILING) {
        SDL_snprintf(label_text, sizeof(label_text), "Drift Progress: %3.0f%% ", ctx->calibration_phase_progress_fraction * 100.0f);
    } else if (ctx->current_calibration_phase == GYRO_CALIBRATION_PHASE_COMPLETE) {
        SDL_strlcpy(label_text, "Recalibrate Gyro", sizeof(label_text));
    }

    SetGamepadButtonLabel(start_calibration_button, label_text);
    SetGamepadButtonArea(start_calibration_button, &recalibrate_button_area);
    RenderGamepadButton(start_calibration_button);  

    bool bExtremeNoise = ctx->accelerometer_noise_sq > ACCELEROMETER_MAX_NOISE_G_SQ;
    /* Explicit warning message if we detect too much movement */
    if (ctx->current_calibration_phase == GYRO_CALIBRATION_PHASE_OFF) {
        
        if (bExtremeNoise)
        {
            SDL_strlcpy(label_text, "GamePad Must Be Still", sizeof(label_text));
            SDLTest_DrawString(ctx->renderer, recalibrate_button_area.x, recalibrate_button_area.y + recalibrate_button_area.h + new_line_height, label_text);
            SDL_strlcpy(label_text, "Place GamePad On Table", sizeof(label_text));
            SDLTest_DrawString(ctx->renderer, recalibrate_button_area.x, recalibrate_button_area.y + recalibrate_button_area.h + new_line_height * 2, label_text);
        }
    }

    if (ctx->current_calibration_phase == GYRO_CALIBRATION_PHASE_NOISE_PROFILING
        || ctx->current_calibration_phase == GYRO_CALIBRATION_PHASE_DRIFT_PROFILING)
    {
        float flAbsoluteNoiseFraction = SDL_clamp(ctx->accelerometer_noise_sq / ACCELEROMETER_MAX_NOISE_G_SQ, 0.0f, 1.0f);
        float flAbsoluteToleranceFraction = SDL_clamp(ctx->accelerometer_noise_tolerance_sq / ACCELEROMETER_MAX_NOISE_G_SQ, 0.0f, 1.0f);

        float flMaxNoiseForThisPhase = ctx->current_calibration_phase == GYRO_CALIBRATION_PHASE_NOISE_PROFILING ? ACCELEROMETER_MAX_NOISE_G_SQ : ctx->accelerometer_noise_tolerance_sq;
        float flRelativeNoiseFraction = SDL_clamp(ctx->accelerometer_noise_sq / flMaxNoiseForThisPhase, 0.0f, 1.0f);

        float noise_bar_height = gamepad_display->button_height;
        SDL_FRect noise_bar_rect;
        noise_bar_rect.x = recalibrate_button_area.x;
        noise_bar_rect.y = recalibrate_button_area.y + recalibrate_button_area.h + BUTTON_PADDING;
        noise_bar_rect.w = recalibrate_button_area.w;
        noise_bar_rect.h = noise_bar_height;

        SDL_snprintf(label_text, sizeof(label_text), "Accelerometer Noise Tolerance: %3.3fG ", SDL_sqrtf(ctx->accelerometer_noise_tolerance_sq) );
        SDLTest_DrawString(ctx->renderer, recalibrate_button_area.x, recalibrate_button_area.y + recalibrate_button_area.h + new_line_height * 2, label_text);

        /* Adjust the noise bar rectangle based on the accelerometer noise value */
        float noise_bar_fill_width = flAbsoluteNoiseFraction * noise_bar_rect.w; /* Scale the width based on the noise value */
        SDL_FRect noise_bar_fill_rect;
        noise_bar_fill_rect.x = noise_bar_rect.x + (noise_bar_rect.w - noise_bar_fill_width) * 0.5f;
        noise_bar_fill_rect.y = noise_bar_rect.y;
        noise_bar_fill_rect.w = noise_bar_fill_width;
        noise_bar_fill_rect.h = noise_bar_height;


Review comment (suggestion):
```suggestion
    if (ctx->current_calibration_phase == GYRO_CALIBRATION_PHASE_NOISE_PROFILING ||
        ctx->current_calibration_phase == GYRO_CALIBRATION_PHASE_DRIFT_PROFILING)
```

Code after:
        SDL_snprintf(label_text, sizeof(label_text), "Drift Progress: %3.0f%% ", ctx->calibration_phase_progress_fraction * 100.0f);
    } else if (ctx->current_calibration_phase == GYRO_CALIBRATION_PHASE_COMPLETE) {
        SDL_strlcpy(label_text, "Recalibrate Gyro", sizeof(label_text));
    }

    SetGamepadButtonLabel(start_calibration_button, label_text);
    SetGamepadButtonArea(start_calibration_button, &recalibrate_button_area);
    RenderGamepadButton(start_calibration_button);

    bool bExtremeNoise = ctx->accelerometer_noise_sq > ACCELEROMETER_MAX_NOISE_G_SQ;
    /* Explicit warning message if we detect too much movement */
    if (ctx->current_calibration_phase == GYRO_CALIBRATION_PHASE_OFF) {
        if (bExtremeNoise) {
            SDL_strlcpy(label_text, "GamePad Must Be Still", sizeof(label_text));
            SDLTest_DrawString(ctx->renderer, recalibrate_button_area.x, recalibrate_button_area.y + recalibrate_button_area.h + new_line_height, label_text);
            SDL_strlcpy(label_text, "Place GamePad On Table", sizeof(label_text));
            SDLTest_DrawString(ctx->renderer, recalibrate_button_area.x, recalibrate_button_area.y + recalibrate_button_area.h + new_line_height * 2, label_text);
        }
    }

    if (ctx->current_calibration_phase == GYRO_CALIBRATION_PHASE_NOISE_PROFILING ||
        ctx->current_calibration_phase == GYRO_CALIBRATION_PHASE_DRIFT_PROFILING)
    {
        float flAbsoluteNoiseFraction = SDL_clamp(ctx->accelerometer_noise_sq / ACCELEROMETER_MAX_NOISE_G_SQ, 0.0f, 1.0f);
        float flAbsoluteToleranceFraction = SDL_clamp(ctx->accelerometer_noise_tolerance_sq / ACCELEROMETER_MAX_NOISE_G_SQ, 0.0f, 1.0f);

        float flMaxNoiseForThisPhase = ctx->current_calibration_phase == GYRO_CALIBRATION_PHASE_NOISE_PROFILING ? ACCELEROMETER_MAX_NOISE_G_SQ : ctx->accelerometer_noise_tolerance_sq;
        float flRelativeNoiseFraction = SDL_clamp(ctx->accelerometer_noise_sq / flMaxNoiseForThisPhase, 0.0f, 1.0f);

        float noise_bar_height = gamepad_display->button_height;
        SDL_FRect noise_bar_rect;
        noise_bar_rect.x = recalibrate_button_area.x;
        noise_bar_rect.y = recalibrate_button_area.y + recalibrate_button_area.h + BUTTON_PADDING;
        noise_bar_rect.w = recalibrate_button_area.w;
        noise_bar_rect.h = noise_bar_height;

        SDL_snprintf(label_text, sizeof(label_text), "Accelerometer Noise Tolerance: %3.3fG ", SDL_sqrtf(ctx->accelerometer_noise_tolerance_sq) );
        SDLTest_DrawString(ctx->renderer, recalibrate_button_area.x, recalibrate_button_area.y + recalibrate_button_area.h + new_line_height * 2, label_text);

        /* Adjust the noise bar rectangle based on the accelerometer noise value */
        float noise_bar_fill_width = flAbsoluteNoiseFraction * noise_bar_rect.w; /* Scale the width based on the noise value */
        SDL_FRect noise_bar_fill_rect;
        noise_bar_fill_rect.x = noise_bar_rect.x + (noise_bar_rect.w - noise_bar_fill_width) * 0.5f;
        noise_bar_fill_rect.y = noise_bar_rect.y;
        noise_bar_fill_rect.w = noise_bar_fill_width;
        noise_bar_fill_rect.h = noise_bar_height;

        /* Set the color based on the noise value vs the tolerance */
        Uint8 red = (Uint8)(flRelativeNoiseFraction * 255.0f);
        Uint8 green = (Uint8)((1.0f - flRelativeNoiseFraction) * 255.0f);
        SDL_SetRenderDrawColor(ctx->renderer, red, green, 0, 255); /* red when high noise, green when low noise */