scrn-bar.mklx /size: 15 Kb    last modification: 2021-10-28 13:51
1%D \module
2%D   [       file=scrn-bar, % was part of scrn-int
3%D        version=1995.01.01,
4%D          title=\CONTEXT\ Core Macros,
5%D       subtitle=Progress 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 Screen Macros / Progress Bars}
15
16\unprotect
17
18%D The code is a bit upgraded to \MKIV\ but the output is mostly the same. In
19%D retrospect this should have been a module. We can move some definitions to
20%D scrn-run-bar.mkiv if needed. We can also make the code a bit more efficient.
21
22% todo: replace blackrule by stupid rules
23
24%D \starttyping
25%D \setupinteraction
26%D   [state=start]
27%D
28%D \setupsubpagenumber
29%D   [state=start]
30%D
31%D \setuplayout
32%D   [middle]
33%D
34%D \setuppapersize
35%D   [S4][S4]
36%D
37%D \startsetups bars
38%D     \ruledvbox to \textheight \bgroup
39%D         a \ruledhbox{\interactionbar[a]}\vss
40%D         b \ruledhbox{\interactionbar[b]}\vss
41%D         c \ruledhbox{\interactionbar[c]}\vss
42%D         d \ruledhbox{\interactionbar[d]}\vss
43%D         e \ruledhbox{\interactionbar[e]}\vss
44%D         f \ruledhbox{\interactionbar[f]}\vss
45%D         g \ruledhbox{\interactionbar[g]}\vss
46%D     \egroup
47%D \stopsetups
48%D
49%D \setuptexttexts[\setups{bars}]
50%D
51%D \starttext
52%D     \dorecurse {12} {
53%D         \startstandardmakeup
54%D         \stopstandardmakeup
55%D     }
56%D \stoptext
57%D \stoptyping
58
59\installcorenamespace{interactionbar}
60
61\installframedcommandhandler \??interactionbar {interactionbar} \??interactionbar
62
63\permanent\tolerant\protected\def\interactionbar[#tag]#spacer[#settings]% somewhat messy
64  {\iflocation
65     \begingroup
66     \ifhastok={#tag}%
67       \let\currentinteractionbar\empty
68       \setupcurrentinteractionbar[#tag]%
69       \edef\currentinteractionbar{\interactionbarparameter\c!alternative}%
70     \else
71       \edef\currentinteractionbar{#tag}%
72       \setupcurrentinteractionbar[#settings]%
73     \fi
74     \doif{\interactionbarparameter\c!state}\v!start
75       {\interactionbarparameter\c!command}%
76     \endgroup
77   \fi}
78
79\newdimen\d_scrn_bar_width
80\newdimen\d_scrn_bar_height
81\newdimen\d_scrn_bar_depth
82\newdimen\d_scrn_bar_distance
83
84%D Interaction buttons, in fact a row of tiny buttons, are typically only used for
85%D navigational purposed. The next macro builds such a row based on a specification
86%D list.
87%D
88%D \startbuffer
89%D \interactionbuttons[width=\hsize][page,PreviousJump,ExitViewer]
90%D \stopbuffer
91%D
92%D \typebuffer
93%D
94%D gives
95%D
96%D \getbuffer
97%D
98%D Apart from individual entries, one can use \type{page} and \type {subpage} as
99%D shortcuts to their four associated buttons. The symbols are derived from the
100%D symbols linked to the entries.
101
102\permanent\tolerant\protected\def\interactionbuttons[#settings]#spacer[#list]%
103  {\iflocation
104      \ifcstok{\interactionbarparameter\c!state}\v!start
105        \ifparameter#list\or
106          \scrn_bar_buttons_indeed{#settings}{#list}%
107        \else
108          \scrn_bar_buttons_indeed{}{#settings}%
109        \fi
110      \fi
111   \fi}
112
113\def\scrn_bar_buttons_indeed#settings#list%
114  {\begingroup
115  %\let\currentinteractionbar\empty
116   \setupcurrentinteractionbar[#settings]%
117   \d_scrn_bar_width   \interactionbarparameter\c!width\relax
118   \d_scrn_bar_distance\interactionbarparameter\c!distance\relax
119   \ifzeropt\d_scrn_bar_width
120     \d_scrn_bar_width1.5\emwidth
121   \fi
122   \doifnothing{\interactionbarparameter\c!height}{\letinteractionbarparameter\c!height\v!broad}%
123   \doifnothing{\interactionbarparameter\c!depth }{\letinteractionbarparameter\c!depth\zeropoint}%%%
124   \letinteractionbarparameter\c!background\empty
125   \setbox2\hbox{\inheritedinteractionbarframed{\symbol[\interactionparameter\c!symbolset][\v!previouspage]}}%
126   \scratchheight\ht2 % needed because we default to nothing
127   \letinteractionbarparameter\c!strut\v!no
128 % \letinteractionparameter\c!width\zeropoint
129   \scratchcounterone\zerocount % new, was 1
130   \processallactionsinset
131     [#list]
132     [   \v!page=>\advance\scratchcounterone\plusfour,
133      \v!subpage=>\advance\scratchcounterone\plusfour,
134      \s!unknown=>\advance\scratchcounterone\plusone]%
135   \ifzeropt\d_scrn_bar_width
136     \scratchdimenone\dimexpr2\emwidth+\d_scrn_bar_distance\relax
137     \scratchdimentwo\dimexpr\scratchcounterone\scratchdimenone-\d_scrn_bar_distance\relax
138   \else
139     \scratchdimenone\d_scrn_bar_width
140     \scratchdimentwo\dimexpr\scratchcounterone\d_scrn_bar_distance-\d_scrn_bar_distance\relax
141     \advance\scratchdimenone -\scratchdimentwo
142     \divide\scratchdimenone \scratchcounterone
143     \scratchdimentwo\d_scrn_bar_width
144   \fi
145   \hbox to \scratchdimentwo
146     {\setnostrut
147      \startsymbolset[\interactionparameter\c!symbolset]%
148      \setupbuttons
149        [#settings,%
150         \c!height=\the\scratchheight,%
151         \c!width=\the\scratchdimenone]%
152      \processallactionsinset
153        [#list]
154        [   \v!page=>\scrn_bar_goto\v!firstpage
155                     \scrn_bar_goto\v!nextpage
156                     \scrn_bar_goto\v!previouspage
157                     \scrn_bar_goto\v!lastpage,
158         \v!subpage=>\scrn_bar_goto\v!firstsubpage
159                     \scrn_bar_goto\v!nextsubpage
160                     \scrn_bar_goto\v!previoussubpage
161                     \scrn_bar_goto\v!lastsubpage,
162         \s!unknown=>\scrn_bar_goto\commalistelement]%
163      \unskip
164      \stopsymbolset}%
165   \endgroup}
166
167\def\scrn_bar_goto#action%
168  {\button{\symbol[#action]}[#action]\hss}
169
170% todo: this will be \letblackruleparameter\c!width\scratchdimenone (faster)
171% todo: make these setups
172
173\def\scrn_bar_alternative_a
174  {\d_scrn_bar_width   \interactionbarparameter\c!width
175   \d_scrn_bar_distance\interactionbarparameter\c!distance
176   \d_scrn_bar_height  \interactionbarparameter\c!height
177   \d_scrn_bar_depth   \interactionbarparameter\c!depth
178   \noindent\hbox to \d_scrn_bar_width \bgroup
179     \dontcomplain
180     \setupblackrules[\c!height=\v!max,\c!depth=\v!max]%
181     \scratchdimentwo\dimexpr\d_scrn_bar_width-4\emwidth\relax
182     \processaction
183       [\interactionbarparameter\c!step]
184       [   \v!small=>\scratchcounter 20,
185          \v!medium=>\scratchcounter 10,
186             \v!big=>\scratchcounter  5,
187         \s!unknown=>\scratchcounter 10]%
188     \scratchdimenone\dimexpr\scratchdimentwo/\scratchcounter\relax
189     \setupblackrules[\c!width=\scratchdimenone]%
190     \setbox\scratchbox\hbox to \d_scrn_bar_width
191       {\hskip2\emwidth
192        \setbox\scratchbox\hpack{\blackrule[\c!color=\interactionbarparameter\c!backgroundcolor]}%
193        \dorecurse\scratchcounter
194          {\hss\normalexpanded{\directgotodumbbox{\copy\scratchbox}[page(\the\numexpr\recurselevel*\lastpage/\scratchcounter\relax)]}}%
195        \hss
196        \hskip2\emwidth}%
197     \wd\scratchbox\zeropoint
198     \box \scratchbox
199     \setupblackrules[\c!width=\emwidth]%
200     \normalexpanded{\directgotospecbox\noexpand\interactionbarparameter{\blackrule}[\v!firstpage]}%
201     \hskip\emwidth
202     \ifnum\realpageno>\plusone
203       \hskip\zeropoint\s!plus\numexpr\realpageno-\plustwo\relax \s!sp\relax % cm gives overflow
204       \normalexpanded{\directgotospecbox\noexpand\interactionbarparameter{\blackrule}[\v!previouspage)]}%
205     \fi
206     \normalexpanded{\directgotospecbox\noexpand\interactionbarparameter{\blackrule}[page(\number\realpageno)]}% todo: \v!currentpage
207     \ifnum\realpageno<\lastpage\relax
208       \normalexpanded{\directgotospecbox\noexpand\interactionbarparameter{\blackrule}[\v!nextpage]}%
209       \hskip\zeropoint\s!plus\numexpr\lastpage-\realpageno-\plusone\relax \s!sp\relax % cm gives overflow
210     \fi
211     \hskip\emwidth
212     \normalexpanded{\directgotospecbox\noexpand\interactionbarparameter{\blackrule}[\v!lastpage]}%
213   \egroup}
214
215\def\scrn_bar_alternative_b
216  {\ifnum\lastpage>\firstpage\relax
217     \interactionbuttons[\v!firstpage,\v!previouspage,\v!nextpage,\v!lastpage]%
218   \fi}
219
220\def\scrn_bar_alternative_c
221  {\ifnum\lastpage>\plusone
222     \d_scrn_bar_width\interactionbarparameter\c!width
223     \hbox to \d_scrn_bar_width
224       {\setupblackrules[\c!height=\interactionbarparameter\c!height,\c!depth=\interactionbarparameter\c!depth,\c!width=\emwidth]%
225        \scratchdimen\dimexpr(\d_scrn_bar_width-4\emwidth)/\numexpr\lastpage+\minusone\relax\relax
226        \scratchdimenone\numexpr\realpageno+\minusone\relax\scratchdimen
227        \scratchdimentwo\numexpr\lastpage-\realpageno\relax\scratchdimen
228        \directgotospecbox\interactionbarparameter{\blackrule}[\v!firstpage]%
229        \hss
230        \directgotospecbox\interactionbarparameter{\blackrule[\c!width=\scratchdimenone]}[\v!previouspage]%
231        \blackrule[\c!color=\interactionbarparameter\c!contrastcolor]%
232        \directgotospecbox\interactionbarparameter{\blackrule[\c!width=\scratchdimentwo]}[\v!nextpage]%
233        \hss
234        \directgotospecbox\interactionbarparameter{\blackrule}[\v!lastpage]}%
235   \fi}
236
237\protected\def\scrn_bar_goto_a#whereto%
238  {\symbol[\ifcase#whereto\v!previous\or\v!somewhere\or\v!next\fi]}
239
240\protected\def\scrn_bar_goto_b#whereto%
241  {\vrule\s!height\d_scrn_bar_height\s!depth\d_scrn_bar_depth\s!width\scratchdimenone\relax}
242
243\protected\def\scrn_bar_goto_c#whereto%
244  {\symbol[\ifcase#whereto\v!previous\or\v!somewhere\or\v!somewhere\or\v!somewhere\or\v!next\fi}
245
246\protected\def\scrn_bar_goto_d#whereto%
247  {\vrule \s!width\scratchdimenone \ifcase#whereto%
248     \s!height  \d_scrn_bar_height \s!depth  \d_scrn_bar_depth \or
249     \s!height.5\d_scrn_bar_height \s!depth.5\d_scrn_bar_depth \or
250     \s!height  \d_scrn_bar_height \s!depth  \d_scrn_bar_depth \or
251     \s!height.5\d_scrn_bar_height \s!depth.5\d_scrn_bar_depth \else
252     \s!height  \d_scrn_bar_height \s!depth  \d_scrn_bar_depth \fi}
253
254\newconstant\c_scrn_bar_mode
255
256\let\scrn_bar_goto_indeed\relax
257
258\protected\def\scrn_bar_goto_x#command%
259  {\doifelse{\interactionbarparameter\c!symbol}\v!yes
260     {\setupsymbolset[\interactionparameter\c!symbolset]%
261      \let\scrn_bar_goto_indeed\scrn_bar_goto_a}
262     {\let\scrn_bar_goto_indeed\scrn_bar_goto_b}%
263   \dorecurse\nofsubpages
264    %{\scratchcounter\numexpr\recurselevel+\firstsubpage+\minusone\relax
265     {\scratchcounter\therealsubpageno\recurselevel
266      \c_scrn_bar_mode
267        \ifnum\scratchcounter<\realpageno \zerocount \else
268        \ifnum\scratchcounter=\realpageno \plusone   \else
269                                          \plustwo   \fi\fi
270      \normalexpanded{\directgotospecbox\noexpand\interactionbarparameter{\scrn_bar_goto_indeed\c_scrn_bar_mode}[page(\the\scratchcounter)]}%
271      #command}%
272   \unskip}
273
274\def\scrn_bar_alternative_d
275  {\ifnum\nofsubpages>\plusone \doif{\namedcounterparameter\s!subpage\c!state}\v!start{%
276     \d_scrn_bar_width   \interactionbarparameter\c!width
277     \d_scrn_bar_distance\interactionbarparameter\c!distance
278     \d_scrn_bar_height  \interactionbarparameter\c!height
279     \d_scrn_bar_depth   \interactionbarparameter\c!depth
280     \scratchdimenone\d_scrn_bar_width
281     \noindent\hbox{\scrn_bar_goto_x{\hskip\d_scrn_bar_distance}}% \hpack ?
282   }\fi}
283
284\def\scrn_bar_alternative_e
285  {\ifnum\nofsubpages>\plusone \doif{\namedcounterparameter\s!subpage\c!state}\v!start{%
286     \d_scrn_bar_width   \interactionbarparameter\c!width
287     \d_scrn_bar_distance\interactionbarparameter\c!distance
288     \d_scrn_bar_height  \interactionbarparameter\c!height
289     \d_scrn_bar_depth   \interactionbarparameter\c!depth
290     \scratchdimentwo\dimexpr\nofsubpages\d_scrn_bar_distance-\d_scrn_bar_distance\relax % (n-1)
291     \scratchdimenone\dimexpr(\d_scrn_bar_width-\scratchdimentwo)/\nofsubpages\relax
292     \ifdim\scratchdimenone<\d_scrn_bar_distance
293       \scrn_bar_alternative_f
294     \else
295       \noindent\hbox to \d_scrn_bar_width{\scrn_bar_goto_x{\hss}\unskip}% \hpack ?
296     \fi
297   }\fi}
298
299\def\scrn_bar_alternative_f
300  {\ifnum\nofsubpages>\plusone \doif{\namedcounterparameter\s!subpage\c!state}\v!start{%
301     \d_scrn_bar_width   \interactionbarparameter\c!width
302     \d_scrn_bar_distance\interactionbarparameter\c!distance
303     \d_scrn_bar_height  \interactionbarparameter\c!height
304     \d_scrn_bar_depth   \interactionbarparameter\c!depth
305     \noindent \hbox to \d_scrn_bar_width \bgroup
306       \doloop
307         {\scratchcounterthree\numexpr(\nofsubpages/\recurselevel)+\plusone\relax % rounding
308          \scratchdimentwo\d_scrn_bar_distance
309          \multiply\scratchdimentwo \scratchcounterthree
310          \advance\scratchdimentwo -\d_scrn_bar_distance
311          \scratchdimenone\d_scrn_bar_width
312          \advance\scratchdimenone -\scratchdimentwo
313          \divide\scratchdimenone \scratchcounterthree
314          \ifdim\scratchdimenone<\d_scrn_bar_distance\else
315            \scratchcountertwo\recurselevel
316            \exitloop
317          \fi}%
318       \ifnum\scratchcounterthree>\plusone
319         % this is not that well tested
320         \advance\scratchcounterthree \minustwo
321         \scratchdimenone-\d_scrn_bar_distance
322         \scratchdimenone\scratchcounterthree\scratchdimenone
323         \advance\scratchdimenone \d_scrn_bar_width
324         \advance\scratchcounterthree \plusone
325         \divide\scratchdimenone \scratchcounterthree
326       \fi
327       \doifelse{\interactionbarparameter\c!symbol}\v!yes
328         {\setupsymbolset[\interactionparameter\c!symbolset]%
329          \let\scrn_bar_goto_indeed\scrn_bar_goto_c}%
330         {\let\scrn_bar_goto_indeed\scrn_bar_goto_d}%
331       \scratchcounterthree\numexpr\realpageno-\plustwo\relax
332       \scratchcounterfour\numexpr\realpageno+\plustwo\relax
333       \ifnum\scratchcounterthree<\plusone \scratchcounterthree\plusone \fi
334       \scratchcounterfive\zerocount
335       \dostepwiserecurse\firstsubpage\lastsubpage\plusone
336         {\donefalse
337          \advance\scratchcounterfive \plusone
338          \ifnum\recurselevel=\firstsubpage\relax \donetrue \fi
339          \ifnum\recurselevel=\lastsubpage \relax \donetrue \fi
340          \scratchcountersix\therealsubpageno\recurselevel\relax
341          \c_scrn_bar_mode
342            \ifdone
343              \ifnum\scratchcountersix<\realpageno
344                \zerocount
345              \orelse\ifnum\scratchcountersix>\realpageno
346                \plustwo
347              \else
348                \plusfour
349              \fi
350            \else
351              \ifnum\scratchcounterfive=\scratchcountertwo
352                \ifnum\scratchcountersix<\realpageno
353                  \plusone
354                \orelse\ifnum\scratchcountersix>\realpageno
355                  \plusthree
356                \else
357                  \plustwo
358                \fi
359              \else
360                \minusone
361              \fi
362            \fi
363          \ifnum\c_scrn_bar_mode<\zerocount\else
364            \normalexpanded{\directgotospecbox\noexpand\interactionbarparameter{\scrn_bar_goto_indeed\c_scrn_bar_mode}[realpage(\the\scratchcountersix)]}%
365            \hss
366            \scratchcounterfive\zerocount
367          \fi}%
368       \unskip
369     \egroup
370   }\fi}
371
372\def\scrn_bar_alternative_g
373  {\ifnum\lastsubpage>\firstsubpage\relax % no test for state?
374     \interactionbuttons[\v!firstsubpage,\v!previoussubpage,\v!nextsubpage,\v!lastsubpage]%
375   \fi}
376
377\setupinteractionbar
378  [\c!state=\v!start,
379   \c!alternative=a,
380   \c!symbol=\v!no,
381   \c!width=10\emwidth,
382   \c!height=.5\emwidth,
383   \c!depth=\zeropoint,
384   \c!distance=.5\emwidth,
385   \c!step=\v!medium,
386   \c!foregroundcolor=\interactionbarparameter\c!color,
387   \c!foregroundstyle=\interactionbarparameter\c!style,
388   \c!color=\interactionparameter\c!color,
389   \c!contrastcolor=\interactionparameter\c!contrastcolor,
390   \c!style=,
391   \c!frame=\v!on,
392   \c!background=color,
393   \c!backgroundcolor=gray,
394   \c!samepage=\v!yes]
395
396\defineinteractionbar[a][\c!command=\scrn_bar_alternative_a]
397\defineinteractionbar[b][\c!command=\scrn_bar_alternative_b,\c!height=\v!broad]
398\defineinteractionbar[c][\c!command=\scrn_bar_alternative_c,\c!height=\v!max,\c!depth=\v!max]
399\defineinteractionbar[d][\c!command=\scrn_bar_alternative_d,\c!width=.5\emwidth]
400\defineinteractionbar[e][\c!command=\scrn_bar_alternative_e]
401\defineinteractionbar[f][\c!command=\scrn_bar_alternative_f]
402\defineinteractionbar[g][\c!command=\scrn_bar_alternative_g,\c!height=\v!broad]
403
404\protect \endinput
405