Use percentage-based width for the sidebar
Use percentage-based widths internally. This slightly impairs (user) feedback but brings the sidebar configuration menu closer to the actual configuration format (the user now configures percentage-based widths, not absolute width values). As a bonus, the sidebar is now resized automatically on each window resize (based on the percentage values). Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
parent
b4d5316125
commit
c65ccb0e77
37
src/wins.c
37
src/wins.c
@ -44,7 +44,7 @@
|
||||
struct window win[NBWINS];
|
||||
|
||||
/* User-configurable side bar width. */
|
||||
static unsigned sbarwidth;
|
||||
static unsigned sbarwidth_perc;
|
||||
|
||||
static enum win slctd_win;
|
||||
static int layout;
|
||||
@ -135,7 +135,13 @@ wins_set_layout (int nb)
|
||||
unsigned
|
||||
wins_sbar_width (void)
|
||||
{
|
||||
return sbarwidth ? sbarwidth : SBARMINWIDTH;
|
||||
if (sbarwidth_perc > SBARMAXWIDTHPERC)
|
||||
return col * SBARMAXWIDTHPERC / 100;
|
||||
else
|
||||
{
|
||||
unsigned sbarwidth = (unsigned)(col * sbarwidth_perc / 100);
|
||||
return (sbarwidth < SBARMINWIDTH) ? SBARMINWIDTH : sbarwidth;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -145,11 +151,7 @@ wins_sbar_width (void)
|
||||
unsigned
|
||||
wins_sbar_wperc (void)
|
||||
{
|
||||
unsigned perc;
|
||||
|
||||
perc = col ? (unsigned)(100 * sbarwidth / col + 1): 0;
|
||||
|
||||
return perc > SBARMAXWIDTHPERC ? SBARMAXWIDTHPERC : perc;
|
||||
return sbarwidth_perc > SBARMAXWIDTHPERC ? SBARMAXWIDTHPERC : sbarwidth_perc;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -161,33 +163,22 @@ wins_sbar_wperc (void)
|
||||
void
|
||||
wins_set_sbar_width (unsigned perc)
|
||||
{
|
||||
if (perc > SBARMAXWIDTHPERC)
|
||||
sbarwidth = col * SBARMAXWIDTHPERC / 100;
|
||||
else if (perc <= 0)
|
||||
sbarwidth = SBARMINWIDTH;
|
||||
else
|
||||
{
|
||||
sbarwidth = (unsigned)(col * perc / 100);
|
||||
if (sbarwidth < SBARMINWIDTH)
|
||||
sbarwidth = SBARMINWIDTH;
|
||||
}
|
||||
sbarwidth_perc = perc;
|
||||
}
|
||||
|
||||
/* Change the width of the side bar within acceptable boundaries. */
|
||||
void
|
||||
wins_sbar_winc (void)
|
||||
{
|
||||
if (sbarwidth < SBARMINWIDTH)
|
||||
sbarwidth = SBARMINWIDTH + 1;
|
||||
else if (sbarwidth < SBARMAXWIDTHPERC * col / 100)
|
||||
sbarwidth++;
|
||||
if (sbarwidth_perc < SBARMAXWIDTHPERC)
|
||||
sbarwidth_perc++;
|
||||
}
|
||||
|
||||
void
|
||||
wins_sbar_wdec (void)
|
||||
{
|
||||
if (sbarwidth > SBARMINWIDTH)
|
||||
sbarwidth--;
|
||||
if (sbarwidth_perc > 0)
|
||||
sbarwidth_perc--;
|
||||
}
|
||||
|
||||
/* Initialize the selected window in calcurse's interface. */
|
||||
|
Loading…
x
Reference in New Issue
Block a user