ferroui_xaml_interactions_custom/writeable_bitmap/
writeable_bitmap_ref.rs1use ferroui_base::media::imaging::WriteableBitmap;
10use ferroui_base::media::IImage;
11use std::fmt;
12use std::ops::Deref;
13use std::rc::Rc;
14
15#[derive(Clone)]
17pub struct WriteableBitmapRef(pub Rc<WriteableBitmap>);
18
19impl WriteableBitmapRef {
20 pub fn new(bitmap: WriteableBitmap) -> Self {
22 Self(Rc::new(bitmap))
23 }
24
25 pub fn get(&self) -> &Rc<WriteableBitmap> {
27 &self.0
28 }
29
30 pub fn as_image(&self) -> Rc<dyn IImage> {
32 self.0.clone()
33 }
34}
35
36impl Deref for WriteableBitmapRef {
37 type Target = WriteableBitmap;
38
39 fn deref(&self) -> &WriteableBitmap {
40 &self.0
41 }
42}
43
44impl PartialEq for WriteableBitmapRef {
45 fn eq(&self, other: &Self) -> bool {
46 Rc::ptr_eq(&self.0, &other.0)
47 }
48}
49
50impl From<Rc<WriteableBitmap>> for WriteableBitmapRef {
51 fn from(value: Rc<WriteableBitmap>) -> Self {
52 Self(value)
53 }
54}
55
56impl fmt::Debug for WriteableBitmapRef {
57 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
58 write!(f, "WriteableBitmapRef({:p})", Rc::as_ptr(&self.0))
59 }
60}