aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2012-04-12 23:09:31 +0200
committerLukas Fleischer <calcurse@cryptocrack.de>2012-04-12 23:11:33 +0200
commitc65ccb0e77a0f03e06cd2bb6965ec41863d37ae2 (patch)
tree397aa22117ceb8f3e03a088eaf6ca9434ee25d96 /src
parentb4d5316125a50366e030afa1464181f71fff7923 (diff)
downloadcalcurse-c65ccb0e77a0f03e06cd2bb6965ec41863d37ae2.tar.gz
calcurse-c65ccb0e77a0f03e06cd2bb6965ec41863d37ae2.zip
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>
Diffstat (limited to 'src')
-rw-r--r--src/wins.c37
1 files changed, 14 insertions, 23 deletions
diff --git a/src/wins.c b/src/wins.c
index a3e611e..3501b21 100644
--- a/src/wins.c
+++ b/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. */