pack-bar.mkxl /size: 3741 b    last modification: 2025-02-21 11:03
1%D \module
2%D   [       file=pack-bar,
3%D        version=2009.06.26,
4%D          title=\CONTEXT\ Packaging Macros,
5%D       subtitle=Bars,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14\writestatus{loading}{ConTeXt Packaging Macros / Bars}
15
16\unprotect
17
18%D This code has been moved from scrn-int to here (was some old experimental code).
19%D It could be in scrn-bar but it's static. In the meantime the interface has been
20%D adapted to a key|/|value one.
21%D
22%D \startbuffer
23%D  \dorecurse{10}{
24%D      \ruledhbox{\horizontalpositionbar[n=#1,min=1,max=10,text=!,color=red]}
25%D      \par
26%D  }
27%D \stopbuffer
28%D
29%D \typebuffer \stoplinecorrection \getbuffer \stoplinecorrection
30%D
31%D \startbuffer
32%D  \dorecurse{10}{
33%D      \ruledhbox{\horizontalgrowingbar[n=#1,min=1,max=10,text=!,color=red]}
34%D      \par
35%D  }
36%D \stopbuffer
37%D
38%D \typebuffer \stoplinecorrection \getbuffer \stoplinecorrection
39
40%D Maybe [n|min|max] : \numexpr...\relax
41
42\installcorenamespace{positionbar}
43
44\installsimplecommandhandler \??positionbar {positionbar} \??positionbar
45
46\setuppositionbar
47  [\c!min=\plusone,
48   \c!max=\plusone,
49   \c!n=\plusone
50   \c!text=?,
51   \c!width=\emwidth,
52   \c!height=\strutheight,
53   \c!depth=\strutdepth]
54
55\def\pack_bar_common_setting
56  {\usepositionbarstyleandcolor\c!style\c!color
57   \scratchcounter{\positionbarparameter\c!n}%
58   \scratchmin{\positionbarparameter\c!min}%
59   \scratchmax{\positionbarparameter\c!max}}
60
61\permanent\protected\def\horizontalpositionbar[#S#1]%
62  {\hbox to \hsize
63     {\setuppositionbar[#1]%
64      \pack_bar_common_setting
65      \hskip\zeropoint\s!plus \scratchcounter\s!fill
66      \hskip\zeropoint\s!plus-\scratchmin    \s!fill
67      \positionbarparameter\c!text\relax
68      \hskip\zeropoint\s!plus \scratchmax    \s!fill
69      \hskip\zeropoint\s!plus-\scratchcounter\s!fill}}
70
71\permanent\protected\def\verticalpositionbar[#S#1]%
72  {\vbox to \vsize
73     {\hsize{\positionbarparameter\c!width}%
74      \setuppositionbar[#1]%
75      \pack_bar_common_setting
76      \vskip\zeropoint\s!plus \scratchcounter\s!fill
77      \vskip\zeropoint\s!plus-\scratchmin    \s!fill
78      \positionbarparameter\c!text\relax
79      \vskip\zeropoint\s!plus \scratchmax    \s!fill
80      \vskip\zeropoint\s!plus-\scratchcounter\s!fill}}
81
82\permanent\protected\def\horizontalgrowingbar[#S#1]%
83  {\hpack to \hsize
84     {\setuppositionbar[#1]%
85      \pack_bar_common_setting
86      \vrule
87        \s!width  \zeropoint
88        \s!height {\positionbarparameter\c!height}%
89        \s!depth  {\positionbarparameter\c!depth}%
90      \relax
91      \leaders
92        \vrule
93        \hskip
94          \zeropoint
95          \s!plus\numexpr\scratchcounter-\scratchmin+\plusone\relax\s!fill
96      \relax
97      \hskip
98        \zeropoint
99        \s!plus \scratchmax\s!fill
100      \relax
101      \hskip
102        \zeropoint
103        \s!plus-\scratchcounter\s!fill
104      \relax}}
105
106\permanent\protected\def\verticalgrowingbar[#S#1]%
107  {\vpack to \vsize
108     {\hsize{\positionbarparameter\c!width}%
109      \setuppositionbar[#1]%
110      \pack_bar_common_setting
111      \hrule
112        \s!width  {\positionbarparameter\c!width}% can have changed
113        \s!height \zeropoint
114        \s!depth  \zeropoint
115      \relax
116      \leaders
117        \hrule
118        \vskip
119          \zeropoint
120          \s!plus \numexpr\scratchcounter-\scratchmin+\plusone\relax\s!fill
121      \relax
122      \vskip
123        \zeropoint
124        \s!plus \scratchmax\s!fill
125      \relax
126      \vskip
127        \zeropoint
128        \s!plus-\scratchcounter\s!fill
129      \relax}}
130
131\protect \endinput
132