mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-20 03:25:47 +00:00
rust: ncplane constructors
- new NcPlane & NcPlaneOptions constructors. - new NcHoriz enum for NcPlaneOptions horiz parameter. - Make NCPLANE_OPTION_HORALIGNED u64 for consistency with expected value type.
This commit is contained in:
parent
51d01b22c8
commit
00f5001342
@ -149,8 +149,10 @@
|
||||
//
|
||||
// NOTE: TODO: Still remains all the ncplane_printf* functions/macros (at the end)
|
||||
|
||||
use core::ffi::c_void;
|
||||
use core::ptr::null_mut;
|
||||
use core::{
|
||||
ffi::c_void,
|
||||
ptr::{null, null_mut},
|
||||
};
|
||||
|
||||
use cstr_core::CString;
|
||||
use libc::free;
|
||||
@ -163,13 +165,58 @@ use crate::{
|
||||
ncplane_at_yx, ncplane_box, ncplane_channels, ncplane_cursor_move_yx, ncplane_cursor_yx,
|
||||
ncplane_dim_yx, ncplane_gradient, ncplane_hline_interp, ncplane_putc_yx, ncplane_putegc_yx,
|
||||
ncplane_putnstr_yx, ncplane_putstr_yx, ncplane_resize, ncplane_vline_interp,
|
||||
ncplane_vprintf_yx, notcurses_align,
|
||||
ncplane_vprintf_yx, notcurses_align, ncplane_create,
|
||||
types::{
|
||||
AlphaBits, Cell, Channel, Channels, Color, EgcBackstop, IntResult, NcAlign, NcPlane,
|
||||
StyleMask,
|
||||
StyleMask, NcPlaneOptions, NcPlaneOptionHoriz, NcHoriz, NCPLANE_OPTION_HORALIGNED,
|
||||
},
|
||||
};
|
||||
|
||||
// Constructors ----------------------------------------------------------------
|
||||
|
||||
impl NcPlaneOptions {
|
||||
/// `NcPlaneOptions` simple constructor with horizontal x
|
||||
pub fn new(y: i32, x: i32, rows: u32, cols: u32) -> Self {
|
||||
Self::with_all_options(y, NcHoriz::x(x), rows, cols, 0)
|
||||
}
|
||||
|
||||
/// `NcPlaneOptions` simple constructor with horizontal alignment
|
||||
pub fn new_halign(y: i32, align: NcAlign, rows: u32, cols: u32) -> Self {
|
||||
Self::with_all_options(y, NcHoriz::align(align), rows, cols, NCPLANE_OPTION_HORALIGNED)
|
||||
}
|
||||
|
||||
/// `NcplaneOptions` constructor
|
||||
pub fn with_all_options(y: i32, horiz: NcHoriz, rows: u32, cols: u32, flags: u64) -> Self {
|
||||
NcPlaneOptions {
|
||||
y,
|
||||
horiz: {
|
||||
match horiz {
|
||||
NcHoriz::x(data) => NcPlaneOptionHoriz {x: data},
|
||||
NcHoriz::align(data) => NcPlaneOptionHoriz {align: data},
|
||||
}
|
||||
|
||||
},
|
||||
rows: rows as i32,
|
||||
cols: cols as i32,
|
||||
userptr: null_mut(),
|
||||
name: null(),
|
||||
resizecb: None,
|
||||
flags,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl NcPlane {
|
||||
|
||||
/// `NcPlane` constructor
|
||||
pub unsafe fn new<'a>(bound_to: &mut NcPlane, options: &NcPlaneOptions) -> &'a mut NcPlane {
|
||||
&mut *ncplane_create(bound_to, options)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Static Functions ------------------------------------------------------------
|
||||
|
||||
/// Return the column at which 'cols' columns ought start in order to be aligned
|
||||
/// according to 'align' within ncplane 'n'. Returns INT_MAX on invalid 'align'.
|
||||
/// Undefined behavior on negative 'cols'.
|
||||
|
@ -36,8 +36,8 @@ pub use misc::{
|
||||
};
|
||||
pub use plane::{
|
||||
NCBLIT_1x1, NCBLIT_2x1, NCBLIT_2x2, NCBLIT_3x2, NCBLIT_4x1, NCBLIT_8x1, NcAlign, NcBlitter,
|
||||
NcFdPlane, NcFdPlaneOptions, NcPlane, NcPlaneOptionHoriz, NcPlaneOptions, NcScale, NcVisual,
|
||||
NcVisualOptions, NCALIGN_CENTER, NCALIGN_LEFT, NCALIGN_RIGHT, NCALIGN_UNALIGNED,
|
||||
NcFdPlane, NcFdPlaneOptions, NcHoriz, NcPlane, NcPlaneOptionHoriz, NcPlaneOptions, NcScale,
|
||||
NcVisual, NcVisualOptions, NCALIGN_CENTER, NCALIGN_LEFT, NCALIGN_RIGHT, NCALIGN_UNALIGNED,
|
||||
NCBLIT_BRAILLE, NCBLIT_DEFAULT, NCBLIT_SIXEL, NCPLANE_OPTION_HORALIGNED, NCSCALE_NONE,
|
||||
NCSCALE_SCALE, NCSCALE_STRETCH, NCVISUAL_OPTION_BLEND, NCVISUAL_OPTION_NODEGRADE,
|
||||
};
|
||||
|
@ -13,7 +13,7 @@ pub type NcPlane = crate::ncplane;
|
||||
pub type NcPlaneOptions = crate::ncplane_options;
|
||||
|
||||
/// Horizontal alignment relative to the parent plane. Use 'align' instead of 'x'.
|
||||
pub const NCPLANE_OPTION_HORALIGNED: u32 = crate::bindings::NCPLANE_OPTION_HORALIGNED;
|
||||
pub const NCPLANE_OPTION_HORALIGNED: u64 = crate::bindings::NCPLANE_OPTION_HORALIGNED as u64;
|
||||
|
||||
/// The `horiz` union field of [`NcPlaneOptions`](type.NcPlaneOptions)
|
||||
///
|
||||
@ -24,6 +24,12 @@ pub const NCPLANE_OPTION_HORALIGNED: u32 = crate::bindings::NCPLANE_OPTION_HORAL
|
||||
///
|
||||
pub type NcPlaneOptionHoriz = crate::ncplane_options__bindgen_ty_1;
|
||||
|
||||
/// This enum is a wrapper over the C `horiz` union, for the `NcPlaneOption` constructor
|
||||
pub enum NcHoriz {
|
||||
x(i32),
|
||||
align(NcAlign),
|
||||
}
|
||||
|
||||
/// I/O wrapper to dump file descriptor to [`NcPlane`](type.NcPlane.html)
|
||||
///
|
||||
/// `type in C: ncfdplane (struct)`
|
||||
|
Loading…
Reference in New Issue
Block a user