use crate::ecs::text::resources::FontEngine;
use crate::ecs::text::resources::font_engine::FontKind;
pub(super) fn wrap_text(
font_engine: &mut FontEngine,
text: &str,
font_size: f32,
available_width: f32,
) -> String {
if available_width <= 0.0 || text.is_empty() {
return text.to_string();
}
let line_height = font_size * 1.2;
let buffer = font_engine.shape_buffer(
text,
font_size,
line_height,
Some(available_width),
FontKind::Default,
);
let mut result = String::with_capacity(text.len() + 16);
let mut first = true;
for run in buffer.layout_runs() {
if !first {
result.push('\n');
}
first = false;
result.push_str(run.text);
}
result
}