libnotcurses_sys/visual/
reimplemented.rs

1//! `ncvisual_*` reimplemented functions
2
3use crate::{
4    Nc, NcError, NcPlane, NcPlaneOptions, NcResult, NcVisual, NcVisualFlag, NcVisualOptions,
5};
6
7/// Creates a new plane as prescribed in `opts`, either as a child
8/// or the root of a new pile.
9///
10/// Blits `ncv` to the created plane according to `vopts`.
11///
12/// If `opts` has a plane, `NCVISUAL_OPTION_CHILDPLANE` must also be supplied.
13//
14// NOTE: no equivalent method for now.
15#[allow(dead_code)]
16pub fn ncvisualplane_create<'a>(
17    nc: &'a mut Nc,
18    opts: &NcPlaneOptions,
19    ncv: &mut NcVisual,
20    vopts: Option<&NcVisualOptions>,
21) -> NcResult<&'a mut NcPlane> {
22    // struct ncplane* plane;
23    // if (vopts && vopts->n) {
24    //     if(vopts->flags & NCVISUAL_OPTION_CHILDPLANE){
25    //         return NULL; // the whole point is to create a new plane
26    //     }
27    //     plane = ncplane_create(vopts->n, opts);
28    // } else {
29    //     plane = ncpile_create(nc, opts);
30    // }
31    // if(plane == NULL){
32    //     return NULL;
33    // }
34
35    let plane: &mut NcPlane;
36    if let Some(vo) = vopts {
37        if vo.n.is_null() {
38            plane = NcPlane::new_pile(nc, opts)?;
39        } else if vo.flags & NcVisualFlag::ChildPlane != NcVisualFlag::None {
40            return Err(NcError::new_msg("ncvisualplane_create() ERR"));
41        } else {
42            plane = NcPlane::new_child(unsafe { &mut *vo.n }, opts)?;
43        }
44    } else {
45        plane = NcPlane::new_pile(nc, opts)?;
46    }
47
48    // struct ncvisual_options v;
49    // if(!vopts){
50    //     vopts = &v;
51    //     memset(vopts, 0, sizeof(*vopts));
52    // }
53
54    let _vopts2: NcVisualOptions;
55    let vopts2_ref: &NcVisualOptions;
56
57    if let Some(vo) = vopts {
58        vopts2_ref = vo;
59    } else {
60        _vopts2 = NcVisualOptions::default();
61        vopts2_ref = &_vopts2;
62    }
63
64    // WIP:
65
66    // vopts->n = plane;
67    // if(ncvisual_blit(nc, ncv, vopts) == NULL){
68    //     ncplane_destroy(plane);
69    //     vopts->n = NULL;
70    //     return NULL;
71    // }
72    // return plane;
73
74    unsafe { ncv.blit(nc, Some(vopts2_ref))? };
75
76    Ok(plane)
77}