1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// notcurses::plane::builder
//
//!
//
use crate::{
error::NotcursesResult as Result,
plane::{Align, Plane},
sys::{Nc, NcPlane, NcPlaneOptionsBuilder},
Notcurses, Position, Size,
};
/// A [`Plane`] builder.
#[derive(Debug, Default)]
pub struct PlaneBuilder {
options: NcPlaneOptionsBuilder,
}
/// # Constructors
impl PlaneBuilder {
/// Returns a new default `PlaneBuilder`.
///
/// Size, position and margins are set to 0.
/// The plane will be maximized to its parent size.
pub fn new() -> Self {
Self::default()
}
/// Returns a new standalone `Plane`.
pub fn build(self, nc: &Notcurses) -> Result<Plane> {
let notcurses = nc.inner.clone();
let ncplane = {
let inner_nc = notcurses.borrow_mut();
let nc_ptr: *mut Nc = inner_nc.nc;
// SAFETY: ensured via RefCell's borrowing rules
let nc_ref: &mut Nc = unsafe { &mut *nc_ptr };
NcPlane::new_pile(nc_ref, &self.options.build())?
};
Ok(Plane {
nc: ncplane,
notcurses,
})
}
/// Returns a new child `Plane` of the provided parent.
pub fn build_child(self, parent: &mut Plane) -> Result<Plane> {
let ncplane = NcPlane::new_child(parent.into_ref_mut(), &self.options.build())?;
Ok(Plane {
nc: ncplane,
notcurses: parent.notcurses.clone(),
})
}
}
/// # Methods (chainable)
impl PlaneBuilder {
/// Sets the vertical position relative to the parent plane.
///
/// Default: *`0`*.
///
/// Effect: Sets the *`y`* coordinate and unsets vertical alignment.
pub fn y(mut self, y: i32) -> Self {
self.options.set_y(y);
self
}
/// Sets the horizontal position relative to the parent plane.
///
/// Default: *`0`*.
///
/// Effect: Sets the *`x`* coordinate and unsets vertical alignment.
pub fn x(mut self, x: i32) -> Self {
self.options.set_x(x);
self
}
/// Sets the position relative to parent plane.
///
/// Default: *`0`*, *`0`*.
///
/// Effect: Sets both *`x`* & *`y`* coordinates and unsets both horizontal and
/// vertical alignment.
pub fn position(mut self, position: impl Into<Position>) -> Self {
let (x, y) = position.into().into();
self.options.set_yx(y, x);
self
}
//
/// Sets the vertical alignment.
///
/// Default: *[`Align::Top`]*.
///
/// Effect: Sets *`v`* alignment.
pub fn valign(mut self, vertical: Align) -> Self {
self.options.set_valign(vertical);
self
}
/// Sets the horizontal alignment.
///
/// Default: *[`Align::Left`]*.
///
/// Effect: Sets *`h`* alignment.
pub fn halign(mut self, horizontal: Align) -> Self {
self.options.set_halign(horizontal);
self
}
/// Sets the vertical & horizontal placement relative to parent plane.
///
/// Default: *`0`*, *`0`*.
///
/// Effect: Sets both horizontal and vertical alignment.
pub fn align(mut self, vertical: Align, horizontal: Align) -> Self {
self.options.set_align(vertical, horizontal);
self
}
//
/// Sets the height of the plane (rows).
///
/// Default: *`0`*.
///
/// Effect: Sets the height of the plane and *unmaximizes* it.
pub fn height(mut self, height: u32) -> Self {
self.options.set_rows(height);
self
}
/// Sets the width for the plane (columns).
///
/// Default: *`0`*.
///
/// Effect: Sets the width of the plane and *unmaximizes* it.
pub fn width(mut self, width: u32) -> Self {
self.options.set_cols(width);
self
}
/// Sets the size of the plane (rows, columns).
///
/// Default: *`0`*.
///
/// Effect: Sets the height and width of the plane and *unmaximizes* it.
pub fn size(mut self, size: impl Into<Size>) -> Self {
let (width, height) = size.into().into();
self.options.set_rows_cols(height, width);
self
}
//
/// Maximizes the plane, with optional right & bottom margins.
///
/// Default: *`(0, 0)`*.
///
/// Effect: maximizes the plane relative to the parent plane, minus the
/// provided margins.
///
/// See also: [`sys::NcPlaneFlag::Marginalized`].
///
/// [`sys::NcPlaneFlag::Marginalized`]: crate::sys::NcPlaneFlag#associatedconstant.Marginalized
pub fn maximize(mut self, right_bottom: impl Into<Size>) -> Self {
let (x_right, y_bottom) = right_bottom.into().into();
self.options.set_margins(y_bottom, x_right);
self
}
/// If `true`, the plane will **not** scroll with the parent.
///
/// Default: *`false`* (scrolls with the parent).
///
/// Effect: (un)fixes the plane.
///
/// See also: [`sys::NcPlaneFlag::Fixed`].
///
/// [`sys::NcPlaneFlag::Fixed`]: crate::sys::NcPlaneFlag#associatedconstant.Fixed
pub fn fixed(mut self, fixed: bool) -> Self {
self.options.set_fixed(fixed);
self
}
/// If `true`, the plane will scroll vertically to accommodate output.
///
/// This is equivalent to immediately calling [`set_scrolling(true)`]
/// following `Plane` creation.
///
/// Default: *`false`*.
///
/// Effect: (un)sets vertical scrolling.
///
/// [`set_scrolling(true)`]: super::Plane#method.set_scrolling
pub fn scroll(mut self, scroll: bool) -> Self {
self.options.set_vscroll(scroll);
self
}
/// If `true`, the plane will grow automatically.
///
/// Default: *`false`*.
///
/// Effect: (un)sets the plane to automatically grow to accomodate output.
///
/// Note that just setting `autogrow` makes the plane grow to the right,
/// and setting `autogrow` and `scroll` makes the plane grow downwards.
pub fn autogrow(mut self, autogrow: bool) -> Self {
self.options.set_autogrow(autogrow);
self
}
// TODO: resizecb
}