Multiple Windows and Utility Windows

Why hide utility windows?

Why is it better to hide utility windows instead of destroying them?

Abstract art representing computer programming

Hiding utility windows instead of destroying them offers significant performance and usability benefits. Creating a window with SDL_CreateWindow() is a relatively expensive operation. It involves allocating memory, initializing GPU resources, and setting up the window’s interaction with the operating system.

Repeatedly creating and destroying a window for temporary UI elements, like tooltips or dropdown menus, can cause noticeable delays and degrade user experience.

By hiding a utility window with SDL_HideWindow() and later showing it with SDL_ShowWindow(), you avoid the overhead of repeatedly setting up the window. This approach also preserves the state of the window, such as its size, position, and contents, allowing for a smoother user experience.

Here’s an example of toggling a window’s visibility:

SDL_Window* Window{
  SDL_CreateWindow(
    "Tooltip",
    100, 100, 200, 100,
    SDL_WINDOW_TOOLTIP | SDL_WINDOW_HIDDEN)
};

// Show the window
SDL_ShowWindow(Window);

// Hide the window
SDL_HideWindow(Window);

Hiding windows is particularly useful for UI components that need to appear dynamically, such as tooltips or dropdown menus. The user perceives these windows as instantly appearing or disappearing, creating a seamless interaction.

This Question is from the Lesson:

Multiple Windows and Utility Windows

Learn how to manage multiple windows, and practical examples using utility windows.

Answers to questions are automatically generated and may not have been reviewed.

This Question is from the Lesson:

Multiple Windows and Utility Windows

Learn how to manage multiple windows, and practical examples using utility windows.

sdl2-promo.jpg
Part of the course:

Game Dev with SDL2

Learn C++ and SDL development by creating hands on, practical projects inspired by classic retro games

Free, unlimited access

This course includes:

  • 67 Lessons
  • 100+ Code Samples
  • 91% Positive Reviews
  • Regularly Updated
  • Help and FAQ
Free, Unlimited Access

Professional C++

Comprehensive course covering advanced concepts, and how to use them on large-scale projects.

Screenshot from Warhammer: Total War
Screenshot from Tomb Raider
Screenshot from Jedi: Fallen Order
Contact|Privacy Policy|Terms of Use
Copyright © 2024 - All Rights Reserved