minifb_ui/lib.rs
1//! # Minifb-UI
2//!
3//! This is a crate aiming to make usage of the minifb crate easier than it already is,
4//! by providing abstractions and features for easy creation and management of windows
5//! and UI elements.
6//!
7//! # Example Usage
8//!
9//! ```rust
10//! use minifb_ui;
11//!
12//! fn main() {
13//! // Create a custom window with resolution and title, and determine whether it's
14//! // borderless and resizable
15//! let mut window = minifb_ui::window::Window::custom(
16//! "TestWindow",
17//! 1920,
18//! 1080,
19//! false,
20//! false,
21//! );
22//!
23//! // You can load both otf and ttf fonts, some might work better than others
24//! let font = minifb_ui::ttf::Font::new("assets/Dico.ttf");
25//!
26//! // Create an example text and give it a font. A Text instance owns a Font instance
27//! let text = minifb_ui::ui::text::Text::new(
28//! "The quick brown fox jumps over the lazy dog !\"ยง$%&/()=?+~*#'-_.:,;<>|",
29//! font.clone()
30//! );
31//!
32//! // Create a button. Chaining of methods only works at creation, they cannot be used afterwards.
33//! // Values can still be modified using the fields of the struct instance
34//! let button = minifb_ui::ui::button::Button::default()
35//! .label("Press Me!", font)
36//! .text_color(minifb_ui::color::Color::from(0xAAAAAA))
37//! .label_alignment(minifb_ui::ui::button::Alignment::Center)
38//! .position(100, 100)
39//! .size(150, 33)
40//! .border(true, 1)
41//! .shadow(true, 5, 75)
42//! .border_color(minifb_ui::color::Color::from(0x777777))
43//! .bg_color(minifb_ui::color::Color::from(0x202020));
44//!
45//! // Infinite loop until the window's close button is pressed
46//! while window.window.is_open() {
47//! // Draw the text variable at position 10|10 with size 16 and the color white
48//! window.draw_text(10, 10, &text, 16.0, &minifb_ui::color::Color::from(0xFFFFFF));
49//!
50//! // Self-explanatory
51//! button.draw(&mut window);
52//!
53//! // Needs to be called every iteration of a loop
54//! window.update();
55//! }
56//! }
57//! ```
58
59/// Provides necessary things to work with ttf and otf fonts
60pub mod ttf;
61/// Provides the Window struct and gives you everything you need to create one and draw in it
62pub mod window;
63/// Provides the Color RGBA struct
64pub mod color;
65/// Provides UI elements you can draw in a Window
66pub mod ui;