From b8f6c1e8e169bc8d8ff0f85de1e3ddd478026e3d Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 2 Dec 2026 02:17:56 +0400 Subject: feat(ui): render current messages in the native cockpit pager --- crates/fparkan-font/src/bitmap.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'crates/fparkan-font') diff --git a/crates/fparkan-font/src/bitmap.rs b/crates/fparkan-font/src/bitmap.rs index 6360b367..0110de40 100644 --- a/crates/fparkan-font/src/bitmap.rs +++ b/crates/fparkan-font/src/bitmap.rs @@ -143,6 +143,43 @@ impl BitmapFont { Ok([width, height]) } + /// Wraps pager tokens by their atlas advances. A newline starts a row + /// when it opens a token, while spaces inside a row retain their width. + pub fn wrap_pager_lines(&self, mut text: &str, max_width: u16) -> Result, String> { + let mut lines = Vec::new(); + let mut line = String::new(); + let mut width = 0; + while !text.is_empty() { + if let Some(after) = text.strip_prefix('\n') { + lines.push(std::mem::take(&mut line)); + text = after; + width = 0; + continue; + } + let is_space = text.starts_with(' '); + let end = if is_space { + text.len() - text.trim_start_matches(' ').len() + } else { + text.find(' ').unwrap_or(text.len()) + }; + let token = &text[..end]; + text = &text[end..]; + let advance = usize::from(self.line_metrics(token)?[0]); + if !line.is_empty() && width + advance > usize::from(max_width) { + lines.push(std::mem::take(&mut line)); + width = 0; + } + if !is_space || !line.is_empty() { + line.push_str(token); + width += advance; + } + } + if !line.is_empty() { + lines.push(line); + } + Ok(lines) + } + /// Composes a single line from a game resource's original CP1251 bytes. pub fn centered_line_bytes( &self, -- cgit v1.2.3