Skip to content

Commit

Permalink
[rust] add pending functions
Browse files Browse the repository at this point in the history
- include new functions: ncdirect_stream, ncdirect_supported_styles, ncdirect_styles, nccell_width, ncinput_nomod_p.
- account for functions: ncplane_halign, ncplane_valign.
- rename ncpalette_get_rgb and ncpalette_set_rgb to ncpalette_get_rgb8 and ncpalette_set_rgb8 respectively.
- minor formatting fixes.
  • Loading branch information
joseluis committed Jun 12, 2021
1 parent d695a82 commit 125ab36
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 53 deletions.
6 changes: 6 additions & 0 deletions rust/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ pub use ffi::{
nccell_extended_gcluster,
nccell_load,
nccell_release,
nccell_width,
nccells_double_box,
nccells_rounded_box,
};
Expand Down Expand Up @@ -182,6 +183,9 @@ pub use ffi::{
ncdirect_set_fg_rgb,
ncdirect_set_styles,
ncdirect_stop,
ncdirect_stream,
ncdirect_styles,
ncdirect_supported_styles,
ncdirect_vline_interp,
};

Expand Down Expand Up @@ -382,6 +386,7 @@ pub use ffi::{
ncplane_dim_yx,
ncplane_dup,
ncplane_erase,
ncplane_erase_region,
ncplane_fadein,
ncplane_fadein_iteration,
ncplane_fadeout,
Expand Down Expand Up @@ -760,6 +765,7 @@ pub use ffi::{
notcurses_core_init,
notcurses_cursor_disable,
notcurses_cursor_enable,
notcurses_cursor_yx,
notcurses_debug,
notcurses_debug_caps,
notcurses_drop_planes,
Expand Down
3 changes: 2 additions & 1 deletion rust/src/cells/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
//! `NcCell`
// functions already exported by bindgen : 6
// functions already exported by bindgen : 7
// -----------------------------------------
// (W) wrap: 4
// (#) test: 0
// ------------------------------------------
//… nccell_extended_gcluster
//… nccell_load
// nccell_width
//W nccells_double_box
//W nccells_rounded_box
//W nccell_duplicate
Expand Down
7 changes: 5 additions & 2 deletions rust/src/direct/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! `NcDirect`
// total: 47
// total: 50
// ---------------------------------------------------
// (X) 1 : wont do
//
// (f) 42 : unsafe ffi function exported by bindgen
// (f) 45 : unsafe ffi function exported by bindgen
// (w) 0 : safely wrapped ffi function
// (r) 4 : static function manually reimplemented
//
Expand Down Expand Up @@ -56,6 +56,9 @@
// fm ncdirect_rounded_box
// fm ncplane_set_styles
// fm ncdirect_stop
// f ncdirect_stream
// f ncdirect_styles
// f ncdirect_supported_styles
// fm ncdirect_vline_interp
// rm ncdirect_bg_rgb8
// rm ncdirect_fg_rgb8
Expand Down
38 changes: 22 additions & 16 deletions rust/src/input/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
//! `NcInput` & `NcKey`
// functions manually reimplemented: 1
// functions manually reimplemented: 4
// ------------------------------------------
// (+) done: 3 / 0
// (#) test: 0 / 3
// ------------------------------------------
// + ncinput_equal_p
// + nckey_mouse_p
// + nckey_nomod_p
// + nckey_supppuab_p

use crate::NcDim;
Expand Down Expand Up @@ -35,21 +36,6 @@ pub use keycodes::*;
/// For all events, modifiers (e.g. "Alt") are carried as bools in this struct.
pub type NcInput = crate::bindings::ffi::ncinput;

/// Compares two ncinput structs for data equality by doing a field-by-field
/// comparison for equality (excepting seqnum).
///
/// Returns true if the two are data-equivalent.
pub const fn ncinput_equal_p(n1: NcInput, n2: NcInput) -> bool {
if n1.id != n2.id {
return false;
}
if n1.y != n2.y || n1.x != n2.x {
return false;
}
// do not check seqnum
true
}

/// New NcInput.
impl NcInput {
/// New empty NcInput.
Expand Down Expand Up @@ -119,6 +105,21 @@ impl NcInput {
}
}

/// Compares two ncinput structs for data equality by doing a field-by-field
/// comparison for equality (excepting seqnum).
///
/// Returns true if the two are data-equivalent.
pub const fn ncinput_equal_p(n1: NcInput, n2: NcInput) -> bool {
if n1.id != n2.id {
return false;
}
if n1.y != n2.y || n1.x != n2.x {
return false;
}
// do not check seqnum
true
}

/// Is this [char] a Supplementary Private Use Area-B codepoint?
///
/// Links:
Expand All @@ -134,3 +135,8 @@ pub const fn nckey_supppuab_p(w: char) -> bool {
pub const fn nckey_mouse_p(r: char) -> bool {
r >= NCKEY_BUTTON1 && r <= NCKEY_RELEASE
}

/// Are all the modifiers off (alt, control, shift)?
pub const fn ncinput_nomod_p(input: &NcInput) -> bool {
!input.alt && !input.ctrl && !input.shift
}
5 changes: 3 additions & 2 deletions rust/src/notcurses/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! `Notcurses`
// total: 51
// total: 52
// ---------------------------------------------------
// (X) 1 : wont do
//
// (f) 44 : unsafe ffi function exported by bindgen
// (f) 45 : unsafe ffi function exported by bindgen
// (w) 0 : safely wrapped ffi function
// (r) 6 : static function manually reimplemented
//
Expand All @@ -28,6 +28,7 @@
//~f notcurses_core_init
// fm notcurses_cursor_disable
// fm notcurses_cursor_enable
// f notcurses_cursor_yx
// fmt notcurses_debug
// fm notcurses_debug_caps
// fmt notcurses_drop_planes
Expand Down
4 changes: 3 additions & 1 deletion rust/src/palette/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@
//W ncpalette_new
//W ncpalette_use
//
// functions manually reimplemented: 3
// functions manually reimplemented: 5
// -----------------------------------------
// (+) done: 3 / 0
// (#) test: 0
// (W) wrap: 3 / 0
// -----------------------------------------
//W+ ncpalette_get_rgb
// ncpalette_get_rgb8
//W+ ncpalette_set
//W+ ncpalette_set_rgb
// ncpalette_set_rgb8

mod methods;
mod reimplemented;
Expand Down
4 changes: 2 additions & 2 deletions rust/src/palette/reimplemented.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{NcChannel, NcColor, NcPalette, NcPaletteIndex, NcRgb};
/// *Method: NcPalette.[get_rgb()][NcPalette#method.get_rgb].*
/// *Method: NcPalette.[get_rgb8()][NcPalette#method.get_rgb8].*
#[inline]
pub fn ncpalette_get_rgb(
pub fn ncpalette_get_rgb8(
palette: &NcPalette,
index: NcPaletteIndex,
red: &mut NcColor,
Expand All @@ -30,7 +30,7 @@ pub fn ncpalette_set(palette: &mut NcPalette, index: NcPaletteIndex, rgb: NcRgb)
///
/// *Method: NcPalette.[set_rgb()][NcPalette#method.set_rgb].*
#[inline]
pub fn ncpalette_set_rgb(
pub fn ncpalette_set_rgb8(
palette: &mut NcPalette,
index: NcPaletteIndex,
red: NcColor,
Expand Down
5 changes: 4 additions & 1 deletion rust/src/plane/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! `NcPlane`
// functions already exported by bindgen : 113
// functions already exported by bindgen : 116
// -------------------------------------------
// (X) wont: 10
// (D) depr: 4
Expand Down Expand Up @@ -33,13 +33,15 @@
//W# ncplane_dim_yx
//W ncplane_dup
//W# ncplane_erase
// ncplane_erase_region
//W ncplane_fadein
//W ncplane_fadein_iteration
//W ncplane_fadeout
//W ncplane_fadeout_iteration
//W ncplane_format
//W ncplane_gradient
//W ncplane_greyscale
// ncplane_halign
//W ncplane_highgradient
//W ncplane_highgradient_sized
// ncplane_hline_interp
Expand Down Expand Up @@ -113,6 +115,7 @@
//W ncplane_translate
//W ncplane_translate_abs
// ncplane_userptr
// ncplane_valign
// ncplane_vline_interp
// X ncplane_vprintf_aligned
// X ncplane_vprintf_stained
Expand Down
13 changes: 2 additions & 11 deletions rust/src/visual/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,7 @@ impl NcDirectF {
options: &NcVisualOptions,
) -> NcResult<&mut NcDirectV> {
error_ref_mut![
unsafe {
crate::ncdirectf_render(ncd, self, options)
},
unsafe { crate::ncdirectf_render(ncd, self, options) },
"NcVisual.render()"
]
}
Expand All @@ -532,14 +530,7 @@ impl NcDirectF {
) -> NcResult<NcVGeom> {
let mut geom = NcVGeom::new();

let res = unsafe {
crate::ncdirectf_geom(
ncd,
self,
options,
&mut geom,
)
};
let res = unsafe { crate::ncdirectf_geom(ncd, self, options, &mut geom) };
error![res, "NcDirectF.ncdirectf_geom()", geom];
}
}
Expand Down
8 changes: 5 additions & 3 deletions rust/src/visual/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// functions already exported by bindgen : 22
// functions already exported by bindgen : 24
// -----------------------------------------
// (W) wrap: 20
// (#) test: 0
Expand All @@ -10,6 +10,7 @@
//W ncvisual_at_yx
//W ncvisual_decode
//W ncvisual_decode_loop
// ncvisual_default_blitter
//W ncvisual_destroy
//W ncvisual_from_bgra
//W ncvisual_from_file
Expand All @@ -19,6 +20,7 @@
//W ncvisual_blitter_geom
//W ncvisual_media_defblitter
//W ncvisual_polyfill_yx
// ncvisual_plane_create
//W ncvisual_render
//W ncvisual_resize
//W ncvisual_rotate
Expand All @@ -32,7 +34,7 @@ use crate::{NcChannel, NcDim, NcRgb};

mod methods;

/// How to scale an [`NcVisual`] during rendering
/// How to scale an [`NcVisual`] during rendering.
///
/// - [`NCSCALE_NONE`] will apply no scaling.
/// - [`NCSCALE_SCALE`] scales a visual to the plane's size,
Expand Down Expand Up @@ -155,7 +157,7 @@ pub const NCVISUAL_OPTION_HORALIGNED: u32 = crate::bindings::ffi::NCVISUAL_OPTIO
/// Uses non-interpolative scaling.
pub const NCVISUAL_OPTION_NOINTERPOLATE: u32 = crate::bindings::ffi::NCVISUAL_OPTION_NOINTERPOLATE;

/// Blitter Mode (`NCBLIT_*`)
/// The blitter mode to use for rasterizing an [`NcVisual`].
///
/// We never blit full blocks, but instead spaces (more efficient) with the
/// background set to the desired foreground.
Expand Down
21 changes: 7 additions & 14 deletions tools/function-summary/PENDING-changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,17 @@ PENDING changes

## from changes-20210406-20210410.txt
bindgen add:
- [ ] ncdirect_stream
- [x] ncdirect_stream

## from changes-20120518-20210603.txt …

- ncdirect_styles
- ncdirect_supported_styles
- [x] ncdirect_styles
- [x] ncdirect_supported_styles

- ncplane_erase_region
- ncplane_align
- [x] ncplane_erase_region

- ncvisual_default_blitter
- ncvisualplane_create
- [x] nccell_width

- nccell_width
- [x] notcurses_cursor_yx

- ncpalette_get_rgb8
- ncpalette_set_rgb8

- notcurses_cursor_yx

- ncinput_nomod_p
- [x] ncinput_nomod_p

0 comments on commit 125ab36

Please sign in to comment.