mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-20 03:25:47 +00:00
ncplane_new_internal: use ncplane_valign() #1468
This commit is contained in:
parent
fc79dcd77a
commit
229c1ab3c2
@ -1204,12 +1204,27 @@ impl NcPlane {
|
|||||||
/// Returns `-`[NCRESULT_MAX][crate::NCRESULT_MAX] if
|
/// Returns `-`[NCRESULT_MAX][crate::NCRESULT_MAX] if
|
||||||
/// [NCALIGN_UNALIGNED][crate::NCALIGN_UNALIGNED] or invalid [NcAlign].
|
/// [NCALIGN_UNALIGNED][crate::NCALIGN_UNALIGNED] or invalid [NcAlign].
|
||||||
///
|
///
|
||||||
/// *C style function: [ncplane_align()][crate::ncplane_align].*
|
/// *C style function: [ncplane_halign()][crate::ncplane_halign].*
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn align(&mut self, align: NcAlign, cols: NcDim) -> NcResult<()> {
|
pub fn halign(&mut self, align: NcAlign, cols: NcDim) -> NcResult<()> {
|
||||||
error![
|
error![
|
||||||
crate::ncplane_align(self, align, cols),
|
crate::ncplane_halign(self, halign, cols),
|
||||||
&format!("NcPlane.align({:?}, {})", align, cols)
|
&format!("NcPlane.halign({:?}, {})", halign, cols)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the row at which `rows` rows ought start in order to be
|
||||||
|
/// aligned according to `align` within this NcPlane.
|
||||||
|
///
|
||||||
|
/// Returns `-`[NCRESULT_MAX][crate::NCRESULT_MAX] if
|
||||||
|
/// [NCALIGN_UNALIGNED][crate::NCALIGN_UNALIGNED] or invalid [NcAlign].
|
||||||
|
///
|
||||||
|
/// *C style function: [ncplane_valign()][crate::ncplane_valign].*
|
||||||
|
#[inline]
|
||||||
|
pub fn valign(&mut self, align: NcAlign, cols: NcDim) -> NcResult<()> {
|
||||||
|
error![
|
||||||
|
crate::ncplane_valign(self, valign, cols),
|
||||||
|
&format!("NcPlane.valign({:?}, {})", valign, cols)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,15 +24,14 @@ visualize(struct notcurses* nc, struct ncvisual* ncv){
|
|||||||
struct ncvisual_options vopts = {
|
struct ncvisual_options vopts = {
|
||||||
.scaling = NCSCALE_SCALE,
|
.scaling = NCSCALE_SCALE,
|
||||||
.blitter = bs[i],
|
.blitter = bs[i],
|
||||||
.y = NCALIGN_CENTER,
|
|
||||||
.flags = NCVISUAL_OPTION_NODEGRADE | NCVISUAL_OPTION_HORALIGNED
|
.flags = NCVISUAL_OPTION_NODEGRADE | NCVISUAL_OPTION_HORALIGNED
|
||||||
| NCVISUAL_OPTION_VERALIGNED,
|
| NCVISUAL_OPTION_VERALIGNED,
|
||||||
};
|
};
|
||||||
int scalex, scaley, truey, truex;
|
int scalex, scaley, truey, truex;
|
||||||
ncvisual_geom(nc, ncv, &vopts, &truey, &truex, &scaley, &scalex);
|
ncvisual_geom(nc, ncv, &vopts, &truey, &truex, &scaley, &scalex);
|
||||||
vopts.x = NCALIGN_CENTER;
|
vopts.x = NCALIGN_CENTER;
|
||||||
vopts.y = (ncplane_dim_y(notcurses_stdplane(nc)) - truey / scaley) / 2;
|
vopts.y = NCALIGN_CENTER;
|
||||||
//fprintf(stderr, "X: %d truex: %d sclaex: %d\n", vopts.x, truex, scalex);
|
//fprintf(stderr, "X: %d truex: %d scalex: %d\n", vopts.x, truex, scalex);
|
||||||
ncplane_erase(stdn);
|
ncplane_erase(stdn);
|
||||||
// if we're about to blit pixel graphics, render the screen as empty, so
|
// if we're about to blit pixel graphics, render the screen as empty, so
|
||||||
// that everything is damaged for the printing of the legend.
|
// that everything is damaged for the printing of the legend.
|
||||||
@ -49,9 +48,9 @@ visualize(struct notcurses* nc, struct ncvisual* ncv){
|
|||||||
DEMO_RENDER(nc);
|
DEMO_RENDER(nc);
|
||||||
}
|
}
|
||||||
ncplane_printf_aligned(stdn, ncplane_dim_y(stdn) / 2 - 1, NCALIGN_CENTER,
|
ncplane_printf_aligned(stdn, ncplane_dim_y(stdn) / 2 - 1, NCALIGN_CENTER,
|
||||||
"%03dx%03d", truex, truey);
|
"%03dx%03d", truex, truey);
|
||||||
ncplane_printf_aligned(stdn, ncplane_dim_y(stdn) / 2 + 1, NCALIGN_CENTER,
|
ncplane_printf_aligned(stdn, ncplane_dim_y(stdn) / 2 + 1, NCALIGN_CENTER,
|
||||||
"%d:%d pixels -> cell", scalex, scaley);
|
"%d:%d pixels -> cell", scalex, scaley);
|
||||||
}
|
}
|
||||||
const char* name = notcurses_str_blitter(bs[i]);
|
const char* name = notcurses_str_blitter(bs[i]);
|
||||||
ncplane_printf_aligned(stdn, ncplane_dim_y(stdn) / 2 - 3, NCALIGN_CENTER, "%sblitter", name);
|
ncplane_printf_aligned(stdn, ncplane_dim_y(stdn) / 2 - 3, NCALIGN_CENTER, "%sblitter", name);
|
||||||
|
@ -341,7 +341,7 @@ ncplane* ncplane_new_internal(notcurses* nc, ncplane* n,
|
|||||||
}
|
}
|
||||||
p->absx += n->absx;
|
p->absx += n->absx;
|
||||||
if(nopts->flags & NCPLANE_OPTION_VERALIGNED){
|
if(nopts->flags & NCPLANE_OPTION_VERALIGNED){
|
||||||
p->absy = ncplane_halign(n, nopts->y, nopts->rows);
|
p->absy = ncplane_valign(n, nopts->y, nopts->rows);
|
||||||
p->valign = nopts->y;
|
p->valign = nopts->y;
|
||||||
}else{
|
}else{
|
||||||
p->absy = nopts->y;
|
p->absy = nopts->y;
|
||||||
|
Loading…
Reference in New Issue
Block a user