libnotcurses_sys/plane/options/flags.rs
1/// A bitmask of flags for [`NcPlaneOptions`][crate::NcPlaneOptions].
2///
3/// # Flag
4/// - [`None`][NcPlaneFlag::None]
5/// - [`HorAligned`][NcPlaneFlag::HorAligned]
6/// - [`VerAligned`][NcPlaneFlag::VerAligned]
7/// - [`Marginalized`][NcPlaneFlag::Marginalized]
8/// - [`Fixed`][NcPlaneFlag::Fixed]
9/// - [`AutoGrow`][NcPlaneFlag::AutoGrow]
10/// - [`VScroll`][NcPlaneFlag::VScroll]
11///
12/// # Default
13/// *[`NcPlaneFlag::None`]
14#[derive(Copy, Clone, Debug, PartialEq, Eq)]
15pub struct NcPlaneFlag(pub c_api::NcPlaneFlag_u64);
16
17impl NcPlaneFlag {
18 /// No flags.
19 pub const None: Self = Self(0);
20
21 /// Horizontal alignment relative to the parent plane.
22 ///
23 /// Use [`NcAlign`][crate::NcAlign] for 'x'.
24 pub const HorAligned: Self = Self(c_api::NCPLANE_OPTION_HORALIGNED);
25
26 /// Vertical alignment relative to the parent plane.
27 ///
28 /// Use [`NcAlign`][crate::NcAlign] for 'y'.
29 pub const VerAligned: Self = Self(c_api::NCPLANE_OPTION_VERALIGNED);
30
31 /// Maximize relative to the parent plane, minus the provided margins.
32 ///
33 /// The margins are best-effort; the plane will always be at least 1 column
34 /// by 1 row. If the margins can be effected, the plane will be sized to all
35 /// remaining space. 'y' and 'x' are overloaded as the top and left margins
36 /// when this flag is used. 'rows' and 'cols' must be 0 when this flag is
37 /// used. This flag is exclusive with both of the alignment flags.
38 pub const Marginalized: Self = Self(c_api::NCPLANE_OPTION_MARGINALIZED);
39
40 /// Do not scroll alongside its parent.
41 ///
42 /// If this plane is bound to a scrolling plane, it ought *not* scroll along
43 /// with the parent (it will still move with the parent, maintaining its
44 /// relative position, if the parent is moved to a new location).
45 pub const Fixed: Self = Self(c_api::NCPLANE_OPTION_FIXED);
46
47 /// Enables automatic growth of the plane to accommodate output.
48 ///
49 /// Creating a plane with this flag is equivalent to immediately calling
50 /// `NcPlane::`[`set_autogrow`]`(true)` following plane creation.
51 ///
52 /// [`set_autogrow`]: crate::NcPlane#method.set_autogrow
53 pub const AutoGrow: Self = Self(c_api::NCPLANE_OPTION_AUTOGROW);
54
55 /// Enables vertical scrolling of the plane to accommodate output.
56 ///
57 /// Creating a plane with this flag is equivalent to immediately calling
58 /// `NcPlane::`[`set_scrolling`]`(true)` following plane creation.
59 ///
60 /// [`set_scrolling`]: crate::NcPlane#method.set_autogrow
61 pub const VScroll: Self = Self(c_api::NCPLANE_OPTION_VSCROLL);
62}
63
64mod core_impls {
65 use super::{c_api::NcPlaneFlag_u64, NcPlaneFlag};
66
67 impl Default for NcPlaneFlag {
68 fn default() -> Self {
69 Self::None
70 }
71 }
72
73 crate::from_primitive![NcPlaneFlag, NcPlaneFlag_u64];
74 crate::unit_impl_from![NcPlaneFlag, NcPlaneFlag_u64];
75 crate::unit_impl_ops![bitwise; NcPlaneFlag, NcPlaneFlag_u64];
76 crate::unit_impl_fmt![bases+display; NcPlaneFlag];
77}
78
79pub(crate) mod c_api {
80 use crate::c_api::ffi;
81
82 /// A bitmask of flags for [`NcPlaneOptions`][crate::NcPlaneOptions].
83 ///
84 /// It's recommended to use [`NcPlaneFlag`][crate::NcPlaneFlag] instead.
85 ///
86 /// # Associated `c_api` constants
87 /// - [`NCPLANE_OPTION_HORALIGNED`]
88 /// - [`NCPLANE_OPTION_VERALIGNED`]
89 /// - [`NCPLANE_OPTION_MARGINALIZED`]
90 /// - [`NCPLANE_OPTION_FIXED`]
91 /// - [`NCPLANE_OPTION_AUTOGROW`]
92 /// - [`NCPLANE_OPTION_VSCROLL`]
93 pub type NcPlaneFlag_u64 = u64;
94
95 /// [`NcPlaneFlag_u64`] Horizontal alignment relative to the parent plane.
96 ///
97 /// Use `NcAlign_u32` for 'x'.
98 pub const NCPLANE_OPTION_HORALIGNED: NcPlaneFlag_u64 =
99 ffi::NCPLANE_OPTION_HORALIGNED as NcPlaneFlag_u64;
100
101 /// [`NcPlaneFlag_u64`] flag for vertical alignment relative to the parent
102 /// plane.
103 ///
104 /// Use `NcAlign_u32` for 'y'.
105 pub const NCPLANE_OPTION_VERALIGNED: NcPlaneFlag_u64 =
106 ffi::NCPLANE_OPTION_VERALIGNED as NcPlaneFlag_u64;
107
108 /// [`NcPlaneFlag_u64`] flag to maximize relative to the parent plane,
109 /// modulo the provided margins.
110 ///
111 /// The margins are best-effort; the plane will always be at least 1 column by
112 /// 1 row. If the margins can be effected, the plane will be sized to all
113 /// remaining space. 'y' and 'x' are overloaded as the top and left margins
114 /// when this flag is used. 'rows' and 'cols' must be 0 when this flag is
115 /// used. This flag is exclusive with both of the alignment flags.
116 pub const NCPLANE_OPTION_MARGINALIZED: NcPlaneFlag_u64 =
117 ffi::NCPLANE_OPTION_MARGINALIZED as NcPlaneFlag_u64;
118
119 /// [`NcPlaneFlag_u64`] flag to avoid scrolling alongside its parent.
120 ///
121 /// If this plane is bound to a scrolling plane, it ought *not* scroll along
122 /// with the parent (it will still move with the parent, maintaining its
123 /// relative position, if the parent is moved to a new location).
124 pub const NCPLANE_OPTION_FIXED: NcPlaneFlag_u64 = ffi::NCPLANE_OPTION_FIXED as NcPlaneFlag_u64;
125
126 /// [`NcPlaneFlag_u64`] flag that enables automatic growth of the plane to
127 /// accommodate output.
128 ///
129 /// Creating a plane with this flag is equivalent to immediately calling
130 /// `ncplane_set_autogrow(p, true)` following plane creation.
131 pub const NCPLANE_OPTION_AUTOGROW: NcPlaneFlag_u64 =
132 ffi::NCPLANE_OPTION_AUTOGROW as NcPlaneFlag_u64;
133
134 /// [`NcPlaneFlag_u64`] flag that enables vertical scrolling of the plane
135 /// to accommodate output.
136 ///
137 /// Creating a plane with this flag is equivalent to immediately calling
138 /// `ncplane_set_scrolling(p, true)` following plane creation.
139 pub const NCPLANE_OPTION_VSCROLL: NcPlaneFlag_u64 =
140 ffi::NCPLANE_OPTION_VSCROLL as NcPlaneFlag_u64;
141}