Chapter 10: The Button Element
The Button
struct is one of our basic UI elements. It has an associated text box for displaying text, a color for the background, and a callback that is invoked when the button is clicked.
We provide a render
method to draw the button onto the screen, an is_pressed
method to check whether a button was clicked based on the x and y coordinates of a mouse click, and an on_click
method to execute the button's callback function.
Moreover, we have serialization logic implemented for the Button
and its inner components: RcTextBoxWrapper
, ColorWrapper
, and RectWrapper
. This allows us to convert a Button
to a serialized form for storage or network communication.
Last updated