polyhorn_ui/styles/scrollable.rs
1use super::ViewStyle;
2use crate::geometry::{ByEdge, Dimension};
3
4/// Color of the scroll bars of a Scrollable.
5#[derive(Copy, Clone, Debug, Eq, PartialEq)]
6pub enum ScrollbarColor {
7 /// This variant lets the OS decide which color to use. The OS may look at
8 /// the appearance mode chosen by the user (i.e. light vs. dark mode) and/or
9 /// at the content that is shown in the scrollable (e.g. to determine which
10 /// color would have the highest contrast with respect to the content
11 /// underlying).
12 Auto,
13
14 /// This is a dark scroll bar. Use this only if the underlying content is
15 /// light.
16 Dark,
17
18 /// This is a light scroll bar. Use this only if the underlying content is
19 /// dark.
20 Light,
21}
22
23impl Default for ScrollbarColor {
24 fn default() -> Self {
25 ScrollbarColor::Auto
26 }
27}
28
29/// Controls the appearance of a Scrollable.
30#[derive(Copy, Clone, Debug, Default, PartialEq)]
31pub struct ScrollableStyle {
32 /// Controls the distance between the scrollable content and each edge of a
33 /// rectangle.
34 pub scroll_padding: ByEdge<Dimension<f32>>,
35
36 /// This field controls the appearance of scroll bars used in this
37 /// Scrollable. When set to Default, the scroll bar's appearance is
38 /// automatically updated when the OS indicates that the user has changed
39 /// its appearance mode, or when the OS chooses its own style depending on
40 /// the brightness of underlying content and recommends a different style
41 /// than is currently shown.
42 pub scrollbar_color: ScrollbarColor,
43
44 /// Controls the distance between the scrollbars and each edge of a
45 /// rectangle.
46 pub scrollbar_padding: ByEdge<Dimension<f32>>,
47}
48
49/// This is a union style of the Scrollable and View styles.
50#[derive(Copy, Clone, Debug, Default, PartialEq)]
51pub struct ScrollableViewStyle {
52 /// This style contains the properties that are only applicable to
53 /// Scrollables.
54 pub scrollable: ScrollableStyle,
55
56 /// This style contains the properties that are only applicable to
57 /// Views.
58 pub view: ViewStyle,
59}
60
61impl From<ScrollableStyle> for ScrollableViewStyle {
62 fn from(style: ScrollableStyle) -> Self {
63 ScrollableViewStyle {
64 scrollable: style,
65 ..Default::default()
66 }
67 }
68}
69
70impl From<ViewStyle> for ScrollableViewStyle {
71 fn from(style: ViewStyle) -> Self {
72 ScrollableViewStyle {
73 view: style,
74 ..Default::default()
75 }
76 }
77}