pub trait TextAlignment {
// Required methods
fn draw_centered_text(
&mut self,
text: &str,
x: i32,
y: i32,
font_size: i32,
color: impl Into<Color>,
);
fn draw_right_aligned_text(
&mut self,
text: &str,
x: i32,
y: i32,
font_size: i32,
color: impl Into<Color>,
);
fn measure_text_ext(&mut self, text: &str, font_size: i32) -> (i32, i32);
}
Expand description
Trait for drawing text with different alignments (centered or right-aligned)
Required Methods§
fn draw_centered_text( &mut self, text: &str, x: i32, y: i32, font_size: i32, color: impl Into<Color>, )
fn draw_right_aligned_text( &mut self, text: &str, x: i32, y: i32, font_size: i32, color: impl Into<Color>, )
fn measure_text_ext(&mut self, text: &str, font_size: i32) -> (i32, i32)
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl TextAlignment for RaylibDrawHandle<'_>
Implement the TextAlignment
trait for RaylibDrawHandle
to enable custom text drawing
impl TextAlignment for RaylibDrawHandle<'_>
Implement the TextAlignment
trait for RaylibDrawHandle
to enable custom text drawing
Source§fn draw_centered_text(
&mut self,
text: &str,
x: i32,
y: i32,
font_size: i32,
color: impl Into<Color>,
)
fn draw_centered_text( &mut self, text: &str, x: i32, y: i32, font_size: i32, color: impl Into<Color>, )
Draw text centered at the specified (x, y) position
§Example:
use raylib::prelude::*;
use raylib_ext::*;
fn main() {
let (mut rl, thread) = init()
.size(640, 480)
.title("Hello, World")
.build();
while !rl.window_should_close() {
let mut d = rl.begin_drawing(&thread);
d.clear_background(Color::WHITE);
// Draws text where (x, y) is in the middle of the text instead of top-left
d.draw_centered_text("Hello, world!", 12, 12, 20, Color::BLACK);
}
}
Source§fn draw_right_aligned_text(
&mut self,
text: &str,
x: i32,
y: i32,
font_size: i32,
color: impl Into<Color>,
)
fn draw_right_aligned_text( &mut self, text: &str, x: i32, y: i32, font_size: i32, color: impl Into<Color>, )
Draw text right-aligned at the specified (x, y) position
§Example:
use raylib::prelude::*;
use raylib_ext::*;
fn main() {
let (mut rl, thread) = init()
.size(640, 480)
.title("Hello, World")
.build();
while !rl.window_should_close() {
let mut d = rl.begin_drawing(&thread);
d.clear_background(Color::WHITE);
// Draws text where (x, y) is in the top-right corner instead of top-left
d.draw_right_aligned_text("Hello, world!", 12, 12, 20, Color::BLACK);
}
}