[planes] implement ncplane_resize_marginalized() #1472

This commit is contained in:
nick black 2021-03-27 06:50:03 -04:00 committed by Nick Black
parent 7c5b7fe85c
commit a8a42c2a50
2 changed files with 24 additions and 6 deletions

View File

@ -13,7 +13,7 @@ use crate::{
impl NcPlaneOptions {
/// New NcPlaneOptions using the horizontal x.
pub fn new(y: NcOffset, x: NcOffset, rows: NcDim, cols: NcDim) -> Self {
Self::with_flags(y, x, rows, cols, None, 0)
Self::with_flags(y, x, rows, cols, None, 0, 0, 0)
}
/// New NcPlaneOptions with horizontal alignment.
@ -68,8 +68,8 @@ impl NcPlaneOptions {
name: null(),
resizecb: crate::ncresizecb_to_c(resizecb),
flags,
0,
0,
margin_b: 0,
margin_r: 0,
}
}
}

View File

@ -2184,9 +2184,27 @@ int (*ncplane_resizecb(const ncplane* n))(ncplane*){
}
int ncplane_resize_marginalized(ncplane* n){
(void)n;// FIXME uhhh do something here
fprintf(stderr, "NEED TO RESIZE THIS MARGINALIZED-ASS PLANE\n");
return 0;
const ncplane* parent = ncplane_parent_const(n);
// a marginalized plane cannot be larger than its oppressor plane =]
int maxy, maxx;
if(parent == n){ // root plane, need to use pile size
return 0; // FIXME
}else{
ncplane_dim_yx(parent, &maxy, &maxx);
}
if((maxy -= n->margin_b) < 1){
maxy = 1;
}
if((maxx -= n->margin_r) < 1){
maxx = 1;
}
// FIXME mix in top/left margins (absy/absx)
int oldy, oldx;
ncplane_dim_yx(n, &oldy, &oldx); // current dimensions of 'n'
int keepleny = oldy > maxy ? maxy : oldy;
int keeplenx = oldx > maxx ? maxx : oldx;
// FIXME place it according to top/left
return ncplane_resize_internal(n, 0, 0, keepleny, keeplenx, 0, 0, maxy, maxx);
}
int ncplane_resize_maximize(ncplane* n){