rocketsplash-rt 0.2.2

Runtime library for loading and rendering Rocketsplash assets (.rst, .rsf)
Documentation
// <FILE>crates/rocketsplash-rt/src/font/fnc_align_offset.rs</FILE>
// <DESC>Calculate horizontal alignment offset for a rendered line.</DESC>
// <VERS>VERSION: 1.0.0</VERS>
// <WCTX>Public release refactor audit</WCTX>
// <CLOG>Extract align offset logic from fnc_render_text</CLOG>

use crate::Align;

pub(super) fn align_offset(align: Align, max_width: i64, line_width: i64) -> i64 {
    if max_width <= line_width {
        return 0;
    }
    let diff = max_width - line_width;
    match align {
        Align::Left => 0,
        Align::Center => diff / 2,
        Align::Right => diff,
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn align_offset_respects_alignment_mode() {
        assert_eq!(align_offset(Align::Left, 10, 6), 0);
        assert_eq!(align_offset(Align::Center, 10, 6), 2);
        assert_eq!(align_offset(Align::Right, 10, 6), 4);
    }

    #[test]
    fn align_offset_zero_when_line_wider_than_canvas() {
        assert_eq!(align_offset(Align::Right, 5, 8), 0);
    }
}

// <FILE>crates/rocketsplash-rt/src/font/fnc_align_offset.rs</FILE>
// <VERS>END OF VERSION: 1.0.0</VERS>