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:
Lukas Fleischer 2012-04-12 23:09:31 +02:00
parent b4d5316125
commit c65ccb0e77

View File

@ -44,7 +44,7 @@
struct window win[NBWINS]; struct window win[NBWINS];
/* User-configurable side bar width. */ /* User-configurable side bar width. */
static unsigned sbarwidth; static unsigned sbarwidth_perc;
static enum win slctd_win; static enum win slctd_win;
static int layout; static int layout;
@ -135,7 +135,13 @@ wins_set_layout (int nb)
unsigned unsigned
wins_sbar_width (void) 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 unsigned
wins_sbar_wperc (void) wins_sbar_wperc (void)
{ {
unsigned perc; return sbarwidth_perc > SBARMAXWIDTHPERC ? SBARMAXWIDTHPERC : sbarwidth_perc;
perc = col ? (unsigned)(100 * sbarwidth / col + 1): 0;
return perc > SBARMAXWIDTHPERC ? SBARMAXWIDTHPERC : perc;
} }
/* /*
@ -161,33 +163,22 @@ wins_sbar_wperc (void)
void void
wins_set_sbar_width (unsigned perc) wins_set_sbar_width (unsigned perc)
{ {
if (perc > SBARMAXWIDTHPERC) sbarwidth_perc = perc;
sbarwidth = col * SBARMAXWIDTHPERC / 100;
else if (perc <= 0)
sbarwidth = SBARMINWIDTH;
else
{
sbarwidth = (unsigned)(col * perc / 100);
if (sbarwidth < SBARMINWIDTH)
sbarwidth = SBARMINWIDTH;
}
} }
/* Change the width of the side bar within acceptable boundaries. */ /* Change the width of the side bar within acceptable boundaries. */
void void
wins_sbar_winc (void) wins_sbar_winc (void)
{ {
if (sbarwidth < SBARMINWIDTH) if (sbarwidth_perc < SBARMAXWIDTHPERC)
sbarwidth = SBARMINWIDTH + 1; sbarwidth_perc++;
else if (sbarwidth < SBARMAXWIDTHPERC * col / 100)
sbarwidth++;
} }
void void
wins_sbar_wdec (void) wins_sbar_wdec (void)
{ {
if (sbarwidth > SBARMINWIDTH) if (sbarwidth_perc > 0)
sbarwidth--; sbarwidth_perc--;
} }
/* Initialize the selected window in calcurse's interface. */ /* Initialize the selected window in calcurse's interface. */