Skip to main content

polyhorn_ios/raw/
apply.rs

1use polyhorn_ios_sys::polykit::{PLYScrollView, PLYView};
2use polyhorn_ui::styles::{ScrollableStyle, Transform, ViewStyle, Visibility};
3
4use crate::raw::convert::Convert;
5
6/// This trait is implemented for every style that can be applied to an instance
7/// of `UIView`.
8pub trait Apply<T> {
9    /// Applies this style to the given view.
10    fn apply(&self, to: &mut T);
11}
12
13impl Apply<PLYView> for ViewStyle {
14    fn apply(&self, view: &mut PLYView) {
15        view.set_background_color(self.background_color.convert());
16        view.set_alpha(self.opacity as _);
17        view.set_corner_radii(self.border_radius.convert());
18        view.set_hidden(self.visibility == Visibility::Hidden);
19        view.set_transform(Transform::squash(self.transform, Default::default()).convert());
20    }
21}
22
23impl Apply<PLYScrollView> for ScrollableStyle {
24    fn apply(&self, view: &mut PLYScrollView) {
25        view.set_scroll_padding(self.scroll_padding.convert());
26        view.set_indicator_style(self.scrollbar_color.convert());
27        view.set_scrollbar_padding(self.scrollbar_padding.convert());
28    }
29}