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_RESIZEDfires multiple times during a resize operation, whileSDL_WINDOWEVENT_SIZE_CHANGEDfires once after the size stabilizes. - Purpose: Use
SDL_WINDOWEVENT_RESIZEDfor tasks like logging or real-time feedback, andSDL_WINDOWEVENT_SIZE_CHANGEDfor 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