goku
goku game engine_en
goku game engine_en
  • Chapter 1: Introduction to SDL2, Rust, and goku
  • Chapter2: The Base Structure: SpriteSheet
  • Chapter 3: Animated Textures
  • Chapter 4: Handling Textures: TextureManager
  • Chapter 5: Bringing Textures to Life: GameObject
  • Chapter 6: The Foundation: Tile System
  • Chapter 7: Moving the View: Camera
  • Chapter 8: Particle System
  • Chapter 9: The User Interface Layer
  • Chapter 10: The Button Element
  • Chapter 11: The Text Box Element
  • Chapter 12: The Checkbox Element
  • Chapter 13: The Slider Element
  • Chapter 14: The Audio System
  • Chapter 15: The AI System
  • Chapter 16: The Window System
  • Chapter 17: User Input Handling
  • Chapter 18: Rendering a Parallax Background
  • Chapter 19: Timing and Frame Rate Management
  • Chapter 20: Conclusion
Powered by GitBook
On this page

Chapter 9: The User Interface Layer

The UI layer is a crucial component of our GUI system as it is responsible for managing and rendering all UI elements. In our Layer struct, we have two types of UI elements: Button and Checkbox. These two elements are stored in Vecs which will allow us to manage any number of these elements.

We provide methods for adding new elements (add_button, add_checkbox), rendering elements (render), and handling mouse click events (handle_mouse_click).

In the render method, we loop over all buttons and call their render method. Later, we could extend this to render other types of UI elements as well.

The handle_mouse_click method, given a mouse click's x and y coordinates, checks if any button or checkbox was clicked, and if so, triggers the associated actions.

PreviousChapter 8: Particle SystemNextChapter 10: The Button Element

Last updated 1 year ago