Size Changed vs Resized Events

What is the difference between SDL_WINDOWEVENT_SIZE_CHANGED and SDL_WINDOWEVENT_RESIZED?

Both SDL_WINDOWEVENT_SIZE_CHANGED and SDL_WINDOWEVENT_RESIZED are window events related to size changes, but they differ in when and how they are triggered.

SDL_WINDOWEVENT_SIZE_CHANGED

This event occurs when the window size changes and rendering must be updated. It's typically triggered after the user completes a resize action or when the window is resized programmatically using functions like SDL_SetWindowSize().

Here's how you might handle it:

if (event.type == SDL_WINDOWEVENT &&
    event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
  int width = event.window.data1;
  int height = event.window.data2;
  std::cout << "Size changed to: "
    << width << "x" << height << "\n";
}

SDL_WINDOWEVENT_RESIZED

This event is sent more broadly and includes platform-specific behavior. It's triggered whenever a resize operation occurs, including intermediate steps while the user is actively resizing the window.

To handle this:

if (event.type == SDL_WINDOWEVENT &&
    event.window.event == SDL_WINDOWEVENT_RESIZED) {
  int width = event.window.data1;
  int height = event.window.data2;
  std::cout << "Resizing in progress: "
    << width << "x" << height << "\n";
}

Key Differences

  • Frequency: SDL_WINDOWEVENT_RESIZED fires multiple times during a resize operation, while SDL_WINDOWEVENT_SIZE_CHANGED fires once after the size stabilizes.
  • Purpose: Use SDL_WINDOWEVENT_RESIZED for tasks like logging or real-time feedback, and SDL_WINDOWEVENT_SIZE_CHANGED for updating rendering or layouts after resizing.

By distinguishing between these events, you can optimize your application's response to resizing and avoid unnecessary recalculations or redraws.

Window Sizing

Learn how to resize, constrain, and manage SDL2 windows

Questions & Answers

Answers are generated by AI models and may not have been reviewed. Be mindful when running any code on your device.

Handling Exceeded Minimum Window Size
What happens if the minimum window size exceeds the current window size?
Resizing and Graphical Content
How does resizing affect graphical content displayed inside the window?
Constraints in SDL_SetWindowSize()
Is SDL_SetWindowSize() affected by the maximum and minimum size constraints?
Best Practices for Resize Events
What are the best practices for handling resize events in games?
Integer Pointers in SDL
Why does SDL require integer pointers in functions like SDL_GetWindowSize()?
Or Ask your Own Question
Get an immediate answer to your specific question using our AI assistant