Raylib Interactive
The library for people who want to do other things but stick to raylib
This is a library that supports c++ and rust and adds many interactive things to your current raylib project, such as:
Buttons, Checkboxes, Dropdowns, and Textfields.
A copy of "rust docs.md" is pasted below:
Raylib Interactive Elements Documentation
This document provides an overview of the interactive elements implemented in Rust using the Raylib library. These components provide a rich set of interactive UI functionality for graphical applications or games.
- Checkbox
Description:
An animated checkbox that toggles between checked and unchecked states with visual feedback.
Public Methods:
-
pub fn new(x: f32, y: f32, size: f32, label: &str) -> Self
- Constructor to initialize the checkbox.
- Parameters:
x
,y
: Position of the checkboxsize
: Size of the checkboxlabel
: Text label displayed next to the checkbox
-
pub fn set_colors(&mut self, background: Color, check: Color, border: Color, hover: Color, label: Color)
- Set all colors for the checkbox components.
-
pub fn set_font_size(&mut self, size: i32)
- Set the font size for the label.
-
pub fn update(&mut self, rl: &RaylibHandle)
- Handles input and animations.
-
pub fn draw(&self, d: &mut RaylibDrawHandle)
- Renders the checkbox with animations.
-
pub fn is_checked(&self) -> bool
- Returns the current state.
-
pub fn set_checked(&mut self, checked: bool)
- Programmatically set the checkbox state.
-
pub fn toggle(&mut self)
- Toggle the checkbox state.
- Dropdown
Description:
A scrollable dropdown menu with hover effects and custom styling.
Public Methods:
-
pub fn new(x: f32, y: f32, width: f32, height: f32, items: Vec<String>) -> Self
- Constructor to initialize the dropdown.
- Parameters:
x
,y
: Positionwidth
,height
: Dimensionsitems
: List of options
-
pub fn set_colors(&mut self, background: Color, border: Color, text: Color, hover: Color)
- Set the colors for all components.
-
pub fn set_font_size(&mut self, size: i32)
- Set the font size.
-
pub fn set_max_visible_items(&mut self, count: usize)
- Set maximum number of visible items before scrolling.
-
pub fn update(&mut self, rl: &RaylibHandle)
- Handles input, scrolling, and item selection.
-
pub fn draw(&self, d: &mut RaylibDrawHandle)
- Renders the dropdown with scroll indicators.
-
pub fn get_selected_index(&self) -> Option<usize>
- Returns the selected item's index.
-
pub fn get_selected_item(&self) -> Option<&String>
- Returns the selected item.
- TextField
Description:
A text input field with cursor animation and selection support.
Public Methods:
-
pub fn new(x: f32, y: f32, width: f32, height: f32, max_length: usize) -> Self
- Constructor to initialize the text field.
- Parameters:
x
,y
: Positionwidth
,height
: Dimensionsmax_length
: Maximum text length
-
pub fn set_colors(&mut self, background: Color, border: Color, text: Color)
- Set the colors.
-
pub fn set_font_size(&mut self, size: i32)
- Set the font size.
-
pub fn update(&mut self, rl: &RaylibHandle)
- Handles text input and cursor movement.
-
pub fn draw(&self, d: &mut RaylibDrawHandle)
- Renders the field with animated cursor.
-
pub fn get_text(&self) -> &str
- Returns current text.
-
pub fn is_active(&self) -> bool
- Returns focus state.
-
pub fn activate(&mut self)
- Set focus to this field.
-
pub fn deactivate(&mut self)
- Remove focus.
- Button
Description:
An animated button with hover and press effects, rounded corners, and custom styling.
Public Methods:
-
pub fn new(x: f32, y: f32, width: f32, height: f32, label: &str) -> Self
- Constructor to initialize the button.
- Parameters:
x
,y
: Positionwidth
,height
: Dimensionslabel
: Button text
-
pub fn set_colors(&mut self, background: Color, hover: Color, pressed: Color, border: Color, text: Color)
- Set all button colors.
-
pub fn set_font_size(&mut self, size: i32)
- Set the font size.
-
pub fn set_corner_radius(&mut self, radius: f32)
- Set corner rounding radius.
-
pub fn set_padding(&mut self, padding: f32)
- Set internal padding.
-
pub fn set_enabled(&mut self, enabled: bool)
- Enable/disable the button.
-
pub fn update(&mut self, rl: &RaylibHandle)
- Handles input and animations.
-
pub fn draw(&self, d: &mut RaylibDrawHandle)
- Renders the button with effects.
-
pub fn is_clicked(&self, rl: &RaylibHandle) -> bool
- Returns true if clicked.
-
pub fn is_pressed(&self) -> bool
- Returns true if being pressed.
-
pub fn is_hovered(&self) -> bool
- Returns true if mouse is over button.
-
pub fn is_enabled(&self) -> bool
- Returns enabled state.
-
pub fn get_label(&self) -> &str
- Returns button text.
-
pub fn set_label(&mut self, label: &str)
- Set button text.
Usage Example:
// Initialize Raylib
let = init
.size
.title
.msaa_4x
.vsync
.build;
// Create elements
let mut checkbox = new;
let mut dropdown = new;
let mut text_field = new;
let mut button = new;
// Customize appearance
button.set_corner_radius;
dropdown.set_max_visible_items;
// Main loop
while !rl.window_should_close