use crate::{c_api::ffi, NcAlign, NcResizeCb};
mod builder;
pub use builder::NcPlaneOptionsBuilder;
use std::ptr::{null, null_mut};
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: y as i32,
x: x as i32,
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: y as i32,
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
}
}
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct NcPlaneFlag(pub c_api::NcPlaneFlag_u64);
impl NcPlaneFlag {
pub const None: Self = Self(0);
pub const HorAligned: Self = Self(c_api::NCPLANE_OPTION_HORALIGNED);
pub const VerAligned: Self = Self(c_api::NCPLANE_OPTION_VERALIGNED);
pub const Marginalized: Self = Self(c_api::NCPLANE_OPTION_MARGINALIZED);
pub const Fixed: Self = Self(c_api::NCPLANE_OPTION_FIXED);
pub const AutoGrow: Self = Self(c_api::NCPLANE_OPTION_AUTOGROW);
pub const VScroll: Self = Self(c_api::NCPLANE_OPTION_VSCROLL);
}
mod std_impls {
use super::{c_api::NcPlaneFlag_u64, NcPlaneFlag};
impl Default for NcPlaneFlag {
fn default() -> Self {
Self::None
}
}
crate::from_primitive![NcPlaneFlag, NcPlaneFlag_u64];
crate::unit_impl_from![NcPlaneFlag, NcPlaneFlag_u64];
crate::unit_impl_ops![bitwise; NcPlaneFlag, NcPlaneFlag_u64];
crate::unit_impl_fmt![bases+display; NcPlaneFlag];
}
pub(crate) mod c_api {
use super::ffi;
pub type NcPlaneFlag_u64 = u64;
pub const NCPLANE_OPTION_HORALIGNED: NcPlaneFlag_u64 =
ffi::NCPLANE_OPTION_HORALIGNED as NcPlaneFlag_u64;
pub const NCPLANE_OPTION_VERALIGNED: NcPlaneFlag_u64 =
ffi::NCPLANE_OPTION_VERALIGNED as NcPlaneFlag_u64;
pub const NCPLANE_OPTION_MARGINALIZED: NcPlaneFlag_u64 =
ffi::NCPLANE_OPTION_MARGINALIZED as NcPlaneFlag_u64;
pub const NCPLANE_OPTION_FIXED: NcPlaneFlag_u64 = ffi::NCPLANE_OPTION_FIXED as NcPlaneFlag_u64;
pub const NCPLANE_OPTION_AUTOGROW: NcPlaneFlag_u64 =
ffi::NCPLANE_OPTION_AUTOGROW as NcPlaneFlag_u64;
pub const NCPLANE_OPTION_VSCROLL: NcPlaneFlag_u64 =
ffi::NCPLANE_OPTION_VSCROLL as NcPlaneFlag_u64;
}