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

Code before:
    /* Show the recalibration progress bar. */
    float recalibrate_button_width = GetGamepadButtonLabelWidth(start_calibration_button) + 2 * BUTTON_PADDING;
    SDL_FRect recalibrate_button_area;
    recalibrate_button_area.x = ctx->area.x + ctx->area.w - recalibrate_button_width - BUTTON_PADDING;
    recalibrate_button_area.y = log_y + FONT_CHARACTER_SIZE * 0.5f - gamepad_display->button_height * 0.5f;
    recalibrate_button_area.w = GetGamepadButtonLabelWidth(start_calibration_button) + 2.0f * BUTTON_PADDING;
    recalibrate_button_area.h = gamepad_display->button_height + BUTTON_PADDING * 2.0f;

    /* Above button */
    SDL_strlcpy(label_text, "Gyro Orientation:", sizeof(label_text));
    SDLTest_DrawString(ctx->renderer, recalibrate_button_area.x, recalibrate_button_area.y - new_line_height, label_text);

    /* Button label vs state */
    if (ctx->current_calibration_phase == GYRO_CALIBRATION_PHASE_OFF) {
        SDL_strlcpy(label_text, "Start Gyro Calibration", sizeof(label_text));
    } else if (ctx->current_calibration_phase == GYRO_CALIBRATION_PHASE_NOISE_PROFILING) {
        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;

Review comment (suggestion):
```suggestion
    RenderGamepadButton(start_calibration_button);
```

Code after:
    SDL_FRect recalibrate_button_area;
    recalibrate_button_area.x = ctx->area.x + ctx->area.w - recalibrate_button_width - BUTTON_PADDING;
    recalibrate_button_area.y = log_y + FONT_CHARACTER_SIZE * 0.5f - gamepad_display->button_height * 0.5f;
    recalibrate_button_area.w = GetGamepadButtonLabelWidth(start_calibration_button) + 2.0f * BUTTON_PADDING;
    recalibrate_button_area.h = gamepad_display->button_height + BUTTON_PADDING * 2.0f;

    /* Above button */
    SDL_strlcpy(label_text, "Gyro Orientation:", sizeof(label_text));
    SDLTest_DrawString(ctx->renderer, recalibrate_button_area.x, recalibrate_button_area.y - new_line_height, label_text);

    /* Button label vs state */
    if (ctx->current_calibration_phase == GYRO_CALIBRATION_PHASE_OFF) {
        SDL_strlcpy(label_text, "Start Gyro Calibration", sizeof(label_text));
    } else if (ctx->current_calibration_phase == GYRO_CALIBRATION_PHASE_NOISE_PROFILING) {
        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;