Skip to main content

libbitsub_core/pgs/
window.rs

1//! Window Definition Segment parsing.
2
3use crate::utils::BigEndianReader;
4
5/// Window definition specifies the on-screen rectangle for rendering.
6#[derive(Debug, Clone, Copy, Default)]
7pub struct WindowDefinition {
8    /// Window ID
9    pub id: u8,
10    /// Horizontal position (x coordinate)
11    pub x: u16,
12    /// Vertical position (y coordinate)
13    pub y: u16,
14    /// Window width
15    pub width: u16,
16    /// Window height
17    pub height: u16,
18}
19
20/// Window Definition Segment contains one or more window definitions.
21#[derive(Debug, Clone)]
22pub struct WindowDefinitionSegment {
23    /// List of window definitions
24    pub windows: Vec<WindowDefinition>,
25}
26
27impl WindowDefinitionSegment {
28    /// Parse a window definition segment from binary data.
29    pub fn parse(reader: &mut BigEndianReader, _length: usize) -> Option<Self> {
30        let count = reader.read_u8()? as usize;
31        let mut windows = Vec::with_capacity(count);
32
33        for _ in 0..count {
34            let id = reader.read_u8()?;
35            let x = reader.read_u16()?;
36            let y = reader.read_u16()?;
37            let width = reader.read_u16()?;
38            let height = reader.read_u16()?;
39
40            windows.push(WindowDefinition {
41                id,
42                x,
43                y,
44                width,
45                height,
46            });
47        }
48
49        Some(Self { windows })
50    }
51}