polyhorn_ios_sys/polykit/
scroll_view.rs1use objc::runtime::*;
2use objc::*;
3
4use super::{PLYByEdge, PLYDimension, PLYLayout, PLYView};
5use crate::coregraphics::CGRect;
6use crate::uikit::UIScrollViewIndicatorStyle;
7use crate::Raw;
8
9pub struct PLYScrollView {
11 pub(super) object: *mut Object,
12}
13
14impl PLYScrollView {
15 pub fn new() -> PLYScrollView {
17 unsafe {
18 let mut object: *mut Object = msg_send![class!(PLYScrollView), alloc];
19 object = msg_send![object, init];
20 PLYScrollView { object }
21 }
22 }
23
24 pub fn to_view(&self) -> PLYView {
26 unsafe { PLYView::from_raw_retain(self.object) }
27 }
28
29 pub fn set_content_layout(&mut self, callback: impl FnMut() -> CGRect + 'static) {
31 let layout = PLYLayout::new(callback);
32
33 unsafe {
34 let _: () = msg_send![self.object, setContentLayout: layout];
35 }
36 }
37
38 pub fn set_indicator_style(&mut self, style: UIScrollViewIndicatorStyle) {
40 unsafe {
41 let _: () = msg_send![self.object, setIndicatorStyle: style];
42 }
43 }
44
45 pub fn set_scroll_padding(&mut self, padding: PLYByEdge<PLYDimension>) {
48 unsafe {
49 let _: () = msg_send![self.object, setScrollPadding: padding];
50 }
51 }
52
53 pub fn set_scrollbar_padding(&mut self, padding: PLYByEdge<PLYDimension>) {
56 unsafe {
57 let _: () = msg_send![self.object, setScrollbarPadding: padding];
58 }
59 }
60}
61
62impl Raw for PLYScrollView {
63 unsafe fn from_raw(object: *mut Object) -> Self {
64 PLYScrollView { object }
65 }
66
67 unsafe fn as_raw(&self) -> *mut Object {
68 self.object
69 }
70}
71
72impl Clone for PLYScrollView {
73 fn clone(&self) -> Self {
74 unsafe { Self::from_raw_retain(self.as_raw()) }
75 }
76}
77
78impl Drop for PLYScrollView {
79 fn drop(&mut self) {
80 unsafe { objc_release(self.object) }
81 }
82}