%D \module
%D   [       file=pack-bar,
%D        version=2009.06.26,
%D          title=\CONTEXT\ Packaging Macros,
%D       subtitle=Bars,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\writestatus{loading}{ConTeXt Packaging Macros / Bars}


\unprotect

%D This code has been moved from scrn-int to here (was some old
%D experimental code). It could be in scrn-bar but it's static. In
%D the meantime the interface has been adapted to a key|/|value one.
%D
%D \startbuffer
%D  \dorecurse{10}{
%D      \ruledhbox{\horizontalpositionbar[n=#1,min=1,max=10,text=!,color=red]}
%D      \par
%D  }
%D \stopbuffer
%D
%D \typebuffer \stoplinecorrection \getbuffer \stoplinecorrection
%D
%D \startbuffer
%D  \dorecurse{10}{
%D      \ruledhbox{\horizontalgrowingbar[n=#1,min=1,max=10,text=!,color=red]}
%D      \par
%D  }
%D \stopbuffer
%D
%D \typebuffer \stoplinecorrection \getbuffer \stoplinecorrection

\installcorenamespace{positionbar}

\installsimplecommandhandler \??positionbar {positionbar}

\setuppositionbar
  [\c!min=1,
   \c!max=1,
   \c!n=1,
   \c!text=?,
   \c!width=\emwidth,
   \c!height=\strutheight,
   \c!depth=\strutdepth]

\unexpanded\def\horizontalpositionbar[#1]%
  {\hbox to \hsize
     {\setuppositionbar[#1]%
      \usepositionbarstyleandcolor\c!style\c!color
      \hskip\zeropoint\s!plus \positionbarparameter\c!n  \s!fill
      \hskip\zeropoint\s!plus-\positionbarparameter\c!min\s!fill
      \positionbarparameter\c!text\relax
      \hskip\zeropoint\s!plus \positionbarparameter\c!max\s!fill
      \hskip\zeropoint\s!plus-\positionbarparameter\c!n  \s!fill}}

\unexpanded\def\verticalpositionbar[#1]%
  {\vbox to \vsize
     {\setuppositionbar[#1]%
      \usepositionbarstyleandcolor\c!style\c!color
      \vskip\zeropoint\s!plus \positionbarparameter\c!n  \s!fill
      \vskip\zeropoint\s!plus-\positionbarparameter\c!min\s!fill
      \positionbarparameter\c!text\relax
      \vskip\zeropoint\s!plus \positionbarparameter\c!max\s!fill
      \vskip\zeropoint\s!plus-\positionbarparameter\c!n  \s!fill}}

\unexpanded\def\horizontalgrowingbar[#1]%
  {\hpack to \hsize
     {\setuppositionbar[#1]%
      \usepositionbarstyleandcolor\c!style\c!color
      \leaders\vrule\hskip\zeropoint\s!plus\numexpr\positionbarparameter\c!n-\positionbarparameter\c!min+\plusone\relax\s!fill
      \vrule\s!width\zeropoint\s!height\positionbarparameter\c!height\s!depth\positionbarparameter\c!depth
      \hskip\zeropoint\s!plus \positionbarparameter\c!max\s!fill
      \hskip\zeropoint\s!plus-\positionbarparameter\c!n  \s!fill}}

\unexpanded\def\verticalgrowingbar[#1]%
  {\vpack to \vsize
     {\setuppositionbar[#1]%
      \usepositionbarstyleandcolor\c!style\c!color
      \leaders\hrule\vskip\zeropoint\s!plus\numexpr\positionbarparameter\c!n-\positionbarparameter\c!min+\plusone\relax\s!fill
      \hrule\s!width\positionbarparameter\c!width\s!height\zeropoint\s!depth\zeropoint
      \vskip\zeropoint\s!plus \positionbarparameter\c!max\s!fill
      \vskip\zeropoint\s!plus-\positionbarparameter\c!n  \s!fill}}

\protect \endinput
