// NPatchInfo: 36 bytes (source as Rectangle + 5 ints)
///|
/// NPatchInfo, n-patch layout info.
pub struct NPatchInfo {
source : Rectangle
left : Int32
top : Int32
right : Int32
bottom : Int32
layout : Int32
} derive(Eq, Debug)
///|
pub extend NPatchInfo with Eq::{equal, not_equal}
///|
pub extend NPatchInfo with @debug.Debug::{to_repr}
///|
/// Create a new NPatchInfo.
pub fn NPatchInfo::new(
source : Rectangle,
left : Int32,
top : Int32,
right : Int32,
bottom : Int32,
layout : Int32,
) -> NPatchInfo {
{ source, left, top, right, bottom, layout, }
}
///|
/// Serialize NPatchInfo to bytes.
pub fn NPatchInfo::to_bytes(n : NPatchInfo) -> Bytes {
let buf = Buffer(size_hint=36)
buf.write_float_le(n.source.x)
buf.write_float_le(n.source.y)
buf.write_float_le(n.source.width)
buf.write_float_le(n.source.height)
buf.write_int_le(n.left)
buf.write_int_le(n.top)
buf.write_int_le(n.right)
buf.write_int_le(n.bottom)
buf.write_int_le(n.layout)
buf.to_bytes()
}
///|
/// Deserialize NPatchInfo from bytes.
pub fn NPatchInfo::from_bytes(b : Bytes) -> NPatchInfo {
{
source: {
x: read_float(b, 0),
y: read_float(b, 4),
width: read_float(b, 8),
height: read_float(b, 12),
},
left: read_int(b, 16),
top: read_int(b, 20),
right: read_int(b, 24),
bottom: read_int(b, 28),
layout: read_int(b, 32),
}
}
// NPatchLayout constants
///|
/// Npatch layout: 3x3 tiles.
pub const NpatchNinePatch : Int32 = 0
///|
/// Npatch layout: 1x3 tiles.
pub const NpatchThreePatchVertical : Int32 = 1
///|
/// Npatch layout: 3x1 tiles.
pub const NpatchThreePatchHorizontal : Int32 = 2