use crate::{c_api::ffi, NcAlign, NcResizeCb};
use core::ptr::{null, null_mut};
mod builder;
pub(crate) mod flags;
pub use builder::NcPlaneOptionsBuilder;
pub use flags::NcPlaneFlag;
pub type NcPlaneOptions = ffi::ncplane_options;
impl NcPlaneOptions {
pub fn new(y: i32, x: i32, rows: u32, cols: u32) -> Self {
Self::with_flags(y, x, rows, cols, None, NcPlaneFlag::None, 0, 0)
}
pub fn builder() -> NcPlaneOptionsBuilder {
NcPlaneOptionsBuilder::default()
}
pub fn to_builder(&self) -> NcPlaneOptionsBuilder {
NcPlaneOptionsBuilder::from_options(self)
}
pub fn new_aligned(y: i32, align: impl Into<NcAlign>, rows: u32, cols: u32) -> Self {
Self::with_flags_aligned(y, align.into(), rows, cols, None, NcPlaneFlag::HorAligned)
}
pub fn with_flags(
y: i32,
x: i32,
rows: u32,
cols: u32,
resizecb: Option<NcResizeCb>,
flags: impl Into<NcPlaneFlag>,
margin_b: u32,
margin_r: u32,
) -> Self {
NcPlaneOptions {
y,
x,
rows,
cols,
userptr: null_mut(),
name: null(),
resizecb: crate::c_api::ncresizecb_to_c(resizecb),
flags: flags.into().into(),
margin_b,
margin_r,
}
}
pub fn with_flags_aligned(
y: i32,
align: impl Into<NcAlign>,
rows: u32,
cols: u32,
resizecb: Option<NcResizeCb>,
flags: impl Into<NcPlaneFlag>,
) -> Self {
let flags = NcPlaneFlag::HorAligned | flags.into();
NcPlaneOptions {
y,
x: align.into().into(),
rows,
cols,
userptr: null_mut(),
name: null(),
resizecb: crate::c_api::ncresizecb_to_c(resizecb),
flags: flags.into(),
margin_b: 0,
margin_r: 0,
}
}
}
impl NcPlaneOptions {
pub fn is_veraligned(&self) -> bool {
self.flags & NcPlaneFlag::VerAligned != NcPlaneFlag::None
}
pub fn is_horaligned(&self) -> bool {
self.flags & NcPlaneFlag::HorAligned != NcPlaneFlag::None
}
pub fn is_marginalized(&self) -> bool {
self.flags & NcPlaneFlag::Marginalized != NcPlaneFlag::None
}
pub fn is_fixed(&self) -> bool {
self.flags & NcPlaneFlag::Fixed != NcPlaneFlag::None
}
pub fn is_autogrow(&self) -> bool {
self.flags & NcPlaneFlag::AutoGrow != NcPlaneFlag::None
}
pub fn is_vscroll(&self) -> bool {
self.flags & NcPlaneFlag::VScroll != NcPlaneFlag::None
}
}