use crate::value::VBObject;
use std::any::Any;
use std::fmt;
#[derive(Debug)]
pub struct StdPicture {
width: i32,
height: i32,
handle: Option<u32>,
}
impl StdPicture {
pub fn new(width: i32, height: i32) -> Self {
Self {
width,
height,
handle: None,
}
}
pub fn width(&self) -> i32 {
self.width
}
pub fn height(&self) -> i32 {
self.height
}
pub fn handle(&self) -> Option<u32> {
self.handle
}
pub fn set_handle(&mut self, handle: u32) {
self.handle = Some(handle);
}
}
impl fmt::Display for StdPicture {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"StdPicture(width={}, height={})",
self.width, self.height
)
}
}
impl VBObject for StdPicture {
fn type_name(&self) -> &str {
"StdPicture"
}
fn as_any(&self) -> &dyn Any {
self
}
fn clone_box(&self) -> Box<dyn VBObject> {
Box::new(StdPicture {
width: self.width,
height: self.height,
handle: self.handle,
})
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::value::VBVariant;
#[test]
fn stdpicture_type_name() {
let pic = StdPicture::new(100, 200);
assert_eq!(pic.type_name(), "StdPicture");
}
#[test]
fn stdpicture_clone() {
let original = StdPicture::new(100, 200);
let cloned = original.clone_box();
let cloned_pic = cloned.as_any().downcast_ref::<StdPicture>().unwrap();
assert_eq!(cloned_pic.width(), 100);
assert_eq!(cloned_pic.height(), 200);
}
#[test]
fn stdpicture_as_variant() {
let pic = StdPicture::new(100, 200);
let variant = VBVariant::from_object(Box::new(pic));
let retrieved = variant.as_object().unwrap();
assert_eq!(retrieved.type_name(), "StdPicture");
}
}