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 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.

PreviousChapter 9: The User Interface LayerNextChapter 11: The Text Box Element

Last updated 1 year ago