polyhorn_ios_sys/polykit/
image_view.rs1use objc::runtime::*;
2use objc::*;
3
4use super::PLYView;
5use crate::uikit::{UIColor, UIImage};
6use crate::Raw;
7
8pub struct PLYImageView {
11 pub(super) object: *mut Object,
12}
13
14impl PLYImageView {
15 pub fn new() -> PLYImageView {
17 unsafe {
18 let mut object: *mut Object = msg_send![class!(PLYImageView), alloc];
19 object = msg_send![object, init];
20 PLYImageView { object }
21 }
22 }
23
24 pub fn set_image(&mut self, image: &UIImage) {
26 unsafe {
27 let _: () = msg_send![self.object, setImage: image.as_raw()];
28 }
29 }
30
31 pub fn set_tint_color(&mut self, color: &UIColor) {
33 unsafe {
34 let _: () = msg_send![self.object, setTintColor: color.as_raw()];
35 }
36 }
37
38 pub fn to_view(&self) -> PLYView {
40 unsafe { PLYView::from_raw_retain(self.object) }
41 }
42}
43
44impl Raw for PLYImageView {
45 unsafe fn from_raw(object: *mut Object) -> Self {
46 PLYImageView { object }
47 }
48
49 unsafe fn as_raw(&self) -> *mut Object {
50 self.object
51 }
52}
53
54impl Drop for PLYImageView {
55 fn drop(&mut self) {
56 unsafe { objc_release(self.object) }
57 }
58}