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 Vec
s 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.
Last updated